blob: 89006361bac013dc03a3b0f24639c4531fb7c4ed [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 Tarreau7aabd112010-01-26 10:59:06 +010067 " set timeout : change a timeout setting\n"
Cyril Bontécd19e512010-01-31 22:34:03 +010068 " disable server : set a server in maintenance mode\n"
69 " enable server : re-enable a server that was previously in maintenance mode\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020070 "";
Willy Tarreau5ca791d2009-08-16 19:06:42 +020071
Willy Tarreau6162db22009-10-10 17:13:00 +020072const char stats_permission_denied_msg[] =
73 "Permission denied\n"
74 "";
75
Willy Tarreaufbee7132007-10-18 13:53:22 +020076/* This function parses a "stats" statement in the "global" section. It returns
77 * -1 if there is any error, otherwise zero. If it returns -1, it may write an
78 * error message into ther <err> buffer, for at most <errlen> bytes, trailing
79 * zero included. The trailing '\n' must not be written. The function must be
80 * called with <args> pointing to the first word after "stats".
81 */
Willy Tarreau10522fd2008-07-09 20:12:41 +020082static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
83 struct proxy *defpx, char *err, int errlen)
Willy Tarreaufbee7132007-10-18 13:53:22 +020084{
Willy Tarreau10522fd2008-07-09 20:12:41 +020085 args++;
Willy Tarreaufbee7132007-10-18 13:53:22 +020086 if (!strcmp(args[0], "socket")) {
87 struct sockaddr_un su;
88 int cur_arg;
89
90 if (*args[1] == 0) {
91 snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket");
92 return -1;
93 }
94
95 if (global.stats_sock.state != LI_NEW) {
96 snprintf(err, errlen, "'stats socket' already specified in global section");
97 return -1;
98 }
99
100 su.sun_family = AF_UNIX;
101 strncpy(su.sun_path, args[1], sizeof(su.sun_path));
102 su.sun_path[sizeof(su.sun_path) - 1] = 0;
103 memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit
104
Willy Tarreau89a63132009-08-16 17:41:45 +0200105 if (!global.stats_fe) {
106 if ((global.stats_fe = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) {
107 snprintf(err, errlen, "out of memory");
108 return -1;
109 }
110
111 LIST_INIT(&global.stats_fe->pendconns);
112 LIST_INIT(&global.stats_fe->acl);
113 LIST_INIT(&global.stats_fe->block_cond);
114 LIST_INIT(&global.stats_fe->redirect_rules);
115 LIST_INIT(&global.stats_fe->mon_fail_cond);
116 LIST_INIT(&global.stats_fe->switching_rules);
117 LIST_INIT(&global.stats_fe->tcp_req.inspect_rules);
118
119 /* Timeouts are defined as -1, so we cannot use the zeroed area
120 * as a default value.
121 */
122 proxy_reset_timeouts(global.stats_fe);
123
124 global.stats_fe->last_change = now.tv_sec;
125 global.stats_fe->id = strdup("GLOBAL");
126 global.stats_fe->cap = PR_CAP_FE;
127 }
128
Willy Tarreaufbee7132007-10-18 13:53:22 +0200129 global.stats_sock.state = LI_INIT;
Willy Tarreau6fb42e02007-10-28 17:02:33 +0100130 global.stats_sock.options = LI_O_NONE;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200131 global.stats_sock.accept = uxst_event_accept;
Willy Tarreau104eb362009-08-16 18:51:29 +0200132 global.stats_sock.handler = process_session;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200133 global.stats_sock.analysers = 0;
Willy Tarreau2c9f5b12009-08-16 19:12:36 +0200134 global.stats_sock.nice = -64; /* we want to boost priority for local stats */
Willy Tarreau89a63132009-08-16 17:41:45 +0200135 global.stats_sock.private = global.stats_fe; /* must point to the frontend */
Willy Tarreau6162db22009-10-10 17:13:00 +0200136 global.stats_sock.perm.ux.level = ACCESS_LVL_OPER; /* default access level */
Willy Tarreau89a63132009-08-16 17:41:45 +0200137
138 global.stats_fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
139 global.stats_sock.timeout = &global.stats_fe->timeout.client;
140
141 global.stats_sock.next = global.stats_fe->listen;
142 global.stats_fe->listen = &global.stats_sock;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200143
144 cur_arg = 2;
145 while (*args[cur_arg]) {
146 if (!strcmp(args[cur_arg], "uid")) {
147 global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]);
148 cur_arg += 2;
149 }
150 else if (!strcmp(args[cur_arg], "gid")) {
151 global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]);
152 cur_arg += 2;
153 }
154 else if (!strcmp(args[cur_arg], "mode")) {
155 global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
156 cur_arg += 2;
157 }
158 else if (!strcmp(args[cur_arg], "user")) {
159 struct passwd *user;
160 user = getpwnam(args[cur_arg + 1]);
161 if (!user) {
162 snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')",
163 args[cur_arg + 1]);
164 return -1;
165 }
166 global.stats_sock.perm.ux.uid = user->pw_uid;
167 cur_arg += 2;
168 }
169 else if (!strcmp(args[cur_arg], "group")) {
170 struct group *group;
171 group = getgrnam(args[cur_arg + 1]);
172 if (!group) {
173 snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')",
174 args[cur_arg + 1]);
175 return -1;
176 }
177 global.stats_sock.perm.ux.gid = group->gr_gid;
178 cur_arg += 2;
179 }
Willy Tarreau6162db22009-10-10 17:13:00 +0200180 else if (!strcmp(args[cur_arg], "level")) {
181 if (!strcmp(args[cur_arg+1], "user"))
182 global.stats_sock.perm.ux.level = ACCESS_LVL_USER;
183 else if (!strcmp(args[cur_arg+1], "operator"))
184 global.stats_sock.perm.ux.level = ACCESS_LVL_OPER;
185 else if (!strcmp(args[cur_arg+1], "admin"))
186 global.stats_sock.perm.ux.level = ACCESS_LVL_ADMIN;
187 else {
188 snprintf(err, errlen, "'stats socket level' only supports 'user', 'operator', and 'admin'");
189 return -1;
190 }
191 cur_arg += 2;
192 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200193 else {
Willy Tarreau6162db22009-10-10 17:13:00 +0200194 snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', 'level', and 'mode'");
Willy Tarreaufbee7132007-10-18 13:53:22 +0200195 return -1;
196 }
197 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100198
Willy Tarreaufbee7132007-10-18 13:53:22 +0200199 uxst_add_listener(&global.stats_sock);
200 global.maxsock++;
201 }
202 else if (!strcmp(args[0], "timeout")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100203 unsigned timeout;
204 const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS);
205
206 if (res) {
207 snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res);
208 return -1;
209 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200210
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100211 if (!timeout) {
Willy Tarreaufbee7132007-10-18 13:53:22 +0200212 snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'");
213 return -1;
214 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200215 global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200216 }
217 else if (!strcmp(args[0], "maxconn")) {
218 int maxconn = atol(args[1]);
219
220 if (maxconn <= 0) {
221 snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'");
222 return -1;
223 }
224 global.maxsock -= global.stats_sock.maxconn;
225 global.stats_sock.maxconn = maxconn;
226 global.maxsock += global.stats_sock.maxconn;
227 }
228 else {
229 snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section");
230 return -1;
231 }
232 return 0;
233}
234
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200235int print_csv_header(struct chunk *msg)
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100236{
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200237 return chunk_printf(msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100238 "# pxname,svname,"
239 "qcur,qmax,"
240 "scur,smax,slim,stot,"
241 "bin,bout,"
242 "dreq,dresp,"
243 "ereq,econ,eresp,"
244 "wretr,wredis,"
245 "status,weight,act,bck,"
246 "chkfail,chkdown,lastchg,downtime,qlimit,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +0200247 "pid,iid,sid,throttle,lbtot,tracked,type,"
248 "rate,rate_lim,rate_max,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200249 "check_status,check_code,check_duration,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100250 "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100251 "\n");
252}
253
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200254/* Processes the stats interpreter on the statistics socket. This function is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200255 * called from an applet running in a stream interface. The function returns 1
256 * if the request was understood, otherwise zero. It sets si->st0 to a value
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200257 * designating the function which will have to process the request, which can
258 * also be the print function to display the return message set into cli.msg.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200259 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200260int stats_sock_parse_request(struct stream_interface *si, char *line)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200261{
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200262 struct session *s = si->private;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200263 char *args[MAX_STATS_ARGS + 1];
264 int arg;
265
266 while (isspace((unsigned char)*line))
267 line++;
268
269 arg = 0;
270 args[arg] = line;
271
272 while (*line && arg < MAX_STATS_ARGS) {
273 if (isspace((unsigned char)*line)) {
274 *line++ = '\0';
275
276 while (isspace((unsigned char)*line))
277 line++;
278
279 args[++arg] = line;
280 continue;
281 }
282
283 line++;
284 }
285
286 while (++arg <= MAX_STATS_ARGS)
287 args[arg] = line;
288
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200289 s->data_ctx.stats.flags = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200290 if (strcmp(args[0], "show") == 0) {
291 if (strcmp(args[1], "stat") == 0) {
292 if (*args[2] && *args[3] && *args[4]) {
293 s->data_ctx.stats.flags |= STAT_BOUND;
294 s->data_ctx.stats.iid = atoi(args[2]);
295 s->data_ctx.stats.type = atoi(args[3]);
296 s->data_ctx.stats.sid = atoi(args[4]);
297 }
298
299 s->data_ctx.stats.flags |= STAT_SHOW_STAT;
300 s->data_ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200301 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200302 si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200303 }
304 else if (strcmp(args[1], "info") == 0) {
305 s->data_ctx.stats.flags |= STAT_SHOW_INFO;
306 s->data_ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200307 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200308 si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200309 }
310 else if (strcmp(args[1], "sess") == 0) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200311 s->data_state = DATA_ST_INIT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200312 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200313 s->data_ctx.cli.msg = stats_permission_denied_msg;
314 si->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200315 return 1;
316 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200317 si->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200318 }
319 else if (strcmp(args[1], "errors") == 0) {
Willy Tarreau6162db22009-10-10 17:13:00 +0200320 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200321 s->data_ctx.cli.msg = stats_permission_denied_msg;
322 si->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200323 return 1;
324 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200325 if (*args[2])
326 s->data_ctx.errors.iid = atoi(args[2]);
327 else
328 s->data_ctx.errors.iid = -1;
329 s->data_ctx.errors.px = NULL;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200330 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200331 si->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200332 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200333 else { /* neither "stat" nor "info" nor "sess" nor "errors"*/
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200334 return 0;
335 }
336 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200337 else if (strcmp(args[0], "clear") == 0) {
338 if (strcmp(args[1], "counters") == 0) {
339 struct proxy *px;
340 struct server *sv;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200341 struct listener *li;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200342 int clrall = 0;
343
344 if (strcmp(args[2], "all") == 0)
345 clrall = 1;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200346
Willy Tarreau6162db22009-10-10 17:13:00 +0200347 /* check permissions */
348 if (s->listener->perm.ux.level < ACCESS_LVL_OPER ||
349 (clrall && s->listener->perm.ux.level < ACCESS_LVL_ADMIN)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200350 s->data_ctx.cli.msg = stats_permission_denied_msg;
351 si->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200352 return 1;
353 }
354
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200355 for (px = proxy; px; px = px->next) {
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200356 if (clrall)
357 memset(&px->counters, 0, sizeof(px->counters));
358 else {
359 px->counters.feconn_max = 0;
360 px->counters.beconn_max = 0;
361 px->counters.fe_sps_max = 0;
362 px->counters.be_sps_max = 0;
363 px->counters.nbpend_max = 0;
364 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200365
366 for (sv = px->srv; sv; sv = sv->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200367 if (clrall)
368 memset(&sv->counters, 0, sizeof(sv->counters));
369 else {
370 sv->counters.cur_sess_max = 0;
371 sv->counters.nbpend_max = 0;
372 sv->counters.sps_max = 0;
373 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200374
375 for (li = px->listen; li; li = li->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200376 if (li->counters) {
377 if (clrall)
378 memset(li->counters, 0, sizeof(*li->counters));
379 else
380 li->counters->conn_max = 0;
381 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200382 }
383
384 return 1;
385 }
386 else {
387 return 0;
388 }
389 }
Willy Tarreau38338fa2009-10-10 18:37:29 +0200390 else if (strcmp(args[0], "get") == 0) {
391 if (strcmp(args[1], "weight") == 0) {
392 struct proxy *px;
393 struct server *sv;
394
395 /* split "backend/server" and make <line> point to server */
396 for (line = args[2]; *line; line++)
397 if (*line == '/') {
398 *line++ = '\0';
399 break;
400 }
401
402 if (!*line) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200403 s->data_ctx.cli.msg = "Require 'backend/server'.\n";
404 si->st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +0200405 return 1;
406 }
407
408 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200409 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
410 si->st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +0200411 return 1;
412 }
413
414 /* return server's effective weight at the moment */
415 snprintf(trash, sizeof(trash), "%d (initial %d)\n", sv->uweight, sv->iweight);
416 buffer_feed(si->ib, trash);
417 return 1;
418 }
419 else { /* not "get weight" */
420 return 0;
421 }
422 }
Willy Tarreau4483d432009-10-10 19:30:08 +0200423 else if (strcmp(args[0], "set") == 0) {
424 if (strcmp(args[1], "weight") == 0) {
425 struct proxy *px;
426 struct server *sv;
427 int w;
428
429 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200430 s->data_ctx.cli.msg = stats_permission_denied_msg;
431 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200432 return 1;
433 }
434
435 /* split "backend/server" and make <line> point to server */
436 for (line = args[2]; *line; line++)
437 if (*line == '/') {
438 *line++ = '\0';
439 break;
440 }
441
442 if (!*line || !*args[3]) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200443 s->data_ctx.cli.msg = "Require 'backend/server' and 'weight' or 'weight%'.\n";
444 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200445 return 1;
446 }
447
448 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200449 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
450 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200451 return 1;
452 }
453
454 /* if the weight is terminated with '%', it is set relative to
455 * the initial weight, otherwise it is absolute.
456 */
457 w = atoi(args[3]);
458 if (strchr(args[3], '%') != NULL) {
459 if (w < 0 || w > 100) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200460 s->data_ctx.cli.msg = "Relative weight can only be set between 0 and 100% inclusive.\n";
461 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200462 return 1;
463 }
464 w = sv->iweight * w / 100;
465 }
466 else {
467 if (w < 0 || w > 256) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200468 s->data_ctx.cli.msg = "Absolute weight can only be between 0 and 256 inclusive.\n";
469 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200470 return 1;
471 }
472 }
473
474 if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200475 s->data_ctx.cli.msg = "Backend is using a static LB algorithm and only accepts weights '0%' and '100%'.\n";
476 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200477 return 1;
478 }
479
480 sv->uweight = w;
481
482 if (px->lbprm.algo & BE_LB_PROP_DYN) {
483 /* we must take care of not pushing the server to full throttle during slow starts */
484 if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN))
485 sv->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - sv->last_change) + sv->slowstart - 1) / sv->slowstart;
486 else
487 sv->eweight = BE_WEIGHT_SCALE;
488 sv->eweight *= sv->uweight;
489 } else {
490 sv->eweight = sv->uweight;
491 }
492
493 /* static LB algorithms are a bit harder to update */
494 if (px->lbprm.update_server_eweight)
495 px->lbprm.update_server_eweight(sv);
496 else if (sv->eweight)
497 px->lbprm.set_server_status_up(sv);
498 else
499 px->lbprm.set_server_status_down(sv);
500
501 return 1;
502 }
Willy Tarreau7aabd112010-01-26 10:59:06 +0100503 else if (strcmp(args[1], "timeout") == 0) {
504 if (strcmp(args[2], "cli") == 0) {
505 unsigned timeout;
506 const char *res;
507
508 if (!*args[3]) {
509 s->data_ctx.cli.msg = "Expects an integer value.\n";
510 si->st0 = STAT_CLI_PRINT;
511 return 1;
512 }
513
514 res = parse_time_err(args[3], &timeout, TIME_UNIT_S);
515 if (res || timeout < 1) {
516 s->data_ctx.cli.msg = "Invalid timeout value.\n";
517 si->st0 = STAT_CLI_PRINT;
518 return 1;
519 }
520
521 s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000);
522 return 1;
523 }
524 else {
525 s->data_ctx.cli.msg = "'set timeout' only supports 'cli'.\n";
526 si->st0 = STAT_CLI_PRINT;
527 return 1;
528 }
529 }
530 else { /* unknown "set" parameter */
Willy Tarreau4483d432009-10-10 19:30:08 +0200531 return 0;
532 }
533 }
Cyril Bontécd19e512010-01-31 22:34:03 +0100534 else if (strcmp(args[0], "enable") == 0) {
535 if (strcmp(args[1], "server") == 0) {
536 struct proxy *px;
537 struct server *sv;
538
539 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
540 s->data_ctx.cli.msg = stats_permission_denied_msg;
541 si->st0 = STAT_CLI_PRINT;
542 return 1;
543 }
544
545 /* split "backend/server" and make <line> point to server */
546 for (line = args[2]; *line; line++)
547 if (*line == '/') {
548 *line++ = '\0';
549 break;
550 }
551
552 if (!*line || !*args[2]) {
553 s->data_ctx.cli.msg = "Require 'backend/server'.\n";
554 si->st0 = STAT_CLI_PRINT;
555 return 1;
556 }
557
558 if (!get_backend_server(args[2], line, &px, &sv)) {
559 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
560 si->st0 = STAT_CLI_PRINT;
561 return 1;
562 }
563
564 if (sv->state & SRV_MAINTAIN) {
565 /* The server is really in maintenance, we can change the server state */
566 if (sv->tracked) {
567 /* If this server tracks the status of another one,
568 * we must restore the good status.
569 */
570 if (sv->tracked->state & SRV_RUNNING) {
571 set_server_up(sv);
572 } else {
573 sv->state &= ~SRV_MAINTAIN;
574 set_server_down(sv);
575 }
576 } else {
577 set_server_up(sv);
578 }
579 }
580
581 return 1;
582 }
583 else { /* unknown "enable" parameter */
584 return 0;
585 }
586 }
587 else if (strcmp(args[0], "disable") == 0) {
588 if (strcmp(args[1], "server") == 0) {
589 struct proxy *px;
590 struct server *sv;
591
592 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
593 s->data_ctx.cli.msg = stats_permission_denied_msg;
594 si->st0 = STAT_CLI_PRINT;
595 return 1;
596 }
597
598 /* split "backend/server" and make <line> point to server */
599 for (line = args[2]; *line; line++)
600 if (*line == '/') {
601 *line++ = '\0';
602 break;
603 }
604
605 if (!*line || !*args[2]) {
606 s->data_ctx.cli.msg = "Require 'backend/server'.\n";
607 si->st0 = STAT_CLI_PRINT;
608 return 1;
609 }
610
611 if (!get_backend_server(args[2], line, &px, &sv)) {
612 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
613 si->st0 = STAT_CLI_PRINT;
614 return 1;
615 }
616
617 if (! (sv->state & SRV_MAINTAIN)) {
618 /* Not already in maintenance, we can change the server state */
619 sv->state |= SRV_MAINTAIN;
620 set_server_down(sv);
621 }
622
623 return 1;
624 }
625 else { /* unknown "disable" parameter */
626 return 0;
627 }
628 }
629 else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200630 return 0;
631 }
632 return 1;
633}
634
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200635/* This I/O handler runs as an applet embedded in a stream interface. It is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200636 * used to processes I/O from/to the stats unix socket. The system relies on a
637 * state machine handling requests and various responses. We read a request,
638 * then we process it and send the response, and we possibly display a prompt.
639 * Then we can read again. The state is stored in si->st0 and is one of the
640 * STAT_CLI_* constants. si->st1 is used to indicate whether prompt is enabled
641 * or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200642 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200643void stats_io_handler(struct stream_interface *si)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200644{
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200645 struct session *s = si->private;
646 struct buffer *req = si->ob;
647 struct buffer *res = si->ib;
648 int reql;
649 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200650
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200651 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
652 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200653
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200654 while (1) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200655 if (si->st0 == STAT_CLI_INIT) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200656 /* Stats output not initialized yet */
657 memset(&s->data_ctx.stats, 0, sizeof(s->data_ctx.stats));
658 s->data_source = DATA_SRC_STATS;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200659 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200660 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200661 else if (si->st0 == STAT_CLI_END) {
662 /* Let's close for real now. We just close the request
663 * side, the conditions below will complete if needed.
664 */
665 si->shutw(si);
666 break;
667 }
668 else if (si->st0 == STAT_CLI_GETREQ) {
Willy Tarreau4e33d862009-10-11 23:35:10 +0200669 /* ensure we have some output room left in the event we
670 * would want to return some info right after parsing.
671 */
672 if (buffer_almost_full(si->ib))
673 break;
674
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200675 reql = buffer_si_peekline(si->ob, trash, sizeof(trash));
676 if (reql <= 0) { /* closed or EOL not found */
677 if (reql == 0)
678 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200679 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200680 continue;
681 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200682
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200683 /* seek for a possible semi-colon. If we find one, we
684 * replace it with an LF and skip only this part.
685 */
686 for (len = 0; len < reql; len++)
687 if (trash[len] == ';') {
688 trash[len] = '\n';
689 reql = len + 1;
690 break;
691 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200692
Willy Tarreau816fc222009-10-04 07:36:58 +0200693 /* now it is time to check that we have a full line,
694 * remove the trailing \n and possibly \r, then cut the
695 * line.
696 */
697 len = reql - 1;
698 if (trash[len] != '\n') {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200699 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200700 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200701 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200702
Willy Tarreau816fc222009-10-04 07:36:58 +0200703 if (len && trash[len-1] == '\r')
704 len--;
705
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200706 trash[len] = '\0';
707
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200708 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200709 if (len) {
710 if (strcmp(trash, "quit") == 0) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200711 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200712 continue;
713 }
714 else if (strcmp(trash, "prompt") == 0)
715 si->st1 = !si->st1;
716 else if (strcmp(trash, "help") == 0 ||
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200717 !stats_sock_parse_request(si, trash)) {
718 s->data_ctx.cli.msg = stats_sock_usage_msg;
719 si->st0 = STAT_CLI_PRINT;
720 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200721 /* NB: stats_sock_parse_request() may have put
722 * another STAT_CLI_O_* into si->st0.
723 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200724 }
725 else if (!si->st1) {
726 /* if prompt is disabled, print help on empty lines,
727 * so that the user at least knows how to enable
728 * prompt and find help.
729 */
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200730 s->data_ctx.cli.msg = stats_sock_usage_msg;
731 si->st0 = STAT_CLI_PRINT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200732 }
733
734 /* re-adjust req buffer */
735 buffer_skip(si->ob, reql);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200736 req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200737 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200738 else { /* output functions: first check if the output buffer is closed then abort */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200739 if (res->flags & (BF_SHUTR_NOW|BF_SHUTR)) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200740 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200741 continue;
742 }
743
744 switch (si->st0) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200745 case STAT_CLI_PRINT:
746 if (buffer_feed(si->ib, s->data_ctx.cli.msg) < 0)
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200747 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200748 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200749 case STAT_CLI_O_INFO:
Willy Tarreau24955a12009-10-04 11:54:04 +0200750 if (stats_dump_raw_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200751 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200752 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200753 case STAT_CLI_O_SESS:
Willy Tarreau7e72a8f2009-10-03 23:55:14 +0200754 if (stats_dump_sess_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200755 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200756 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200757 case STAT_CLI_O_ERR: /* errors dump */
Willy Tarreau61b34732009-10-03 23:49:35 +0200758 if (stats_dump_errors_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200759 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200760 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200761 default: /* abnormal state */
762 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200763 break;
764 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200765
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200766 /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
767 if (si->st0 == STAT_CLI_PROMPT) {
Willy Tarreau9bcc91e2009-10-10 18:01:44 +0200768 if (buffer_feed(si->ib, si->st1 ? "\n> " : "\n") < 0)
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200769 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200770 }
771
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200772 /* If the output functions are still there, it means they require more room. */
Willy Tarreau96fd4b52009-10-04 17:18:35 +0200773 if (si->st0 >= STAT_CLI_OUTPUT)
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200774 break;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200775
776 /* Now we close the output if one of the writers did so,
777 * or if we're not in interactive mode and the request
778 * buffer is empty. This still allows pipelined requests
779 * to be sent in non-interactive mode.
780 */
781 if ((res->flags & (BF_SHUTW|BF_SHUTW_NOW)) || (!si->st1 && !req->send_max)) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200782 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200783 continue;
784 }
785
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200786 /* switch state back to GETREQ to read next requests */
787 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200788 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200789 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200790
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200791 if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST) && (si->st0 != STAT_CLI_GETREQ)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200792 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
793 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
794 /* Other size has closed, let's abort if we have no more processing to do
795 * and nothing more to consume. This is comparable to a broken pipe, so
796 * we forward the close to the request side so that it flows upstream to
797 * the client.
798 */
799 si->shutw(si);
800 }
801
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200802 if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && (si->st0 < STAT_CLI_OUTPUT)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200803 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
804 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
805 /* We have no more processing to do, and nothing more to send, and
806 * the client side has closed. So we'll forward this state downstream
807 * on the response buffer.
808 */
809 si->shutr(si);
810 res->flags |= BF_READ_NULL;
811 }
812
813 /* update all other flags and resync with the other side */
814 si->update(si);
815
816 /* we don't want to expire timeouts while we're processing requests */
817 si->ib->rex = TICK_ETERNITY;
818 si->ob->wex = TICK_ETERNITY;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200819
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200820 out:
821 DPRINTF(stderr, "%s@%d: st=%d, rqf=%x, rpf=%x, rql=%d, rqs=%d, rl=%d, rs=%d\n",
822 __FUNCTION__, __LINE__,
823 si->state, req->flags, res->flags, req->l, req->send_max, res->l, res->send_max);
824
825 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
826 /* check that we have released everything then unregister */
827 stream_int_unregister_handler(si);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200828 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200829}
830
Willy Tarreau24955a12009-10-04 11:54:04 +0200831/* This function is called to send output to the response buffer.
832 * It dumps statistics onto the output buffer <rep> owned by session <s>.
833 * s->data_ctx must have been zeroed first, and the flags properly set.
834 * It returns 0 as long as it does not complete, non-zero upon completion.
835 * Some states are not used but it makes the code more similar to other
836 * functions which handle stats too.
Willy Tarreau3e76e722007-10-17 18:57:38 +0200837 */
Willy Tarreau24955a12009-10-04 11:54:04 +0200838int stats_dump_raw_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau3e76e722007-10-17 18:57:38 +0200839{
Willy Tarreau3e76e722007-10-17 18:57:38 +0200840 struct proxy *px;
841 struct chunk msg;
Willy Tarreaua8efd362008-01-03 10:19:15 +0100842 unsigned int up;
Willy Tarreau3e76e722007-10-17 18:57:38 +0200843
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200844 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3e76e722007-10-17 18:57:38 +0200845
846 switch (s->data_state) {
847 case DATA_ST_INIT:
Willy Tarreau24955a12009-10-04 11:54:04 +0200848 /* the function had not been called yet */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200849 s->data_state = DATA_ST_HEAD;
850 /* fall through */
851
852 case DATA_ST_HEAD:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100853 if (s->data_ctx.stats.flags & STAT_SHOW_STAT) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200854 print_csv_header(&msg);
Willy Tarreau24955a12009-10-04 11:54:04 +0200855 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100856 return 0;
857 }
Willy Tarreau3e76e722007-10-17 18:57:38 +0200858
859 s->data_state = DATA_ST_INFO;
860 /* fall through */
861
862 case DATA_ST_INFO:
Willy Tarreaua8efd362008-01-03 10:19:15 +0100863 up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100864 if (s->data_ctx.stats.flags & STAT_SHOW_INFO) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200865 chunk_printf(&msg,
Willy Tarreaua8efd362008-01-03 10:19:15 +0100866 "Name: " PRODUCT_NAME "\n"
867 "Version: " HAPROXY_VERSION "\n"
868 "Release_date: " HAPROXY_DATE "\n"
869 "Nbproc: %d\n"
870 "Process_num: %d\n"
871 "Pid: %d\n"
872 "Uptime: %dd %dh%02dm%02ds\n"
873 "Uptime_sec: %d\n"
874 "Memmax_MB: %d\n"
875 "Ulimit-n: %d\n"
876 "Maxsock: %d\n"
877 "Maxconn: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +0100878 "Maxpipes: %d\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +0100879 "CurrConns: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +0100880 "PipesUsed: %d\n"
881 "PipesFree: %d\n"
Willy Tarreauc7bdf092009-03-21 18:33:52 +0100882 "Tasks: %d\n"
883 "Run_queue: %d\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200884 "node: %s\n"
885 "description: %s\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +0100886 "",
887 global.nbproc,
888 relative_pid,
889 pid,
890 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
891 up,
892 global.rlimit_memmax,
893 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +0100894 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +0100895 actconn, pipes_used, pipes_free,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200896 nb_tasks_cur, run_queue_cur,
897 global.node, global.desc?global.desc:""
Willy Tarreaua8efd362008-01-03 10:19:15 +0100898 );
Willy Tarreau24955a12009-10-04 11:54:04 +0200899 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100900 return 0;
901 }
902
Willy Tarreau3e76e722007-10-17 18:57:38 +0200903 s->data_ctx.stats.px = proxy;
904 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +0100905
906 s->data_ctx.stats.sv = NULL;
907 s->data_ctx.stats.sv_st = 0;
908
Willy Tarreau3e76e722007-10-17 18:57:38 +0200909 s->data_state = DATA_ST_LIST;
910 /* fall through */
911
912 case DATA_ST_LIST:
913 /* dump proxies */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100914 if (s->data_ctx.stats.flags & STAT_SHOW_STAT) {
Willy Tarreaua8efd362008-01-03 10:19:15 +0100915 while (s->data_ctx.stats.px) {
916 px = s->data_ctx.stats.px;
917 /* skip the disabled proxies and non-networked ones */
918 if (px->state != PR_STSTOPPED &&
Willy Tarreau24955a12009-10-04 11:54:04 +0200919 (px->cap & (PR_CAP_FE | PR_CAP_BE))) {
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100920 if (stats_dump_proxy(s, px, NULL) == 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100921 return 0;
Willy Tarreau24955a12009-10-04 11:54:04 +0200922 }
Willy Tarreau3e76e722007-10-17 18:57:38 +0200923
Willy Tarreaua8efd362008-01-03 10:19:15 +0100924 s->data_ctx.stats.px = px->next;
925 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
926 }
927 /* here, we just have reached the last proxy */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200928 }
Willy Tarreau3e76e722007-10-17 18:57:38 +0200929
930 s->data_state = DATA_ST_END;
931 /* fall through */
932
933 case DATA_ST_END:
934 s->data_state = DATA_ST_FIN;
Willy Tarreau0a464892008-12-07 18:30:00 +0100935 /* fall through */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200936
937 case DATA_ST_FIN:
938 return 1;
939
940 default:
941 /* unknown state ! */
Willy Tarreau24955a12009-10-04 11:54:04 +0200942 s->data_state = DATA_ST_FIN;
943 return 1;
Willy Tarreau3e76e722007-10-17 18:57:38 +0200944 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100945}
946
947
Willy Tarreaub0c9bc42009-10-04 15:56:38 +0200948/* This I/O handler runs as an applet embedded in a stream interface. It is
949 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
950 * si->st0 becomes non-zero once the transfer is finished. The handler
951 * automatically unregisters itself once transfer is complete.
952 */
953void http_stats_io_handler(struct stream_interface *si)
954{
955 struct session *s = si->private;
956 struct buffer *req = si->ob;
957 struct buffer *res = si->ib;
958
959 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
960 goto out;
961
962 /* check that the output is not closed */
963 if (res->flags & (BF_SHUTW|BF_SHUTW_NOW))
964 si->st0 = 1;
965
966 if (!si->st0) {
967 if (stats_dump_http(s, res, s->be->uri_auth)) {
968 si->st0 = 1;
969 si->shutw(si);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +0200970 }
971 }
972
973 if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST))
974 si->shutw(si);
975
976 if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && si->st0) {
977 si->shutr(si);
978 res->flags |= BF_READ_NULL;
979 }
980
981 /* update all other flags and resync with the other side */
982 si->update(si);
983
984 /* we don't want to expire timeouts while we're processing requests */
985 si->ib->rex = TICK_ETERNITY;
986 si->ob->wex = TICK_ETERNITY;
987
988 out:
989 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
990 /* check that we have released everything then unregister */
991 stream_int_unregister_handler(si);
992 }
993}
994
995
Willy Tarreau3e76e722007-10-17 18:57:38 +0200996/*
997 * Produces statistics data for the session <s>. Expects to be called with
Willy Tarreau1ae3a052008-08-16 10:56:30 +0200998 * client socket shut down on input. It stops by itself by unsetting the
Willy Tarreau72b179a2008-08-28 16:01:32 +0200999 * BF_HIJACK flag from the buffer, which it uses to keep on being called
Willy Tarreau1ae3a052008-08-16 10:56:30 +02001000 * when there is free space in the buffer, of simply by letting an empty buffer
1001 * upon return.s->data_ctx must have been zeroed before the first call, and the
1002 * flags set. It returns 0 if it had to stop writing data and an I/O is needed,
1003 * 1 if the dump is finished and the session must be closed, or -1 in case of
1004 * any error.
Willy Tarreau91861262007-10-17 17:06:05 +02001005 */
Willy Tarreau0a464892008-12-07 18:30:00 +01001006int stats_dump_http(struct session *s, struct buffer *rep, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02001007{
Willy Tarreau91861262007-10-17 17:06:05 +02001008 struct proxy *px;
1009 struct chunk msg;
1010 unsigned int up;
1011
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001012 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +02001013
1014 switch (s->data_state) {
1015 case DATA_ST_INIT:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001016 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001017 "HTTP/1.0 200 OK\r\n"
1018 "Cache-Control: no-cache\r\n"
1019 "Connection: close\r\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001020 "Content-Type: %s\r\n",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001021 (s->data_ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html");
Willy Tarreau91861262007-10-17 17:06:05 +02001022
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001023 if (uri->refresh > 0 && !(s->data_ctx.stats.flags & STAT_NO_REFRESH))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001024 chunk_printf(&msg, "Refresh: %d\r\n",
Willy Tarreau91861262007-10-17 17:06:05 +02001025 uri->refresh);
1026
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001027 chunk_printf(&msg, "\r\n");
Willy Tarreau91861262007-10-17 17:06:05 +02001028
1029 s->txn.status = 200;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001030 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau56a560a2009-09-22 19:27:35 +02001031 return 0;
1032
Willy Tarreau91861262007-10-17 17:06:05 +02001033 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1034 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1035 if (!(s->flags & SN_FINST_MASK))
1036 s->flags |= SN_FINST_R;
1037
1038 if (s->txn.meth == HTTP_METH_HEAD) {
1039 /* that's all we return in case of HEAD request */
1040 s->data_state = DATA_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02001041 return 1;
1042 }
1043
1044 s->data_state = DATA_ST_HEAD; /* let's start producing data */
1045 /* fall through */
1046
1047 case DATA_ST_HEAD:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001048 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001049 /* WARNING! This must fit in the first buffer !!! */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001050 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001051 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
1052 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001053 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001054 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
1055 "<style type=\"text/css\"><!--\n"
1056 "body {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001057 " font-family: arial, helvetica, sans-serif;"
Willy Tarreau91861262007-10-17 17:06:05 +02001058 " font-size: 12px;"
1059 " font-weight: normal;"
1060 " color: black;"
1061 " background: white;"
1062 "}\n"
1063 "th,td {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001064 " font-size: 10px;"
Willy Tarreau91861262007-10-17 17:06:05 +02001065 "}\n"
1066 "h1 {"
Willy Tarreauda6721b2009-07-15 10:07:05 +02001067 " font-size: x-large;"
Willy Tarreau91861262007-10-17 17:06:05 +02001068 " margin-bottom: 0.5em;"
1069 "}\n"
1070 "h2 {"
1071 " font-family: helvetica, arial;"
1072 " font-size: x-large;"
1073 " font-weight: bold;"
1074 " font-style: italic;"
1075 " color: #6020a0;"
1076 " margin-top: 0em;"
1077 " margin-bottom: 0em;"
1078 "}\n"
1079 "h3 {"
1080 " font-family: helvetica, arial;"
1081 " font-size: 16px;"
1082 " font-weight: bold;"
1083 " color: #b00040;"
1084 " background: #e8e8d0;"
1085 " margin-top: 0em;"
1086 " margin-bottom: 0em;"
1087 "}\n"
1088 "li {"
1089 " margin-top: 0.25em;"
1090 " margin-right: 2em;"
1091 "}\n"
1092 ".hr {margin-top: 0.25em;"
1093 " border-color: black;"
1094 " border-bottom-style: solid;"
1095 "}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001096 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001097 ".total {background: #20D0D0;color: #ffff80;}\n"
1098 ".frontend {background: #e8e8d0;}\n"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001099 ".socket {background: #d0d0d0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001100 ".backend {background: #e8e8d0;}\n"
1101 ".active0 {background: #ff9090;}\n"
1102 ".active1 {background: #ffd020;}\n"
1103 ".active2 {background: #ffffa0;}\n"
1104 ".active3 {background: #c0ffc0;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001105 ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
1106 ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */
1107 ".active6 {background: #e0e0e0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001108 ".backup0 {background: #ff9090;}\n"
1109 ".backup1 {background: #ff80ff;}\n"
1110 ".backup2 {background: #c060ff;}\n"
1111 ".backup3 {background: #b0d0ff;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001112 ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
1113 ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
1114 ".backup6 {background: #e0e0e0;}\n"
Cyril Bontécd19e512010-01-31 22:34:03 +01001115 ".maintain {background: #c07820;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +02001116 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001117 "\n"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001118 "a.px:link {color: #ffff40; text-decoration: none;}"
1119 "a.px:visited {color: #ffff40; text-decoration: none;}"
1120 "a.px:hover {color: #ffffff; text-decoration: none;}"
1121 "a.lfsb:link {color: #000000; text-decoration: none;}"
1122 "a.lfsb:visited {color: #000000; text-decoration: none;}"
1123 "a.lfsb:hover {color: #505050; text-decoration: none;}"
1124 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001125 "table.tbl { border-collapse: collapse; border-style: none;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001126 "table.tbl td { text-align: right; border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray; white-space: nowrap;}\n"
1127 "table.tbl td.ac { text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001128 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001129 "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 +02001130 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001131 "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001132 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001133 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
1134 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
1135 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
1136 "-->\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001137 "</style></head>\n",
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001138 (uri->flags&ST_SHNODE) ? " on " : "",
1139 (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001140 );
Willy Tarreau55bb8452007-10-17 18:44:57 +02001141 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001142 print_csv_header(&msg);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001143 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001144 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001145 return 0;
1146
1147 s->data_state = DATA_ST_INFO;
1148 /* fall through */
1149
1150 case DATA_ST_INFO:
1151 up = (now.tv_sec - start_date.tv_sec);
1152
1153 /* WARNING! this has to fit the first packet too.
1154 * We are around 3.5 kB, add adding entries will
1155 * become tricky if we want to support 4kB buffers !
1156 */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001157 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001158 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001159 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
1160 PRODUCT_NAME "%s</a></h1>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001161 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001162 "<hr width=\"100%%\" class=\"hr\">\n"
1163 "<h3>&gt; General process information</h3>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001164 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001165 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001166 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001167 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
1168 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
1169 "current conns = %d; current pipes = %d/%d<br>\n"
1170 "Running tasks: %d/%d<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001171 "</td><td align=\"center\" nowrap>\n"
1172 "<table class=\"lgd\"><tr>\n"
1173 "<td class=\"active3\">&nbsp;</td><td class=\"noborder\">active UP </td>"
1174 "<td class=\"backup3\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
1175 "</tr><tr>\n"
1176 "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
1177 "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
1178 "</tr><tr>\n"
1179 "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
1180 "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
1181 "</tr><tr>\n"
1182 "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001183 "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>"
Cyril Bontécd19e512010-01-31 22:34:03 +01001184 "</tr><tr>\n"
1185 "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) &nbsp;</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001186 "</tr></table>\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001187 "Note: UP with load-balancing disabled is reported as \"NOLB\"."
Willy Tarreau91861262007-10-17 17:06:05 +02001188 "</td>"
1189 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
1190 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
1191 "",
1192 (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001193 pid, (uri->flags&ST_SHNODE) ? " on " : "", (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
1194 (uri->flags&ST_SHDESC)? ": " : "", (uri->flags&ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
1195 pid, relative_pid, global.nbproc,
Willy Tarreau91861262007-10-17 17:06:05 +02001196 up / 86400, (up % 86400) / 3600,
1197 (up % 3600) / 60, (up % 60),
1198 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
1199 global.rlimit_memmax ? " MB" : "",
1200 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +01001201 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001202 actconn, pipes_used, pipes_used+pipes_free,
1203 run_queue_cur, nb_tasks_cur
Willy Tarreau91861262007-10-17 17:06:05 +02001204 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001205
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001206 if (s->data_ctx.stats.flags & STAT_HIDE_DOWN)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001207 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001208 "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
1209 uri->uri_prefix,
1210 "",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001211 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001212 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001213 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001214 "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
1215 uri->uri_prefix,
1216 ";up",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001217 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02001218
Willy Tarreau55bb8452007-10-17 18:44:57 +02001219 if (uri->refresh > 0) {
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001220 if (s->data_ctx.stats.flags & STAT_NO_REFRESH)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001221 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001222 "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
1223 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001224 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02001225 "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001226 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001227 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001228 "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
1229 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001230 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02001231 ";norefresh");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001232 }
Willy Tarreau91861262007-10-17 17:06:05 +02001233
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001234 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001235 "<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
1236 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001237 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
1238 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02001239
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001240 chunk_printf(&msg,
Willy Tarreau5031e6a2007-10-18 11:05:48 +02001241 "<li><a href=\"%s;csv%s\">CSV export</a><br>\n",
1242 uri->uri_prefix,
1243 (uri->refresh > 0) ? ";norefresh" : "");
1244
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001245 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001246 "</ul></td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001247 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
1248 "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n"
1249 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
1250 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
1251 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
1252 "</ul>"
1253 "</td>"
1254 "</tr></table>\n"
1255 ""
1256 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001257
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001258 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001259 return 0;
1260 }
Willy Tarreau91861262007-10-17 17:06:05 +02001261
Willy Tarreau91861262007-10-17 17:06:05 +02001262 s->data_ctx.stats.px = proxy;
1263 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
1264 s->data_state = DATA_ST_LIST;
1265 /* fall through */
1266
1267 case DATA_ST_LIST:
1268 /* dump proxies */
1269 while (s->data_ctx.stats.px) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02001270 if (buffer_almost_full(rep))
1271 return 0;
Willy Tarreau91861262007-10-17 17:06:05 +02001272 px = s->data_ctx.stats.px;
1273 /* skip the disabled proxies and non-networked ones */
1274 if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001275 if (stats_dump_proxy(s, px, uri) == 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001276 return 0;
1277
1278 s->data_ctx.stats.px = px->next;
1279 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
1280 }
1281 /* here, we just have reached the last proxy */
1282
1283 s->data_state = DATA_ST_END;
1284 /* fall through */
1285
1286 case DATA_ST_END:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001287 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001288 chunk_printf(&msg, "</body></html>\n");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001289 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001290 return 0;
1291 }
Willy Tarreau91861262007-10-17 17:06:05 +02001292
1293 s->data_state = DATA_ST_FIN;
1294 /* fall through */
1295
1296 case DATA_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02001297 return 1;
1298
1299 default:
1300 /* unknown state ! */
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001301 s->data_state = DATA_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02001302 return -1;
1303 }
1304}
1305
1306
1307/*
1308 * Dumps statistics for a proxy.
1309 * Returns 0 if it had to stop dumping data because of lack of buffer space,
1310 * ot non-zero if everything completed.
1311 */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001312int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02001313{
1314 struct buffer *rep = s->rep;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001315 struct server *sv, *svs; /* server and server-state, server-state=server or server->tracked */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001316 struct listener *l;
Willy Tarreau91861262007-10-17 17:06:05 +02001317 struct chunk msg;
1318
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001319 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +02001320
1321 switch (s->data_ctx.stats.px_st) {
1322 case DATA_ST_PX_INIT:
1323 /* we are on a new proxy */
1324
1325 if (uri && uri->scope) {
1326 /* we have a limited scope, we have to check the proxy name */
1327 struct stat_scope *scope;
1328 int len;
1329
1330 len = strlen(px->id);
1331 scope = uri->scope;
1332
1333 while (scope) {
1334 /* match exact proxy name */
1335 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
1336 break;
1337
1338 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +02001339 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +02001340 break;
1341 scope = scope->next;
1342 }
1343
1344 /* proxy name not found : don't dump anything */
1345 if (scope == NULL)
1346 return 1;
1347 }
1348
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001349 if ((s->data_ctx.stats.flags & STAT_BOUND) && (s->data_ctx.stats.iid != -1) &&
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001350 (px->uuid != s->data_ctx.stats.iid))
1351 return 1;
1352
Willy Tarreau91861262007-10-17 17:06:05 +02001353 s->data_ctx.stats.px_st = DATA_ST_PX_TH;
1354 /* fall through */
1355
1356 case DATA_ST_PX_TH:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001357 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau55bb8452007-10-17 18:44:57 +02001358 /* print a new table */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001359 chunk_printf(&msg,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001360 "<table class=\"tbl\" width=\"100%%\">\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001361 "<tr class=\"titre\">"
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001362 "<th class=\"pxname\" width=\"10%%\"");
1363
1364 if (uri->flags&ST_SHLGNDS) {
1365 /* cap, mode, id */
1366 chunk_printf(&msg, " title=\"cap: %s, mode: %s, id: %d",
1367 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
1368 px->uuid);
1369
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001370 chunk_printf(&msg, "\"");
1371 }
1372
1373 chunk_printf(&msg,
1374 "><a name=\"%s\"></a>"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001375 "<a class=px href=\"#%s\">%s</a></th>"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001376 "<th class=\"%s\" width=\"90%%\">%s</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001377 "</tr>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001378 "</table>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001379 "<table class=\"tbl\" width=\"100%%\">\n"
1380 "<tr class=\"titre\">"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001381 "<th rowspan=2></th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001382 "<th colspan=3>Queue</th>"
1383 "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001384 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001385 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001386 "<th colspan=9>Server</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001387 "</tr>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001388 "<tr class=\"titre\">"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001389 "<th>Cur</th><th>Max</th><th>Limit</th>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001390 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001391 "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001392 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001393 "<th>Resp</th><th>Retr</th><th>Redis</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001394 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001395 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
1396 "<th>Thrtle</th>\n"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001397 "</tr>",
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001398 px->id, px->id, px->id,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001399 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001400
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001401 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001402 return 0;
1403 }
Willy Tarreau91861262007-10-17 17:06:05 +02001404
1405 s->data_ctx.stats.px_st = DATA_ST_PX_FE;
1406 /* fall through */
1407
1408 case DATA_ST_PX_FE:
1409 /* print the frontend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001410 if ((px->cap & PR_CAP_FE) &&
1411 (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_FE)))) {
1412 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001413 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001414 /* name, queue */
Krzysztof Piotr Oledzki516ed492009-10-22 22:48:09 +02001415 "<tr class=\"frontend\"><td class=ac>"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001416 "<a name=\"%s/Frontend\"></a>"
1417 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td><td colspan=3></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001418 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001419 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001420 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001421 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001422 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001423 "",
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001424 px->id, px->id,
Willy Tarreaua3e49422009-05-10 19:19:41 +02001425 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001426 U2H1(px->counters.fe_sps_max), LIM2A2(px->fe_sps_lim, "-"),
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001427 U2H3(px->feconn), U2H4(px->counters.feconn_max), U2H5(px->maxconn));
1428
1429 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
1430 if (px->mode == PR_MODE_HTTP) {
1431 int i;
1432
1433 chunk_printf(&msg, " title=\"rsp codes:");
1434
1435 for (i = 1; i < 6; i++)
1436 chunk_printf(&msg, " %dxx=%lld,", i, px->counters.p.http.rsp[i]);
1437
1438 chunk_printf(&msg, " other=%lld\"", px->counters.p.http.rsp[0]);
1439 }
1440
1441 chunk_printf(&msg,
1442 /* sessions: total, lbtot */
1443 ">%s</td><td></td>"
1444 /* bytes : in, out */
1445 "<td>%s</td><td>%s</td>"
1446 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001447 U2H6(px->counters.cum_feconn), U2H7(px->counters.bytes_in), U2H8(px->counters.bytes_out));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001448
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001449 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001450 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001451 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001452 /* errors : request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001453 "<td>%s</td><td></td><td></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001454 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001455 "<td></td><td></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001456 /* server status : reflect frontend status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001457 "<td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001458 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001459 "<td class=ac colspan=8></td></tr>"
Willy Tarreau91861262007-10-17 17:06:05 +02001460 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001461 U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp),
1462 U2H2(px->counters.failed_req),
Willy Tarreau91861262007-10-17 17:06:05 +02001463 px->state == PR_STRUN ? "OPEN" :
1464 px->state == PR_STIDLE ? "FULL" : "STOP");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001465 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001466 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001467 /* pxid, name, queue cur, queue max, */
1468 "%s,FRONTEND,,,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001469 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001470 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001471 /* bytes : in, out */
1472 "%lld,%lld,"
1473 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001474 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001475 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001476 "%lld,,,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001477 /* warnings: retries, redispatches */
1478 ",,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001479 /* server status : reflect frontend status */
1480 "%s,"
1481 /* rest of server: nothing */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001482 ",,,,,,,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001483 /* pid, iid, sid, throttle, lbtot, tracked, type */
1484 "%d,%d,0,,,,%d,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001485 /* rate, rate_lim, rate_max */
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001486 "%u,%u,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001487 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001488 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02001489 px->id,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001490 px->feconn, px->counters.feconn_max, px->maxconn, px->counters.cum_feconn,
1491 px->counters.bytes_in, px->counters.bytes_out,
1492 px->counters.denied_req, px->counters.denied_resp,
1493 px->counters.failed_req,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001494 px->state == PR_STRUN ? "OPEN" :
Willy Tarreaudcd47712007-11-04 23:35:08 +01001495 px->state == PR_STIDLE ? "FULL" : "STOP",
Willy Tarreau7f062c42009-03-05 18:43:00 +01001496 relative_pid, px->uuid, STATS_TYPE_FE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001497 read_freq_ctr(&px->fe_sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001498 px->fe_sps_lim, px->counters.fe_sps_max);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001499
1500 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1501 if (px->mode == PR_MODE_HTTP) {
1502 int i;
1503
1504 for (i=1; i<6; i++)
1505 chunk_printf(&msg, "%lld,", px->counters.p.http.rsp[i]);
1506
1507 chunk_printf(&msg, "%lld,", px->counters.p.http.rsp[0]);
1508 } else {
1509 chunk_printf(&msg, ",,,,,,");
1510 }
1511
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001512 /* failed health analyses */
1513 chunk_printf(&msg, ",");
1514
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001515 /* finish with EOL */
1516 chunk_printf(&msg, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001517 }
Willy Tarreau91861262007-10-17 17:06:05 +02001518
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001519 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001520 return 0;
1521 }
1522
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001523 s->data_ctx.stats.l = px->listen; /* may be NULL */
1524 s->data_ctx.stats.px_st = DATA_ST_PX_LI;
1525 /* fall through */
1526
1527 case DATA_ST_PX_LI:
1528 /* stats.l has been initialized above */
1529 for (; s->data_ctx.stats.l != NULL; s->data_ctx.stats.l = l->next) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02001530 if (buffer_almost_full(rep))
1531 return 0;
1532
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001533 l = s->data_ctx.stats.l;
1534 if (!l->counters)
1535 continue;
1536
1537 if (s->data_ctx.stats.flags & STAT_BOUND) {
1538 if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SO)))
1539 break;
1540
1541 if (s->data_ctx.stats.sid != -1 && l->luid != s->data_ctx.stats.sid)
1542 continue;
1543 }
1544
1545 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001546 chunk_printf(&msg, "<tr class=socket><td class=ac");
1547
1548 if (uri->flags&ST_SHLGNDS) {
1549 char str[INET6_ADDRSTRLEN], *fmt = NULL;
1550 int port;
1551
1552 chunk_printf(&msg, " title=\"IP: ");
1553
1554 port = (l->addr.ss_family == AF_INET6)
1555 ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port)
1556 : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port);
1557
1558 if (l->addr.ss_family == AF_INET) {
1559 if (inet_ntop(AF_INET,
1560 (const void *)&((struct sockaddr_in *)&l->addr)->sin_addr,
1561 str, sizeof(str)))
1562 fmt = "%s:%d";
1563 } else {
1564 if (inet_ntop(AF_INET6,
1565 (const void *)&((struct sockaddr_in6 *)(&l->addr))->sin6_addr,
1566 str, sizeof(str)))
1567 fmt = "[%s]:%d";
1568 }
1569
1570 if (fmt)
1571 chunk_printf(&msg, fmt, str, port);
1572 else
1573 chunk_printf(&msg, "(%s)", strerror(errno));
1574
1575 /* id */
1576 chunk_printf(&msg, ", id: %d", l->luid);
1577
1578 chunk_printf(&msg, "\"");
1579 }
1580
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001581 chunk_printf(&msg,
1582 /* name, queue */
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001583 "><a name=\"%s/+%s\"></a>"
Krzysztof Piotr Oledzki2ec025d2010-01-04 11:33:32 +01001584 "<a class=lfsb href=\"#%s/+%s\">%s</a></td><td colspan=3></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001585 /* sessions rate: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001586 "<td colspan=3>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001587 /* sessions: current, max, limit, total, lbtot */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001588 "<td>%s</td><td>%s</td><td>%s</td>"
1589 "<td>%s</td><td>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001590 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001591 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001592 "",
Krzysztof Piotr Oledzki2ec025d2010-01-04 11:33:32 +01001593 px->id, l->name, px->id, l->name, l->name,
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001594 U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn),
1595 U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out));
1596
1597 chunk_printf(&msg,
1598 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001599 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001600 /* errors: request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001601 "<td>%s</td><td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001602 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001603 "<td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001604 /* server status: reflect listener status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001605 "<td class=ac>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001606 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001607 "<td class=ac colspan=8></td></tr>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001608 "",
1609 U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp),
1610 U2H2(l->counters->failed_req),
1611 (l->nbconn < l->maxconn) ? "OPEN" : "FULL");
1612 } else {
1613 chunk_printf(&msg,
1614 /* pxid, name, queue cur, queue max, */
1615 "%s,%s,,,"
1616 /* sessions: current, max, limit, total */
1617 "%d,%d,%d,%lld,"
1618 /* bytes: in, out */
1619 "%lld,%lld,"
1620 /* denied: req, resp */
1621 "%lld,%lld,"
1622 /* errors: request, connect, response */
1623 "%lld,,,"
1624 /* warnings: retries, redispatches */
1625 ",,"
1626 /* server status: reflect listener status */
1627 "%s,"
1628 /* rest of server: nothing */
1629 ",,,,,,,,"
1630 /* pid, iid, sid, throttle, lbtot, tracked, type */
1631 "%d,%d,%d,,,,%d,"
1632 /* rate, rate_lim, rate_max */
1633 ",,,"
1634 /* check_status, check_code, check_duration */
1635 ",,,"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001636 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1637 ",,,,,,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001638 /* failed health analyses */
1639 ","
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001640 "\n",
1641 px->id, l->name,
1642 l->nbconn, l->counters->conn_max,
1643 l->maxconn, l->counters->cum_conn,
1644 l->counters->bytes_in, l->counters->bytes_out,
1645 l->counters->denied_req, l->counters->denied_resp,
1646 l->counters->failed_req,
1647 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
1648 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
1649 }
1650
1651 if (buffer_feed_chunk(rep, &msg) >= 0)
1652 return 0;
1653 }
1654
Willy Tarreau91861262007-10-17 17:06:05 +02001655 s->data_ctx.stats.sv = px->srv; /* may be NULL */
1656 s->data_ctx.stats.px_st = DATA_ST_PX_SV;
1657 /* fall through */
1658
1659 case DATA_ST_PX_SV:
1660 /* stats.sv has been initialized above */
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001661 for (; s->data_ctx.stats.sv != NULL; s->data_ctx.stats.sv = sv->next) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01001662 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 +02001663
Willy Tarreau4e33d862009-10-11 23:35:10 +02001664 if (buffer_almost_full(rep))
1665 return 0;
1666
Willy Tarreau91861262007-10-17 17:06:05 +02001667 sv = s->data_ctx.stats.sv;
1668
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001669 if (s->data_ctx.stats.flags & STAT_BOUND) {
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001670 if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SV)))
1671 break;
1672
1673 if (s->data_ctx.stats.sid != -1 && sv->puid != s->data_ctx.stats.sid)
1674 continue;
1675 }
1676
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001677 if (sv->tracked)
1678 svs = sv->tracked;
1679 else
1680 svs = sv;
1681
Willy Tarreau91861262007-10-17 17:06:05 +02001682 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001683 if (!(svs->state & SRV_CHECKED))
Willy Tarreau2ea81932007-11-30 12:04:38 +01001684 sv_state = 6;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001685 else if (svs->state & SRV_RUNNING) {
1686 if (svs->health == svs->rise + svs->fall - 1)
Willy Tarreau91861262007-10-17 17:06:05 +02001687 sv_state = 3; /* UP */
1688 else
1689 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +01001690
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001691 if (svs->state & SRV_GOINGDOWN)
Willy Tarreau2ea81932007-11-30 12:04:38 +01001692 sv_state += 2;
1693 }
Willy Tarreau91861262007-10-17 17:06:05 +02001694 else
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001695 if (svs->health)
Willy Tarreau91861262007-10-17 17:06:05 +02001696 sv_state = 1; /* going up */
1697 else
1698 sv_state = 0; /* DOWN */
1699
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001700 if ((sv_state == 0) && (s->data_ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02001701 /* do not report servers which are DOWN */
1702 s->data_ctx.stats.sv = sv->next;
1703 continue;
1704 }
1705
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001706 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01001707 static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d &uarr;",
1708 "UP %d/%d &darr;", "UP",
1709 "NOLB %d/%d &darr;", "NOLB",
1710 "<i>no check</i>" };
Cyril Bontécd19e512010-01-31 22:34:03 +01001711 if (sv->state & SRV_MAINTAIN) {
1712 chunk_printf(&msg,
1713 /* name */
1714 "<tr class=\"maintain\"><td class=ac"
1715 );
1716 }
1717 else {
1718 chunk_printf(&msg,
1719 /* name */
1720 "<tr class=\"%s%d\"><td class=ac",
1721 (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state);
1722 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001723
1724 if (uri->flags&ST_SHLGNDS) {
1725 char str[INET6_ADDRSTRLEN];
1726
1727 chunk_printf(&msg, " title=\"IP: ");
1728
1729 /* IP */
1730 if (inet_ntop(sv->addr.sin_family, &sv->addr.sin_addr, str, sizeof(str)))
1731 chunk_printf(&msg, "%s:%d", str, htons(sv->addr.sin_port));
1732 else
1733 chunk_printf(&msg, "(%s)", strerror(errno));
1734
1735 /* id */
1736 chunk_printf(&msg, ", id: %d", sv->puid);
1737
1738 /* cookie */
1739 if (sv->cookie) {
1740 struct chunk src;
1741
1742 chunk_printf(&msg, ", cookie: '");
1743
1744 chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie));
1745 chunk_htmlencode(&msg, &src);
1746
1747 chunk_printf(&msg, "'");
1748 }
1749
1750 chunk_printf(&msg, "\"");
1751 }
1752
1753 chunk_printf(&msg,
1754 "><a name=\"%s/%s\"></a>"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001755 "<a class=lfsb href=\"#%s/%s\">%s</a></td>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001756 /* queue : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001757 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001758 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001759 "<td>%s</td><td>%s</td><td></td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001760 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001761 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001762 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001763 "",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001764 px->id, sv->id, px->id, sv->id, sv->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001765 U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"),
1766 U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max),
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001767 U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-"));
1768
1769 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
1770 if (px->mode == PR_MODE_HTTP) {
1771 int i;
1772
1773 chunk_printf(&msg, " title=\"rsp codes:");
1774
1775 for (i = 1; i < 6; i++)
1776 chunk_printf(&msg, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]);
1777
1778 chunk_printf(&msg, " other=%lld\"", sv->counters.p.http.rsp[0]);
1779 }
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001780
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001781 chunk_printf(&msg,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001782 /* sessions: total, lbtot */
1783 ">%s</td><td>%s</td>",
1784 U2H0(sv->counters.cum_sess), U2H1(sv->counters.cum_lbconn));
1785
1786 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001787 /* bytes : in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001788 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001789 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001790 "<td></td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001791 /* errors : request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001792 "<td></td><td>%s</td><td>%s</td>\n"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001793 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001794 "<td>%lld</td><td>%lld</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001795 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001796 U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out),
1797 U2H2(sv->counters.failed_secu),
1798 U2H3(sv->counters.failed_conns), U2H4(sv->counters.failed_resp),
1799 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001800
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001801 /* status, lest check */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001802 chunk_printf(&msg, "<td class=ac>");
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001803
Cyril Bontécd19e512010-01-31 22:34:03 +01001804 if (sv->state & SRV_MAINTAIN) {
1805 chunk_printf(&msg, "%s ",
1806 human_time(now.tv_sec - sv->last_change, 1));
1807 chunk_printf(&msg, "MAINT");
1808 }
1809 else if (svs->state & SRV_CHECKED) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001810 chunk_printf(&msg, "%s ",
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001811 human_time(now.tv_sec - sv->last_change, 1));
1812
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001813 chunk_printf(&msg,
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001814 srv_hlt_st[sv_state],
1815 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
1816 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001817 }
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02001818
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001819 if (sv->state & SRV_CHECKED) {
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001820 chunk_printf(&msg, "</td><td class=ac title=\"%s",
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02001821 get_check_status_description(sv->check_status));
1822
1823 if (*sv->check_desc) {
1824 struct chunk src;
1825
1826 chunk_printf(&msg, ": ");
1827
1828 chunk_initlen(&src, sv->check_desc, 0, strlen(sv->check_desc));
1829 chunk_htmlencode(&msg, &src);
1830 }
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001831
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001832 chunk_printf(&msg, "\"> %s%s",
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001833 tv_iszero(&sv->check_start)?"":"* ",
1834 get_check_status_info(sv->check_status));
1835
1836 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001837 chunk_printf(&msg, "/%d", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001838
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001839 if (sv->check_status >= HCHK_STATUS_CHECKED && sv->check_duration >= 0)
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001840 chunk_printf(&msg, " in %lums", sv->check_duration);
1841 } else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001842 chunk_printf(&msg, "</td><td>");
Willy Tarreau91861262007-10-17 17:06:05 +02001843
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001844 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001845 /* weight */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001846 "</td><td class=ac>%d</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001847 /* act, bck */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001848 "<td class=ac>%s</td><td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001849 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01001850 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau91861262007-10-17 17:06:05 +02001851 (sv->state & SRV_BACKUP) ? "-" : "Y",
1852 (sv->state & SRV_BACKUP) ? "Y" : "-");
1853
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001854 /* check failures: unique, fatal, down time */
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01001855 if (sv->state & SRV_CHECKED) {
1856 chunk_printf(&msg, "<td title=\"Failed Health Checks%s\">%lld",
1857 svs->observe?"/Health Analyses":"", svs->counters.failed_checks);
1858
1859 if (svs->observe)
1860 chunk_printf(&msg, "/%lld", svs->counters.failed_hana);
1861
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001862 chunk_printf(&msg,
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01001863 "</td>"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001864 "<td>%lld</td><td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001865 "",
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001866 svs->counters.down_trans, human_time(srv_downtime(sv), 1));
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01001867 } else if (sv != svs)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001868 chunk_printf(&msg,
Krzysztof Piotr Oledzki88a14af2010-01-05 18:33:01 +01001869 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>",
1870 svs->proxy->id, svs->id, svs->proxy->id, svs->id);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001871 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001872 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001873 "<td colspan=3></td>");
1874
1875 /* throttle */
1876 if ((sv->state & SRV_WARMINGUP) &&
1877 now.tv_sec < sv->last_change + sv->slowstart &&
1878 now.tv_sec >= sv->last_change) {
1879 unsigned int ratio;
1880 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001881 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001882 "<td class=ac>%d %%</td></tr>\n", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001883 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001884 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001885 "<td class=ac>-</td></tr>\n");
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001886 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02001887 } else {
Willy Tarreau2ea81932007-11-30 12:04:38 +01001888 static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
1889 "UP %d/%d,", "UP,",
1890 "NOLB %d/%d,", "NOLB,",
1891 "no check," };
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001892 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001893 /* pxid, name */
1894 "%s,%s,"
1895 /* queue : current, max */
1896 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001897 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001898 "%d,%d,%s,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001899 /* bytes : in, out */
1900 "%lld,%lld,"
1901 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001902 ",%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001903 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001904 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001905 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001906 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001907 "",
1908 px->id, sv->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001909 sv->nbpend, sv->counters.nbpend_max,
1910 sv->cur_sess, sv->counters.cur_sess_max, LIM2A0(sv->maxconn, ""), sv->counters.cum_sess,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001911 sv->counters.bytes_in, sv->counters.bytes_out,
1912 sv->counters.failed_secu,
1913 sv->counters.failed_conns, sv->counters.failed_resp,
1914 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001915
Willy Tarreau55bb8452007-10-17 18:44:57 +02001916 /* status */
Cyril Bontécd19e512010-01-31 22:34:03 +01001917 if (sv->state & SRV_MAINTAIN) {
1918 chunk_printf(&msg, "MAINT,");
1919 } else {
1920 chunk_printf(&msg,
1921 srv_hlt_st[sv_state],
1922 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
1923 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
1924 }
Willy Tarreau91861262007-10-17 17:06:05 +02001925
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001926 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001927 /* weight, active, backup */
1928 "%d,%d,%d,"
1929 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01001930 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001931 (sv->state & SRV_BACKUP) ? 0 : 1,
1932 (sv->state & SRV_BACKUP) ? 1 : 0);
1933
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001934 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreau55bb8452007-10-17 18:44:57 +02001935 if (sv->state & SRV_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001936 chunk_printf(&msg,
Willy Tarreau3b88d442009-04-11 20:44:08 +02001937 "%lld,%lld,%d,%d,",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001938 sv->counters.failed_checks, sv->counters.down_trans,
Willy Tarreau1772ece2009-04-03 14:49:12 +02001939 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
Willy Tarreau55bb8452007-10-17 18:44:57 +02001940 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001941 chunk_printf(&msg,
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001942 ",,,,");
1943
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001944 /* queue limit, pid, iid, sid, */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001945 chunk_printf(&msg,
Willy Tarreaudcd47712007-11-04 23:35:08 +01001946 "%s,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001947 "%d,%d,%d,",
Willy Tarreaudcd47712007-11-04 23:35:08 +01001948 LIM2A0(sv->maxqueue, ""),
1949 relative_pid, px->uuid, sv->puid);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001950
1951 /* throttle */
1952 if ((sv->state & SRV_WARMINGUP) &&
1953 now.tv_sec < sv->last_change + sv->slowstart &&
1954 now.tv_sec >= sv->last_change) {
1955 unsigned int ratio;
1956 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001957 chunk_printf(&msg, "%d", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001958 }
1959
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001960 /* sessions: lbtot */
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001961 chunk_printf(&msg, ",%lld,", sv->counters.cum_lbconn);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001962
1963 /* tracked */
1964 if (sv->tracked)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001965 chunk_printf(&msg, "%s/%s,",
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001966 sv->tracked->proxy->id, sv->tracked->id);
1967 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001968 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001969
Willy Tarreau7f062c42009-03-05 18:43:00 +01001970 /* type */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001971 chunk_printf(&msg, "%d,", STATS_TYPE_SV);
Willy Tarreau7f062c42009-03-05 18:43:00 +01001972
1973 /* rate */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001974 chunk_printf(&msg, "%u,,%u,",
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001975 read_freq_ctr(&sv->sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001976 sv->counters.sps_max);
Willy Tarreau7f062c42009-03-05 18:43:00 +01001977
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001978 if (sv->state & SRV_CHECKED) {
1979 /* check_status */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001980 chunk_printf(&msg, "%s,", get_check_status_info(sv->check_status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001981
1982 /* check_code */
1983 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001984 chunk_printf(&msg, "%u,", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001985 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001986 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001987
1988 /* check_duration */
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001989 if (sv->check_status >= HCHK_STATUS_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001990 chunk_printf(&msg, "%lu,", sv->check_duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001991 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001992 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001993
1994 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001995 chunk_printf(&msg, ",,,");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001996 }
1997
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001998 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1999 if (px->mode == PR_MODE_HTTP) {
2000 int i;
2001
2002 for (i=1; i<6; i++)
2003 chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[i]);
2004
2005 chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[0]);
2006 } else {
2007 chunk_printf(&msg, ",,,,,,");
2008 }
2009
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002010 /* failed health analyses */
2011 chunk_printf(&msg, "%lld,", sv->counters.failed_hana);
2012
Willy Tarreau7f062c42009-03-05 18:43:00 +01002013 /* finish with EOL */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002014 chunk_printf(&msg, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002015 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002016 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002017 return 0;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002018 } /* for sv */
Willy Tarreau91861262007-10-17 17:06:05 +02002019
2020 s->data_ctx.stats.px_st = DATA_ST_PX_BE;
2021 /* fall through */
2022
2023 case DATA_ST_PX_BE:
2024 /* print the backend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002025 if ((px->cap & PR_CAP_BE) &&
2026 (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_BE)))) {
2027 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002028 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002029 /* name */
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002030 "<tr class=\"backend\"><td class=ac");
2031
2032 if (uri->flags&ST_SHLGNDS) {
2033 /* balancing */
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01002034 chunk_printf(&msg, " title=\"balancing: %s",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002035 backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01002036
2037 /* cookie */
2038 if (px->cookie_name) {
2039 struct chunk src;
2040
2041 chunk_printf(&msg, ", cookie: '");
2042
2043 chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name));
2044 chunk_htmlencode(&msg, &src);
2045
2046 chunk_printf(&msg, "'");
2047 }
2048
2049 chunk_printf(&msg, "\"");
2050
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002051 }
2052
2053 chunk_printf(&msg,
2054 "><a name=\"%s/Backend\"></a>"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002055 "<a class=lfsb href=\"#%s/Backend\">Backend</a></td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002056 /* queue : current, max */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002057 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002058 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002059 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002060 "",
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002061 px->id, px->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002062 U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->counters.nbpend_max),
2063 U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->counters.be_sps_max));
Willy Tarreaua3e49422009-05-10 19:19:41 +02002064
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002065 chunk_printf(&msg,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002066 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002067 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002068 "<td"
2069 "",
2070 U2H2(px->beconn), U2H3(px->counters.beconn_max), U2H4(px->fullconn));
2071
2072 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2073 if (px->mode == PR_MODE_HTTP) {
2074 int i;
2075
2076 chunk_printf(&msg, " title=\"rsp codes:");
2077
2078 for (i = 1; i < 6; i++)
2079 chunk_printf(&msg, " %dxx=%lld", i, px->counters.p.http.rsp[i]);
2080
2081 chunk_printf(&msg, " other=%lld\"", px->counters.p.http.rsp[0]);
2082 }
2083
2084 chunk_printf(&msg,
2085 /* sessions: total, lbtot */
2086 ">%s</td><td>%s</td>"
2087 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002088 "<td>%s</td><td>%s</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002089 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002090 U2H6(px->counters.cum_beconn), U2H7(px->counters.cum_lbconn),
2091 U2H8(px->counters.bytes_in), U2H9(px->counters.bytes_out));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002092
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002093 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002094 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002095 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002096 /* errors : request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002097 "<td></td><td>%s</td><td>%s</td>\n"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002098 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002099 "<td>%lld</td><td>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002100 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau91861262007-10-17 17:06:05 +02002101 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002102 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau91861262007-10-17 17:06:05 +02002103 * active and backups. */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002104 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
2105 "<td class=ac>%d</td><td class=ac>%d</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002106 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002107 U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp),
2108 U2H2(px->counters.failed_conns), U2H3(px->counters.failed_resp),
2109 px->counters.retries, px->counters.redispatches,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002110 human_time(now.tv_sec - px->last_change, 1),
Willy Tarreau2ea81932007-11-30 12:04:38 +01002111 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
2112 "<font color=\"red\"><b>DOWN</b></font>",
Willy Tarreau5542af62007-12-03 02:04:00 +01002113 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01002114 px->srv_act, px->srv_bck);
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002115
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002116 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002117 /* rest of backend: nothing, down transitions, total downtime, throttle */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002118 "<td class=ac>&nbsp;</td><td>%d</td>"
2119 "<td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002120 "<td></td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002121 "</tr>",
2122 px->down_trans,
2123 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002124 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002125 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002126 /* pxid, name */
2127 "%s,BACKEND,"
2128 /* queue : current, max */
2129 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002130 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002131 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002132 /* bytes : in, out */
2133 "%lld,%lld,"
2134 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002135 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002136 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002137 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002138 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002139 "%lld,%lld,"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002140 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau55bb8452007-10-17 18:44:57 +02002141 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002142 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau55bb8452007-10-17 18:44:57 +02002143 * active and backups. */
2144 "%s,"
2145 "%d,%d,%d,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002146 /* rest of backend: nothing, down transitions, last change, total downtime */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002147 ",%d,%d,%d,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002148 /* pid, iid, sid, throttle, lbtot, tracked, type */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002149 "%d,%d,0,,%lld,,%d,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002150 /* rate, rate_lim, rate_max, */
2151 "%u,,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002152 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002153 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02002154 px->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002155 px->nbpend /* or px->totpend ? */, px->counters.nbpend_max,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002156 px->beconn, px->counters.beconn_max, px->fullconn, px->counters.cum_beconn,
2157 px->counters.bytes_in, px->counters.bytes_out,
2158 px->counters.denied_req, px->counters.denied_resp,
2159 px->counters.failed_conns, px->counters.failed_resp,
2160 px->counters.retries, px->counters.redispatches,
Willy Tarreau20697042007-11-15 23:26:18 +01002161 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
Willy Tarreau5542af62007-12-03 02:04:00 +01002162 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01002163 px->srv_act, px->srv_bck,
Willy Tarreau1772ece2009-04-03 14:49:12 +02002164 px->down_trans, (int)(now.tv_sec - px->last_change),
Willy Tarreau20697042007-11-15 23:26:18 +01002165 px->srv?be_downtime(px):0,
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002166 relative_pid, px->uuid,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002167 px->counters.cum_lbconn, STATS_TYPE_BE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002168 read_freq_ctr(&px->be_sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002169 px->counters.be_sps_max);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002170
2171 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2172 if (px->mode == PR_MODE_HTTP) {
2173 int i;
2174
2175 for (i=1; i<6; i++)
2176 chunk_printf(&msg, "%lld,", px->counters.p.http.rsp[i]);
2177
2178 chunk_printf(&msg, "%lld,", px->counters.p.http.rsp[0]);
2179 } else {
2180 chunk_printf(&msg, ",,,,,,");
2181 }
2182
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002183 /* failed health analyses */
2184 chunk_printf(&msg, ",");
2185
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002186 /* finish with EOL */
2187 chunk_printf(&msg, "\n");
2188
Willy Tarreau55bb8452007-10-17 18:44:57 +02002189 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002190 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002191 return 0;
2192 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002193
Willy Tarreau91861262007-10-17 17:06:05 +02002194 s->data_ctx.stats.px_st = DATA_ST_PX_END;
2195 /* fall through */
2196
2197 case DATA_ST_PX_END:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002198 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002199 chunk_printf(&msg, "</table><p>\n");
Willy Tarreau91861262007-10-17 17:06:05 +02002200
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002201 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002202 return 0;
2203 }
Willy Tarreau91861262007-10-17 17:06:05 +02002204
2205 s->data_ctx.stats.px_st = DATA_ST_PX_FIN;
2206 /* fall through */
2207
2208 case DATA_ST_PX_FIN:
2209 return 1;
2210
2211 default:
2212 /* unknown state, we should put an abort() here ! */
2213 return 1;
2214 }
2215}
2216
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002217
2218/* This function is called to send output to the response buffer.
2219 * It dumps the sessions states onto the output buffer <rep>.
2220 * Expects to be called with client socket shut down on input.
2221 * s->data_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002222 * It returns 0 as long as it does not complete, non-zero upon completion.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002223 */
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002224int stats_dump_sess_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002225{
2226 struct chunk msg;
2227
2228 if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) {
2229 /* If we're forced to shut down, we might have to remove our
2230 * reference to the last session being dumped.
2231 */
2232 if (s->data_state == DATA_ST_LIST) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002233 if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002234 LIST_DEL(&s->data_ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002235 LIST_INIT(&s->data_ctx.sess.bref.users);
2236 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002237 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002238 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002239 }
2240
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002241 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002242
2243 switch (s->data_state) {
2244 case DATA_ST_INIT:
2245 /* the function had not been called yet, let's prepare the
2246 * buffer for a response. We initialize the current session
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002247 * pointer to the first in the global list. When a target
2248 * session is being destroyed, it is responsible for updating
2249 * this pointer. We know we have reached the end when this
2250 * pointer points back to the head of the sessions list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002251 */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002252 LIST_INIT(&s->data_ctx.sess.bref.users);
2253 s->data_ctx.sess.bref.ref = sessions.n;
2254 s->data_state = DATA_ST_LIST;
2255 /* fall through */
2256
2257 case DATA_ST_LIST:
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002258 /* first, let's detach the back-ref from a possible previous session */
2259 if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) {
2260 LIST_DEL(&s->data_ctx.sess.bref.users);
2261 LIST_INIT(&s->data_ctx.sess.bref.users);
2262 }
2263
2264 /* and start from where we stopped */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002265 while (s->data_ctx.sess.bref.ref != &sessions) {
2266 char pn[INET6_ADDRSTRLEN + strlen(":65535")];
2267 struct session *curr_sess;
2268
2269 curr_sess = LIST_ELEM(s->data_ctx.sess.bref.ref, struct session *, list);
2270
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002271 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002272 "%p: proto=%s",
2273 curr_sess,
2274 curr_sess->listener->proto->name);
2275
2276 switch (curr_sess->listener->proto->sock_family) {
2277 case AF_INET:
2278 inet_ntop(AF_INET,
2279 (const void *)&((struct sockaddr_in *)&curr_sess->cli_addr)->sin_addr,
2280 pn, sizeof(pn));
2281
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002282 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002283 " src=%s:%d fe=%s be=%s srv=%s",
2284 pn,
2285 ntohs(((struct sockaddr_in *)&curr_sess->cli_addr)->sin_port),
2286 curr_sess->fe->id,
2287 curr_sess->be->id,
2288 curr_sess->srv ? curr_sess->srv->id : "<none>"
2289 );
2290 break;
2291 case AF_INET6:
2292 inet_ntop(AF_INET6,
2293 (const void *)&((struct sockaddr_in6 *)(&curr_sess->cli_addr))->sin6_addr,
2294 pn, sizeof(pn));
2295
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002296 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002297 " src=%s:%d fe=%s be=%s srv=%s",
2298 pn,
2299 ntohs(((struct sockaddr_in6 *)&curr_sess->cli_addr)->sin6_port),
2300 curr_sess->fe->id,
2301 curr_sess->be->id,
2302 curr_sess->srv ? curr_sess->srv->id : "<none>"
2303 );
2304
2305 break;
2306 case AF_UNIX:
2307 /* no more information to print right now */
2308 break;
2309 }
2310
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002311 chunk_printf(&msg,
Willy Tarreau65671ab2009-10-04 14:24:59 +02002312 " ts=%02x age=%s calls=%d",
2313 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01002314 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
2315 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002316
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002317 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002318 " rq[f=%06xh,l=%d,an=%02xh,rx=%s",
2319 curr_sess->req->flags,
2320 curr_sess->req->l,
2321 curr_sess->req->analysers,
2322 curr_sess->req->rex ?
2323 human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
2324 TICKS_TO_MS(1000)) : "");
2325
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002326 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002327 ",wx=%s",
2328 curr_sess->req->wex ?
2329 human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms),
2330 TICKS_TO_MS(1000)) : "");
2331
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002332 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002333 ",ax=%s]",
2334 curr_sess->req->analyse_exp ?
2335 human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms),
2336 TICKS_TO_MS(1000)) : "");
2337
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002338 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002339 " rp[f=%06xh,l=%d,an=%02xh,rx=%s",
2340 curr_sess->rep->flags,
2341 curr_sess->rep->l,
2342 curr_sess->rep->analysers,
2343 curr_sess->rep->rex ?
2344 human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
2345 TICKS_TO_MS(1000)) : "");
2346
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002347 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002348 ",wx=%s",
2349 curr_sess->rep->wex ?
2350 human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms),
2351 TICKS_TO_MS(1000)) : "");
2352
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002353 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002354 ",ax=%s]",
2355 curr_sess->rep->analyse_exp ?
2356 human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms),
2357 TICKS_TO_MS(1000)) : "");
2358
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002359 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002360 " s0=[%d,%1xh,fd=%d,ex=%s]",
2361 curr_sess->si[0].state,
2362 curr_sess->si[0].flags,
2363 curr_sess->si[0].fd,
2364 curr_sess->si[0].exp ?
2365 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
2366 TICKS_TO_MS(1000)) : "");
2367
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002368 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002369 " s1=[%d,%1xh,fd=%d,ex=%s]",
2370 curr_sess->si[1].state,
2371 curr_sess->si[1].flags,
2372 curr_sess->si[1].fd,
2373 curr_sess->si[1].exp ?
2374 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
2375 TICKS_TO_MS(1000)) : "");
2376
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002377 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002378 " exp=%s",
2379 curr_sess->task->expire ?
2380 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
2381 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01002382 if (task_in_rq(curr_sess->task))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002383 chunk_printf(&msg, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002384
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002385 chunk_printf(&msg, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002386
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002387 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002388 /* let's try again later from this session. We add ourselves into
2389 * this session's users so that it can remove us upon termination.
2390 */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002391 LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002392 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002393 }
2394
2395 s->data_ctx.sess.bref.ref = curr_sess->list.n;
2396 }
2397 s->data_state = DATA_ST_FIN;
2398 /* fall through */
2399
2400 default:
2401 s->data_state = DATA_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002402 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002403 }
2404}
2405
Willy Tarreau74808cb2009-03-04 15:53:18 +01002406/* print a line of error buffer (limited to 70 bytes) to <out>. The format is :
2407 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
2408 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
2409 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
2410 * lines are respected within the limit of 70 output chars. Lines that are
2411 * continuation of a previous truncated line begin with "+" instead of " "
2412 * after the offset. The new pointer is returned.
2413 */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002414static int dump_error_line(struct chunk *out, struct error_snapshot *err,
2415 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01002416{
2417 int end;
2418 unsigned char c;
2419
2420 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002421 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01002422 return ptr;
2423
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002424 chunk_printf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01002425
Willy Tarreau61b34732009-10-03 23:49:35 +02002426 while (ptr < err->len && ptr < sizeof(err->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002427 c = err->buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01002428 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002429 if (out->len > end - 2)
2430 break;
2431 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01002432 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002433 if (out->len > end - 3)
2434 break;
2435 out->str[out->len++] = '\\';
2436 switch (c) {
2437 case '\t': c = 't'; break;
2438 case '\n': c = 'n'; break;
2439 case '\r': c = 'r'; break;
2440 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01002441 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002442 }
2443 out->str[out->len++] = c;
2444 } else {
2445 if (out->len > end - 5)
2446 break;
2447 out->str[out->len++] = '\\';
2448 out->str[out->len++] = 'x';
2449 out->str[out->len++] = hextab[(c >> 4) & 0xF];
2450 out->str[out->len++] = hextab[c & 0xF];
2451 }
2452 if (err->buf[ptr++] == '\n') {
2453 /* we had a line break, let's return now */
2454 out->str[out->len++] = '\n';
2455 *line = ptr;
2456 return ptr;
2457 }
2458 }
2459 /* we have an incomplete line, we return it as-is */
2460 out->str[out->len++] = '\n';
2461 return ptr;
2462}
2463
2464/* This function is called to send output to the response buffer.
2465 * It dumps the errors logged in proxies onto the output buffer <rep>.
2466 * Expects to be called with client socket shut down on input.
2467 * s->data_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau61b34732009-10-03 23:49:35 +02002468 * It returns 0 as long as it does not complete, non-zero upon completion.
Willy Tarreau74808cb2009-03-04 15:53:18 +01002469 */
Willy Tarreau61b34732009-10-03 23:49:35 +02002470int stats_dump_errors_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau74808cb2009-03-04 15:53:18 +01002471{
2472 extern const char *monthname[12];
2473 struct chunk msg;
2474
Willy Tarreau61b34732009-10-03 23:49:35 +02002475 if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW)))
2476 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002477
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002478 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau74808cb2009-03-04 15:53:18 +01002479
2480 if (!s->data_ctx.errors.px) {
2481 /* the function had not been called yet, let's prepare the
2482 * buffer for a response.
2483 */
Willy Tarreau74808cb2009-03-04 15:53:18 +01002484 s->data_ctx.errors.px = proxy;
2485 s->data_ctx.errors.buf = 0;
2486 s->data_ctx.errors.bol = 0;
2487 s->data_ctx.errors.ptr = -1;
2488 }
2489
2490 /* we have two inner loops here, one for the proxy, the other one for
2491 * the buffer.
2492 */
2493 while (s->data_ctx.errors.px) {
2494 struct error_snapshot *es;
2495
2496 if (s->data_ctx.errors.buf == 0)
2497 es = &s->data_ctx.errors.px->invalid_req;
2498 else
2499 es = &s->data_ctx.errors.px->invalid_rep;
2500
2501 if (!es->when.tv_sec)
2502 goto next;
2503
2504 if (s->data_ctx.errors.iid >= 0 &&
2505 s->data_ctx.errors.px->uuid != s->data_ctx.errors.iid &&
2506 es->oe->uuid != s->data_ctx.errors.iid)
2507 goto next;
2508
2509 if (s->data_ctx.errors.ptr < 0) {
2510 /* just print headers now */
2511
2512 char pn[INET6_ADDRSTRLEN];
2513 struct tm tm;
2514
2515 get_localtime(es->when.tv_sec, &tm);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002516 chunk_printf(&msg, "\n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01002517 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02002518 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01002519
2520
2521 if (es->src.ss_family == AF_INET)
2522 inet_ntop(AF_INET,
2523 (const void *)&((struct sockaddr_in *)&es->src)->sin_addr,
2524 pn, sizeof(pn));
2525 else
2526 inet_ntop(AF_INET6,
2527 (const void *)&((struct sockaddr_in6 *)(&es->src))->sin6_addr,
2528 pn, sizeof(pn));
2529
2530 switch (s->data_ctx.errors.buf) {
2531 case 0:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002532 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01002533 " frontend %s (#%d): invalid request\n"
2534 " src %s, session #%d, backend %s (#%d), server %s (#%d)\n"
2535 " request length %d bytes, error at position %d:\n\n",
2536 s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid,
2537 pn, es->sid, es->oe->id, es->oe->uuid,
2538 es->srv ? es->srv->id : "<NONE>",
2539 es->srv ? es->srv->puid : -1,
2540 es->len, es->pos);
2541 break;
2542 case 1:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002543 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01002544 " backend %s (#%d) : invalid response\n"
2545 " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n"
2546 " response length %d bytes, error at position %d:\n\n",
2547 s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid,
2548 pn, es->sid, es->oe->id, es->oe->uuid,
2549 es->srv ? es->srv->id : "<NONE>",
2550 es->srv ? es->srv->puid : -1,
2551 es->len, es->pos);
2552 break;
2553 }
2554
Willy Tarreau61b34732009-10-03 23:49:35 +02002555 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002556 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02002557 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002558 }
2559 s->data_ctx.errors.ptr = 0;
2560 s->data_ctx.errors.sid = es->sid;
2561 }
2562
2563 if (s->data_ctx.errors.sid != es->sid) {
2564 /* the snapshot changed while we were dumping it */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002565 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01002566 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreau61b34732009-10-03 23:49:35 +02002567 if (buffer_feed_chunk(rep, &msg) >= 0)
2568 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002569 goto next;
2570 }
2571
2572 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau61b34732009-10-03 23:49:35 +02002573 while (s->data_ctx.errors.ptr < es->len && s->data_ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002574 int newptr;
2575 int newline;
2576
2577 newline = s->data_ctx.errors.bol;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002578 newptr = dump_error_line(&msg, es, &newline, s->data_ctx.errors.ptr);
Willy Tarreau74808cb2009-03-04 15:53:18 +01002579 if (newptr == s->data_ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02002580 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002581
Willy Tarreau61b34732009-10-03 23:49:35 +02002582 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002583 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02002584 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002585 }
2586 s->data_ctx.errors.ptr = newptr;
2587 s->data_ctx.errors.bol = newline;
2588 };
2589 next:
2590 s->data_ctx.errors.bol = 0;
2591 s->data_ctx.errors.ptr = -1;
2592 s->data_ctx.errors.buf++;
2593 if (s->data_ctx.errors.buf > 1) {
2594 s->data_ctx.errors.buf = 0;
2595 s->data_ctx.errors.px = s->data_ctx.errors.px->next;
2596 }
2597 }
2598
2599 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02002600 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002601}
2602
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002603
Willy Tarreau10522fd2008-07-09 20:12:41 +02002604static struct cfg_kw_list cfg_kws = {{ },{
2605 { CFG_GLOBAL, "stats", stats_parse_global },
2606 { 0, NULL, NULL },
2607}};
2608
2609__attribute__((constructor))
2610static void __dumpstats_module_init(void)
2611{
2612 cfg_register_keywords(&cfg_kws);
2613}
2614
Willy Tarreau91861262007-10-17 17:06:05 +02002615/*
2616 * Local variables:
2617 * c-indent-level: 8
2618 * c-basic-offset: 8
2619 * End:
2620 */