blob: 1d1e0ff62245f05707044661eda07a556b3e3f86 [file] [log] [blame]
Willy Tarreau91861262007-10-17 17:06:05 +02001/*
Willy Tarreaueb472682010-05-28 18:46:57 +02002 * Functions dedicated to statistics output and the stats socket
Willy Tarreau91861262007-10-17 17:06:05 +02003 *
Willy Tarreaueb472682010-05-28 18:46:57 +02004 * Copyright 2000-2010 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 Tarreaueb472682010-05-28 18:46:57 +020047#include <proto/log.h>
Willy Tarreaua206fa92009-01-25 14:02:00 +010048#include <proto/pipe.h>
Willy Tarreaufbee7132007-10-18 13:53:22 +020049#include <proto/proto_uxst.h>
Willy Tarreau89a63132009-08-16 17:41:45 +020050#include <proto/proxy.h>
Willy Tarreau91861262007-10-17 17:06:05 +020051#include <proto/session.h>
Krzysztof Oledzki85130942007-10-22 16:21:10 +020052#include <proto/server.h>
Willy Tarreaudded32d2008-11-30 19:48:07 +010053#include <proto/stream_interface.h>
Willy Tarreaueb472682010-05-28 18:46:57 +020054#include <proto/stream_sock.h>
Willy Tarreau4726f532009-03-07 17:25:21 +010055#include <proto/task.h>
Willy Tarreau91861262007-10-17 17:06:05 +020056
Willy Tarreau5ca791d2009-08-16 19:06:42 +020057const char stats_sock_usage_msg[] =
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020058 "Unknown command. Please enter one of the following commands only :\n"
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +020059 " clear counters : clear max statistics counters (add 'all' for all counters)\n"
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020060 " help : this message\n"
61 " prompt : toggle interactive mode with prompt\n"
62 " quit : disconnect\n"
63 " show info : report information about the running process\n"
64 " show stat : report counters for each proxy and server\n"
65 " show errors : report last request and response errors for each proxy\n"
Willy Tarreau66dc20a2010-03-05 17:53:32 +010066 " show sess [id] : report the list of current sessions or dump this session\n"
Willy Tarreau38338fa2009-10-10 18:37:29 +020067 " get weight : report a server's current weight\n"
Willy Tarreau4483d432009-10-10 19:30:08 +020068 " set weight : change a server's weight\n"
Willy Tarreau7aabd112010-01-26 10:59:06 +010069 " set timeout : change a timeout setting\n"
Cyril Bontécd19e512010-01-31 22:34:03 +010070 " disable server : set a server in maintenance mode\n"
71 " enable server : re-enable a server that was previously in maintenance mode\n"
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020072 "";
Willy Tarreau5ca791d2009-08-16 19:06:42 +020073
Willy Tarreau6162db22009-10-10 17:13:00 +020074const char stats_permission_denied_msg[] =
75 "Permission denied\n"
76 "";
77
Willy Tarreaudecd14d2010-06-01 18:03:19 +020078/* This function is called from the session-level accept() in order to instanciate
Willy Tarreaueb472682010-05-28 18:46:57 +020079 * a new stats socket. It returns a positive value upon success, 0 if the connection
80 * needs to be closed and ignored, or a negative value upon critical failure.
81 */
Willy Tarreaudecd14d2010-06-01 18:03:19 +020082int stats_accept(struct session *s)
Willy Tarreaueb472682010-05-28 18:46:57 +020083{
Willy Tarreaudecd14d2010-06-01 18:03:19 +020084 /* we have a dedicated I/O handler for the stats */
Willy Tarreaueb472682010-05-28 18:46:57 +020085 stream_int_register_handler(&s->si[1], stats_io_handler);
86 s->si[1].private = s;
87 s->si[1].st1 = 0;
88 s->si[1].st0 = STAT_CLI_INIT;
89
Willy Tarreaudecd14d2010-06-01 18:03:19 +020090 tv_zero(&s->logs.tv_request);
91 s->logs.t_queue = 0;
92 s->logs.t_connect = 0;
93 s->logs.t_data = 0;
94 s->logs.t_close = 0;
95 s->logs.bytes_in = s->logs.bytes_out = 0;
96 s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */
97 s->logs.srv_queue_size = 0; /* we will get this number soon */
Willy Tarreaueb472682010-05-28 18:46:57 +020098
99 s->data_state = DATA_ST_INIT;
100 s->data_source = DATA_SRC_NONE;
Willy Tarreaueb472682010-05-28 18:46:57 +0200101
Willy Tarreaueb472682010-05-28 18:46:57 +0200102 s->req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */
103
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200104 if (s->listener->timeout) {
105 s->req->rto = *s->listener->timeout;
106 s->rep->wto = *s->listener->timeout;
Willy Tarreaueb472682010-05-28 18:46:57 +0200107 }
Willy Tarreaueb472682010-05-28 18:46:57 +0200108 return 1;
Willy Tarreaueb472682010-05-28 18:46:57 +0200109}
110
Willy Tarreaufbee7132007-10-18 13:53:22 +0200111/* This function parses a "stats" statement in the "global" section. It returns
112 * -1 if there is any error, otherwise zero. If it returns -1, it may write an
113 * error message into ther <err> buffer, for at most <errlen> bytes, trailing
114 * zero included. The trailing '\n' must not be written. The function must be
115 * called with <args> pointing to the first word after "stats".
116 */
Willy Tarreau10522fd2008-07-09 20:12:41 +0200117static int stats_parse_global(char **args, int section_type, struct proxy *curpx,
118 struct proxy *defpx, char *err, int errlen)
Willy Tarreaufbee7132007-10-18 13:53:22 +0200119{
Willy Tarreau10522fd2008-07-09 20:12:41 +0200120 args++;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200121 if (!strcmp(args[0], "socket")) {
122 struct sockaddr_un su;
123 int cur_arg;
124
125 if (*args[1] == 0) {
126 snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket");
127 return -1;
128 }
129
130 if (global.stats_sock.state != LI_NEW) {
131 snprintf(err, errlen, "'stats socket' already specified in global section");
132 return -1;
133 }
134
135 su.sun_family = AF_UNIX;
136 strncpy(su.sun_path, args[1], sizeof(su.sun_path));
137 su.sun_path[sizeof(su.sun_path) - 1] = 0;
138 memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit
139
Willy Tarreau89a63132009-08-16 17:41:45 +0200140 if (!global.stats_fe) {
141 if ((global.stats_fe = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) {
142 snprintf(err, errlen, "out of memory");
143 return -1;
144 }
145
146 LIST_INIT(&global.stats_fe->pendconns);
147 LIST_INIT(&global.stats_fe->acl);
148 LIST_INIT(&global.stats_fe->block_cond);
149 LIST_INIT(&global.stats_fe->redirect_rules);
150 LIST_INIT(&global.stats_fe->mon_fail_cond);
151 LIST_INIT(&global.stats_fe->switching_rules);
152 LIST_INIT(&global.stats_fe->tcp_req.inspect_rules);
153
154 /* Timeouts are defined as -1, so we cannot use the zeroed area
155 * as a default value.
156 */
157 proxy_reset_timeouts(global.stats_fe);
158
159 global.stats_fe->last_change = now.tv_sec;
160 global.stats_fe->id = strdup("GLOBAL");
161 global.stats_fe->cap = PR_CAP_FE;
Willy Tarreaueb472682010-05-28 18:46:57 +0200162 global.stats_fe->maxconn = global.stats_sock.maxconn;
Willy Tarreau89a63132009-08-16 17:41:45 +0200163 }
164
Willy Tarreaufbee7132007-10-18 13:53:22 +0200165 global.stats_sock.state = LI_INIT;
Willy Tarreau6fb42e02007-10-28 17:02:33 +0100166 global.stats_sock.options = LI_O_NONE;
Willy Tarreaudecd14d2010-06-01 18:03:19 +0200167 global.stats_sock.accept = session_accept;
168 global.stats_fe->accept = stats_accept;
Willy Tarreau104eb362009-08-16 18:51:29 +0200169 global.stats_sock.handler = process_session;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200170 global.stats_sock.analysers = 0;
Willy Tarreau2c9f5b12009-08-16 19:12:36 +0200171 global.stats_sock.nice = -64; /* we want to boost priority for local stats */
Willy Tarreaueb472682010-05-28 18:46:57 +0200172 global.stats_sock.frontend = global.stats_fe;
Willy Tarreau6162db22009-10-10 17:13:00 +0200173 global.stats_sock.perm.ux.level = ACCESS_LVL_OPER; /* default access level */
Willy Tarreau89a63132009-08-16 17:41:45 +0200174
175 global.stats_fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */
176 global.stats_sock.timeout = &global.stats_fe->timeout.client;
177
178 global.stats_sock.next = global.stats_fe->listen;
179 global.stats_fe->listen = &global.stats_sock;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200180
181 cur_arg = 2;
182 while (*args[cur_arg]) {
183 if (!strcmp(args[cur_arg], "uid")) {
184 global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]);
185 cur_arg += 2;
186 }
187 else if (!strcmp(args[cur_arg], "gid")) {
188 global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]);
189 cur_arg += 2;
190 }
191 else if (!strcmp(args[cur_arg], "mode")) {
192 global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
193 cur_arg += 2;
194 }
195 else if (!strcmp(args[cur_arg], "user")) {
196 struct passwd *user;
197 user = getpwnam(args[cur_arg + 1]);
198 if (!user) {
199 snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')",
200 args[cur_arg + 1]);
201 return -1;
202 }
203 global.stats_sock.perm.ux.uid = user->pw_uid;
204 cur_arg += 2;
205 }
206 else if (!strcmp(args[cur_arg], "group")) {
207 struct group *group;
208 group = getgrnam(args[cur_arg + 1]);
209 if (!group) {
210 snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')",
211 args[cur_arg + 1]);
212 return -1;
213 }
214 global.stats_sock.perm.ux.gid = group->gr_gid;
215 cur_arg += 2;
216 }
Willy Tarreau6162db22009-10-10 17:13:00 +0200217 else if (!strcmp(args[cur_arg], "level")) {
218 if (!strcmp(args[cur_arg+1], "user"))
219 global.stats_sock.perm.ux.level = ACCESS_LVL_USER;
220 else if (!strcmp(args[cur_arg+1], "operator"))
221 global.stats_sock.perm.ux.level = ACCESS_LVL_OPER;
222 else if (!strcmp(args[cur_arg+1], "admin"))
223 global.stats_sock.perm.ux.level = ACCESS_LVL_ADMIN;
224 else {
225 snprintf(err, errlen, "'stats socket level' only supports 'user', 'operator', and 'admin'");
226 return -1;
227 }
228 cur_arg += 2;
229 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200230 else {
Willy Tarreau6162db22009-10-10 17:13:00 +0200231 snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', 'level', and 'mode'");
Willy Tarreaufbee7132007-10-18 13:53:22 +0200232 return -1;
233 }
234 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100235
Willy Tarreaufbee7132007-10-18 13:53:22 +0200236 uxst_add_listener(&global.stats_sock);
237 global.maxsock++;
238 }
239 else if (!strcmp(args[0], "timeout")) {
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100240 unsigned timeout;
241 const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS);
242
243 if (res) {
244 snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res);
245 return -1;
246 }
Willy Tarreaufbee7132007-10-18 13:53:22 +0200247
Willy Tarreaub3f32f52007-12-02 22:15:14 +0100248 if (!timeout) {
Willy Tarreaufbee7132007-10-18 13:53:22 +0200249 snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'");
250 return -1;
251 }
Willy Tarreau89a63132009-08-16 17:41:45 +0200252 global.stats_fe->timeout.client = MS_TO_TICKS(timeout);
Willy Tarreaufbee7132007-10-18 13:53:22 +0200253 }
254 else if (!strcmp(args[0], "maxconn")) {
255 int maxconn = atol(args[1]);
256
257 if (maxconn <= 0) {
258 snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'");
259 return -1;
260 }
261 global.maxsock -= global.stats_sock.maxconn;
262 global.stats_sock.maxconn = maxconn;
263 global.maxsock += global.stats_sock.maxconn;
Willy Tarreaueb472682010-05-28 18:46:57 +0200264 if (global.stats_fe)
265 global.stats_fe->maxconn = global.stats_sock.maxconn;
Willy Tarreaufbee7132007-10-18 13:53:22 +0200266 }
267 else {
268 snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section");
269 return -1;
270 }
271 return 0;
272}
273
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200274int print_csv_header(struct chunk *msg)
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100275{
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200276 return chunk_printf(msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100277 "# pxname,svname,"
278 "qcur,qmax,"
279 "scur,smax,slim,stot,"
280 "bin,bout,"
281 "dreq,dresp,"
282 "ereq,econ,eresp,"
283 "wretr,wredis,"
284 "status,weight,act,bck,"
285 "chkfail,chkdown,lastchg,downtime,qlimit,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +0200286 "pid,iid,sid,throttle,lbtot,tracked,type,"
287 "rate,rate_lim,rate_max,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200288 "check_status,check_code,check_duration,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100289 "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,"
Willy Tarreauae526782010-03-04 20:34:23 +0100290 "req_rate,req_rate_max,req_tot,"
291 "cli_abrt,srv_abrt,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +0100292 "\n");
293}
294
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200295/* Processes the stats interpreter on the statistics socket. This function is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200296 * called from an applet running in a stream interface. The function returns 1
297 * if the request was understood, otherwise zero. It sets si->st0 to a value
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200298 * designating the function which will have to process the request, which can
299 * also be the print function to display the return message set into cli.msg.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200300 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200301int stats_sock_parse_request(struct stream_interface *si, char *line)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200302{
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200303 struct session *s = si->private;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200304 char *args[MAX_STATS_ARGS + 1];
305 int arg;
306
307 while (isspace((unsigned char)*line))
308 line++;
309
310 arg = 0;
311 args[arg] = line;
312
313 while (*line && arg < MAX_STATS_ARGS) {
314 if (isspace((unsigned char)*line)) {
315 *line++ = '\0';
316
317 while (isspace((unsigned char)*line))
318 line++;
319
320 args[++arg] = line;
321 continue;
322 }
323
324 line++;
325 }
326
327 while (++arg <= MAX_STATS_ARGS)
328 args[arg] = line;
329
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200330 s->data_ctx.stats.flags = 0;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200331 if (strcmp(args[0], "show") == 0) {
332 if (strcmp(args[1], "stat") == 0) {
333 if (*args[2] && *args[3] && *args[4]) {
334 s->data_ctx.stats.flags |= STAT_BOUND;
335 s->data_ctx.stats.iid = atoi(args[2]);
336 s->data_ctx.stats.type = atoi(args[3]);
337 s->data_ctx.stats.sid = atoi(args[4]);
338 }
339
340 s->data_ctx.stats.flags |= STAT_SHOW_STAT;
341 s->data_ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200342 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200343 si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200344 }
345 else if (strcmp(args[1], "info") == 0) {
346 s->data_ctx.stats.flags |= STAT_SHOW_INFO;
347 s->data_ctx.stats.flags |= STAT_FMT_CSV;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200348 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200349 si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200350 }
351 else if (strcmp(args[1], "sess") == 0) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200352 s->data_state = DATA_ST_INIT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200353 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200354 s->data_ctx.cli.msg = stats_permission_denied_msg;
355 si->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200356 return 1;
357 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +0100358 if (*args[2])
359 s->data_ctx.sess.target = (void *)strtoul(args[2], NULL, 0);
360 else
361 s->data_ctx.sess.target = NULL;
362 s->data_ctx.sess.section = 0; /* start with session status */
363 s->data_ctx.sess.pos = 0;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200364 si->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200365 }
366 else if (strcmp(args[1], "errors") == 0) {
Willy Tarreau6162db22009-10-10 17:13:00 +0200367 if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200368 s->data_ctx.cli.msg = stats_permission_denied_msg;
369 si->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200370 return 1;
371 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200372 if (*args[2])
373 s->data_ctx.errors.iid = atoi(args[2]);
374 else
375 s->data_ctx.errors.iid = -1;
376 s->data_ctx.errors.px = NULL;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200377 s->data_state = DATA_ST_INIT;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200378 si->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200379 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200380 else { /* neither "stat" nor "info" nor "sess" nor "errors"*/
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200381 return 0;
382 }
383 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200384 else if (strcmp(args[0], "clear") == 0) {
385 if (strcmp(args[1], "counters") == 0) {
386 struct proxy *px;
387 struct server *sv;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200388 struct listener *li;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200389 int clrall = 0;
390
391 if (strcmp(args[2], "all") == 0)
392 clrall = 1;
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200393
Willy Tarreau6162db22009-10-10 17:13:00 +0200394 /* check permissions */
395 if (s->listener->perm.ux.level < ACCESS_LVL_OPER ||
396 (clrall && s->listener->perm.ux.level < ACCESS_LVL_ADMIN)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200397 s->data_ctx.cli.msg = stats_permission_denied_msg;
398 si->st0 = STAT_CLI_PRINT;
Willy Tarreau6162db22009-10-10 17:13:00 +0200399 return 1;
400 }
401
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200402 for (px = proxy; px; px = px->next) {
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200403 if (clrall)
404 memset(&px->counters, 0, sizeof(px->counters));
405 else {
406 px->counters.feconn_max = 0;
407 px->counters.beconn_max = 0;
Willy Tarreaud9b587f2010-02-26 10:05:55 +0100408 px->counters.fe_rps_max = 0;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200409 px->counters.fe_sps_max = 0;
Willy Tarreaub36b4242010-06-04 20:59:39 +0200410 px->counters.fe_cps_max = 0;
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200411 px->counters.be_sps_max = 0;
412 px->counters.nbpend_max = 0;
413 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200414
415 for (sv = px->srv; sv; sv = sv->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200416 if (clrall)
417 memset(&sv->counters, 0, sizeof(sv->counters));
418 else {
419 sv->counters.cur_sess_max = 0;
420 sv->counters.nbpend_max = 0;
421 sv->counters.sps_max = 0;
422 }
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200423
424 for (li = px->listen; li; li = li->next)
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +0200425 if (li->counters) {
426 if (clrall)
427 memset(li->counters, 0, sizeof(*li->counters));
428 else
429 li->counters->conn_max = 0;
430 }
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +0200431 }
432
433 return 1;
434 }
435 else {
436 return 0;
437 }
438 }
Willy Tarreau38338fa2009-10-10 18:37:29 +0200439 else if (strcmp(args[0], "get") == 0) {
440 if (strcmp(args[1], "weight") == 0) {
441 struct proxy *px;
442 struct server *sv;
443
444 /* split "backend/server" and make <line> point to server */
445 for (line = args[2]; *line; line++)
446 if (*line == '/') {
447 *line++ = '\0';
448 break;
449 }
450
451 if (!*line) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200452 s->data_ctx.cli.msg = "Require 'backend/server'.\n";
453 si->st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +0200454 return 1;
455 }
456
457 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200458 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
459 si->st0 = STAT_CLI_PRINT;
Willy Tarreau38338fa2009-10-10 18:37:29 +0200460 return 1;
461 }
462
463 /* return server's effective weight at the moment */
464 snprintf(trash, sizeof(trash), "%d (initial %d)\n", sv->uweight, sv->iweight);
465 buffer_feed(si->ib, trash);
466 return 1;
467 }
468 else { /* not "get weight" */
469 return 0;
470 }
471 }
Willy Tarreau4483d432009-10-10 19:30:08 +0200472 else if (strcmp(args[0], "set") == 0) {
473 if (strcmp(args[1], "weight") == 0) {
474 struct proxy *px;
475 struct server *sv;
476 int w;
477
478 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200479 s->data_ctx.cli.msg = stats_permission_denied_msg;
480 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200481 return 1;
482 }
483
484 /* split "backend/server" and make <line> point to server */
485 for (line = args[2]; *line; line++)
486 if (*line == '/') {
487 *line++ = '\0';
488 break;
489 }
490
491 if (!*line || !*args[3]) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200492 s->data_ctx.cli.msg = "Require 'backend/server' and 'weight' or 'weight%'.\n";
493 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200494 return 1;
495 }
496
497 if (!get_backend_server(args[2], line, &px, &sv)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200498 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
499 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200500 return 1;
501 }
502
503 /* if the weight is terminated with '%', it is set relative to
504 * the initial weight, otherwise it is absolute.
505 */
506 w = atoi(args[3]);
507 if (strchr(args[3], '%') != NULL) {
508 if (w < 0 || w > 100) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200509 s->data_ctx.cli.msg = "Relative weight can only be set between 0 and 100% inclusive.\n";
510 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200511 return 1;
512 }
513 w = sv->iweight * w / 100;
514 }
515 else {
516 if (w < 0 || w > 256) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200517 s->data_ctx.cli.msg = "Absolute weight can only be between 0 and 256 inclusive.\n";
518 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200519 return 1;
520 }
521 }
522
523 if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN)) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200524 s->data_ctx.cli.msg = "Backend is using a static LB algorithm and only accepts weights '0%' and '100%'.\n";
525 si->st0 = STAT_CLI_PRINT;
Willy Tarreau4483d432009-10-10 19:30:08 +0200526 return 1;
527 }
528
529 sv->uweight = w;
530
531 if (px->lbprm.algo & BE_LB_PROP_DYN) {
532 /* we must take care of not pushing the server to full throttle during slow starts */
533 if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN))
534 sv->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - sv->last_change) + sv->slowstart - 1) / sv->slowstart;
535 else
536 sv->eweight = BE_WEIGHT_SCALE;
537 sv->eweight *= sv->uweight;
538 } else {
539 sv->eweight = sv->uweight;
540 }
541
542 /* static LB algorithms are a bit harder to update */
543 if (px->lbprm.update_server_eweight)
544 px->lbprm.update_server_eweight(sv);
545 else if (sv->eweight)
546 px->lbprm.set_server_status_up(sv);
547 else
548 px->lbprm.set_server_status_down(sv);
549
550 return 1;
551 }
Willy Tarreau7aabd112010-01-26 10:59:06 +0100552 else if (strcmp(args[1], "timeout") == 0) {
553 if (strcmp(args[2], "cli") == 0) {
554 unsigned timeout;
555 const char *res;
556
557 if (!*args[3]) {
558 s->data_ctx.cli.msg = "Expects an integer value.\n";
559 si->st0 = STAT_CLI_PRINT;
560 return 1;
561 }
562
563 res = parse_time_err(args[3], &timeout, TIME_UNIT_S);
564 if (res || timeout < 1) {
565 s->data_ctx.cli.msg = "Invalid timeout value.\n";
566 si->st0 = STAT_CLI_PRINT;
567 return 1;
568 }
569
570 s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000);
571 return 1;
572 }
573 else {
574 s->data_ctx.cli.msg = "'set timeout' only supports 'cli'.\n";
575 si->st0 = STAT_CLI_PRINT;
576 return 1;
577 }
578 }
579 else { /* unknown "set" parameter */
Willy Tarreau4483d432009-10-10 19:30:08 +0200580 return 0;
581 }
582 }
Cyril Bontécd19e512010-01-31 22:34:03 +0100583 else if (strcmp(args[0], "enable") == 0) {
584 if (strcmp(args[1], "server") == 0) {
585 struct proxy *px;
586 struct server *sv;
587
588 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
589 s->data_ctx.cli.msg = stats_permission_denied_msg;
590 si->st0 = STAT_CLI_PRINT;
591 return 1;
592 }
593
594 /* split "backend/server" and make <line> point to server */
595 for (line = args[2]; *line; line++)
596 if (*line == '/') {
597 *line++ = '\0';
598 break;
599 }
600
601 if (!*line || !*args[2]) {
602 s->data_ctx.cli.msg = "Require 'backend/server'.\n";
603 si->st0 = STAT_CLI_PRINT;
604 return 1;
605 }
606
607 if (!get_backend_server(args[2], line, &px, &sv)) {
608 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
609 si->st0 = STAT_CLI_PRINT;
610 return 1;
611 }
612
613 if (sv->state & SRV_MAINTAIN) {
614 /* The server is really in maintenance, we can change the server state */
615 if (sv->tracked) {
616 /* If this server tracks the status of another one,
617 * we must restore the good status.
618 */
619 if (sv->tracked->state & SRV_RUNNING) {
620 set_server_up(sv);
621 } else {
622 sv->state &= ~SRV_MAINTAIN;
623 set_server_down(sv);
624 }
625 } else {
626 set_server_up(sv);
627 }
628 }
629
630 return 1;
631 }
632 else { /* unknown "enable" parameter */
633 return 0;
634 }
635 }
636 else if (strcmp(args[0], "disable") == 0) {
637 if (strcmp(args[1], "server") == 0) {
638 struct proxy *px;
639 struct server *sv;
640
641 if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
642 s->data_ctx.cli.msg = stats_permission_denied_msg;
643 si->st0 = STAT_CLI_PRINT;
644 return 1;
645 }
646
647 /* split "backend/server" and make <line> point to server */
648 for (line = args[2]; *line; line++)
649 if (*line == '/') {
650 *line++ = '\0';
651 break;
652 }
653
654 if (!*line || !*args[2]) {
655 s->data_ctx.cli.msg = "Require 'backend/server'.\n";
656 si->st0 = STAT_CLI_PRINT;
657 return 1;
658 }
659
660 if (!get_backend_server(args[2], line, &px, &sv)) {
661 s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n";
662 si->st0 = STAT_CLI_PRINT;
663 return 1;
664 }
665
666 if (! (sv->state & SRV_MAINTAIN)) {
667 /* Not already in maintenance, we can change the server state */
668 sv->state |= SRV_MAINTAIN;
669 set_server_down(sv);
670 }
671
672 return 1;
673 }
674 else { /* unknown "disable" parameter */
675 return 0;
676 }
677 }
678 else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200679 return 0;
680 }
681 return 1;
682}
683
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200684/* This I/O handler runs as an applet embedded in a stream interface. It is
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200685 * used to processes I/O from/to the stats unix socket. The system relies on a
686 * state machine handling requests and various responses. We read a request,
687 * then we process it and send the response, and we possibly display a prompt.
688 * Then we can read again. The state is stored in si->st0 and is one of the
689 * STAT_CLI_* constants. si->st1 is used to indicate whether prompt is enabled
690 * or not.
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200691 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200692void stats_io_handler(struct stream_interface *si)
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200693{
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200694 struct session *s = si->private;
695 struct buffer *req = si->ob;
696 struct buffer *res = si->ib;
697 int reql;
698 int len;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200699
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200700 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
701 goto out;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200702
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200703 while (1) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200704 if (si->st0 == STAT_CLI_INIT) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200705 /* Stats output not initialized yet */
706 memset(&s->data_ctx.stats, 0, sizeof(s->data_ctx.stats));
707 s->data_source = DATA_SRC_STATS;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200708 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200709 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200710 else if (si->st0 == STAT_CLI_END) {
711 /* Let's close for real now. We just close the request
712 * side, the conditions below will complete if needed.
713 */
714 si->shutw(si);
715 break;
716 }
717 else if (si->st0 == STAT_CLI_GETREQ) {
Willy Tarreau4e33d862009-10-11 23:35:10 +0200718 /* ensure we have some output room left in the event we
719 * would want to return some info right after parsing.
720 */
721 if (buffer_almost_full(si->ib))
722 break;
723
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200724 reql = buffer_si_peekline(si->ob, trash, sizeof(trash));
725 if (reql <= 0) { /* closed or EOL not found */
726 if (reql == 0)
727 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200728 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200729 continue;
730 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200731
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200732 /* seek for a possible semi-colon. If we find one, we
733 * replace it with an LF and skip only this part.
734 */
735 for (len = 0; len < reql; len++)
736 if (trash[len] == ';') {
737 trash[len] = '\n';
738 reql = len + 1;
739 break;
740 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200741
Willy Tarreau816fc222009-10-04 07:36:58 +0200742 /* now it is time to check that we have a full line,
743 * remove the trailing \n and possibly \r, then cut the
744 * line.
745 */
746 len = reql - 1;
747 if (trash[len] != '\n') {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200748 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200749 continue;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200750 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200751
Willy Tarreau816fc222009-10-04 07:36:58 +0200752 if (len && trash[len-1] == '\r')
753 len--;
754
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200755 trash[len] = '\0';
756
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200757 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200758 if (len) {
759 if (strcmp(trash, "quit") == 0) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200760 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200761 continue;
762 }
763 else if (strcmp(trash, "prompt") == 0)
764 si->st1 = !si->st1;
765 else if (strcmp(trash, "help") == 0 ||
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200766 !stats_sock_parse_request(si, trash)) {
767 s->data_ctx.cli.msg = stats_sock_usage_msg;
768 si->st0 = STAT_CLI_PRINT;
769 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200770 /* NB: stats_sock_parse_request() may have put
771 * another STAT_CLI_O_* into si->st0.
772 */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200773 }
774 else if (!si->st1) {
775 /* if prompt is disabled, print help on empty lines,
776 * so that the user at least knows how to enable
777 * prompt and find help.
778 */
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200779 s->data_ctx.cli.msg = stats_sock_usage_msg;
780 si->st0 = STAT_CLI_PRINT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200781 }
782
783 /* re-adjust req buffer */
784 buffer_skip(si->ob, reql);
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200785 req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200786 }
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200787 else { /* output functions: first check if the output buffer is closed then abort */
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200788 if (res->flags & (BF_SHUTR_NOW|BF_SHUTR)) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200789 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200790 continue;
791 }
792
793 switch (si->st0) {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200794 case STAT_CLI_PRINT:
795 if (buffer_feed(si->ib, s->data_ctx.cli.msg) < 0)
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200796 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200797 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200798 case STAT_CLI_O_INFO:
Willy Tarreau24955a12009-10-04 11:54:04 +0200799 if (stats_dump_raw_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200800 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200801 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200802 case STAT_CLI_O_SESS:
Willy Tarreau7e72a8f2009-10-03 23:55:14 +0200803 if (stats_dump_sess_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200804 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200805 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200806 case STAT_CLI_O_ERR: /* errors dump */
Willy Tarreau61b34732009-10-03 23:49:35 +0200807 if (stats_dump_errors_to_buffer(s, res))
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200808 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200809 break;
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200810 default: /* abnormal state */
811 si->st0 = STAT_CLI_PROMPT;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200812 break;
813 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200814
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200815 /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
816 if (si->st0 == STAT_CLI_PROMPT) {
Willy Tarreau9bcc91e2009-10-10 18:01:44 +0200817 if (buffer_feed(si->ib, si->st1 ? "\n> " : "\n") < 0)
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200818 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200819 }
820
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200821 /* If the output functions are still there, it means they require more room. */
Willy Tarreau96fd4b52009-10-04 17:18:35 +0200822 if (si->st0 >= STAT_CLI_OUTPUT)
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200823 break;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200824
825 /* Now we close the output if one of the writers did so,
826 * or if we're not in interactive mode and the request
827 * buffer is empty. This still allows pipelined requests
828 * to be sent in non-interactive mode.
829 */
830 if ((res->flags & (BF_SHUTW|BF_SHUTW_NOW)) || (!si->st1 && !req->send_max)) {
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200831 si->st0 = STAT_CLI_END;
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200832 continue;
833 }
834
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200835 /* switch state back to GETREQ to read next requests */
836 si->st0 = STAT_CLI_GETREQ;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200837 }
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200838 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200839
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200840 if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST) && (si->st0 != STAT_CLI_GETREQ)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200841 DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n",
842 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
843 /* Other size has closed, let's abort if we have no more processing to do
844 * and nothing more to consume. This is comparable to a broken pipe, so
845 * we forward the close to the request side so that it flows upstream to
846 * the client.
847 */
848 si->shutw(si);
849 }
850
Willy Tarreauf5a885f2009-10-04 14:22:18 +0200851 if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && (si->st0 < STAT_CLI_OUTPUT)) {
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200852 DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n",
853 __FUNCTION__, __LINE__, req->flags, res->flags, si->state);
854 /* We have no more processing to do, and nothing more to send, and
855 * the client side has closed. So we'll forward this state downstream
856 * on the response buffer.
857 */
858 si->shutr(si);
859 res->flags |= BF_READ_NULL;
860 }
861
862 /* update all other flags and resync with the other side */
863 si->update(si);
864
865 /* we don't want to expire timeouts while we're processing requests */
866 si->ib->rex = TICK_ETERNITY;
867 si->ob->wex = TICK_ETERNITY;
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200868
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200869 out:
870 DPRINTF(stderr, "%s@%d: st=%d, rqf=%x, rpf=%x, rql=%d, rqs=%d, rl=%d, rs=%d\n",
871 __FUNCTION__, __LINE__,
872 si->state, req->flags, res->flags, req->l, req->send_max, res->l, res->send_max);
873
874 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
875 /* check that we have released everything then unregister */
876 stream_int_unregister_handler(si);
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200877 }
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200878}
879
Willy Tarreau24955a12009-10-04 11:54:04 +0200880/* This function is called to send output to the response buffer.
881 * It dumps statistics onto the output buffer <rep> owned by session <s>.
882 * s->data_ctx must have been zeroed first, and the flags properly set.
883 * It returns 0 as long as it does not complete, non-zero upon completion.
884 * Some states are not used but it makes the code more similar to other
885 * functions which handle stats too.
Willy Tarreau3e76e722007-10-17 18:57:38 +0200886 */
Willy Tarreau24955a12009-10-04 11:54:04 +0200887int stats_dump_raw_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau3e76e722007-10-17 18:57:38 +0200888{
Willy Tarreau3e76e722007-10-17 18:57:38 +0200889 struct proxy *px;
890 struct chunk msg;
Willy Tarreaua8efd362008-01-03 10:19:15 +0100891 unsigned int up;
Willy Tarreau3e76e722007-10-17 18:57:38 +0200892
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200893 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3e76e722007-10-17 18:57:38 +0200894
895 switch (s->data_state) {
896 case DATA_ST_INIT:
Willy Tarreau24955a12009-10-04 11:54:04 +0200897 /* the function had not been called yet */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200898 s->data_state = DATA_ST_HEAD;
899 /* fall through */
900
901 case DATA_ST_HEAD:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100902 if (s->data_ctx.stats.flags & STAT_SHOW_STAT) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200903 print_csv_header(&msg);
Willy Tarreau24955a12009-10-04 11:54:04 +0200904 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100905 return 0;
906 }
Willy Tarreau3e76e722007-10-17 18:57:38 +0200907
908 s->data_state = DATA_ST_INFO;
909 /* fall through */
910
911 case DATA_ST_INFO:
Willy Tarreaua8efd362008-01-03 10:19:15 +0100912 up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100913 if (s->data_ctx.stats.flags & STAT_SHOW_INFO) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +0200914 chunk_printf(&msg,
Willy Tarreaua8efd362008-01-03 10:19:15 +0100915 "Name: " PRODUCT_NAME "\n"
916 "Version: " HAPROXY_VERSION "\n"
917 "Release_date: " HAPROXY_DATE "\n"
918 "Nbproc: %d\n"
919 "Process_num: %d\n"
920 "Pid: %d\n"
921 "Uptime: %dd %dh%02dm%02ds\n"
922 "Uptime_sec: %d\n"
923 "Memmax_MB: %d\n"
924 "Ulimit-n: %d\n"
925 "Maxsock: %d\n"
926 "Maxconn: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +0100927 "Maxpipes: %d\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +0100928 "CurrConns: %d\n"
Willy Tarreaua206fa92009-01-25 14:02:00 +0100929 "PipesUsed: %d\n"
930 "PipesFree: %d\n"
Willy Tarreauc7bdf092009-03-21 18:33:52 +0100931 "Tasks: %d\n"
932 "Run_queue: %d\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200933 "node: %s\n"
934 "description: %s\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +0100935 "",
936 global.nbproc,
937 relative_pid,
938 pid,
939 up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
940 up,
941 global.rlimit_memmax,
942 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +0100943 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +0100944 actconn, pipes_used, pipes_free,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200945 nb_tasks_cur, run_queue_cur,
946 global.node, global.desc?global.desc:""
Willy Tarreaua8efd362008-01-03 10:19:15 +0100947 );
Willy Tarreau24955a12009-10-04 11:54:04 +0200948 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100949 return 0;
950 }
951
Willy Tarreau3e76e722007-10-17 18:57:38 +0200952 s->data_ctx.stats.px = proxy;
953 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +0100954
955 s->data_ctx.stats.sv = NULL;
956 s->data_ctx.stats.sv_st = 0;
957
Willy Tarreau3e76e722007-10-17 18:57:38 +0200958 s->data_state = DATA_ST_LIST;
959 /* fall through */
960
961 case DATA_ST_LIST:
962 /* dump proxies */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100963 if (s->data_ctx.stats.flags & STAT_SHOW_STAT) {
Willy Tarreaua8efd362008-01-03 10:19:15 +0100964 while (s->data_ctx.stats.px) {
965 px = s->data_ctx.stats.px;
966 /* skip the disabled proxies and non-networked ones */
967 if (px->state != PR_STSTOPPED &&
Willy Tarreau24955a12009-10-04 11:54:04 +0200968 (px->cap & (PR_CAP_FE | PR_CAP_BE))) {
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100969 if (stats_dump_proxy(s, px, NULL) == 0)
Willy Tarreaua8efd362008-01-03 10:19:15 +0100970 return 0;
Willy Tarreau24955a12009-10-04 11:54:04 +0200971 }
Willy Tarreau3e76e722007-10-17 18:57:38 +0200972
Willy Tarreaua8efd362008-01-03 10:19:15 +0100973 s->data_ctx.stats.px = px->next;
974 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
975 }
976 /* here, we just have reached the last proxy */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200977 }
Willy Tarreau3e76e722007-10-17 18:57:38 +0200978
979 s->data_state = DATA_ST_END;
980 /* fall through */
981
982 case DATA_ST_END:
983 s->data_state = DATA_ST_FIN;
Willy Tarreau0a464892008-12-07 18:30:00 +0100984 /* fall through */
Willy Tarreau3e76e722007-10-17 18:57:38 +0200985
986 case DATA_ST_FIN:
987 return 1;
988
989 default:
990 /* unknown state ! */
Willy Tarreau24955a12009-10-04 11:54:04 +0200991 s->data_state = DATA_ST_FIN;
992 return 1;
Willy Tarreau3e76e722007-10-17 18:57:38 +0200993 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100994}
995
996
Willy Tarreaub0c9bc42009-10-04 15:56:38 +0200997/* This I/O handler runs as an applet embedded in a stream interface. It is
998 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
999 * si->st0 becomes non-zero once the transfer is finished. The handler
1000 * automatically unregisters itself once transfer is complete.
1001 */
1002void http_stats_io_handler(struct stream_interface *si)
1003{
1004 struct session *s = si->private;
1005 struct buffer *req = si->ob;
1006 struct buffer *res = si->ib;
1007
1008 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
1009 goto out;
1010
1011 /* check that the output is not closed */
1012 if (res->flags & (BF_SHUTW|BF_SHUTW_NOW))
1013 si->st0 = 1;
1014
1015 if (!si->st0) {
1016 if (stats_dump_http(s, res, s->be->uri_auth)) {
1017 si->st0 = 1;
1018 si->shutw(si);
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001019 }
1020 }
1021
1022 if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST))
1023 si->shutw(si);
1024
1025 if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && si->st0) {
1026 si->shutr(si);
1027 res->flags |= BF_READ_NULL;
1028 }
1029
1030 /* update all other flags and resync with the other side */
1031 si->update(si);
1032
1033 /* we don't want to expire timeouts while we're processing requests */
1034 si->ib->rex = TICK_ETERNITY;
1035 si->ob->wex = TICK_ETERNITY;
1036
1037 out:
1038 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) {
1039 /* check that we have released everything then unregister */
1040 stream_int_unregister_handler(si);
1041 }
1042}
1043
1044
Willy Tarreau3e76e722007-10-17 18:57:38 +02001045/*
1046 * Produces statistics data for the session <s>. Expects to be called with
Willy Tarreau1ae3a052008-08-16 10:56:30 +02001047 * client socket shut down on input. It stops by itself by unsetting the
Willy Tarreau72b179a2008-08-28 16:01:32 +02001048 * BF_HIJACK flag from the buffer, which it uses to keep on being called
Willy Tarreau1ae3a052008-08-16 10:56:30 +02001049 * when there is free space in the buffer, of simply by letting an empty buffer
1050 * upon return.s->data_ctx must have been zeroed before the first call, and the
1051 * flags set. It returns 0 if it had to stop writing data and an I/O is needed,
1052 * 1 if the dump is finished and the session must be closed, or -1 in case of
1053 * any error.
Willy Tarreau91861262007-10-17 17:06:05 +02001054 */
Willy Tarreau0a464892008-12-07 18:30:00 +01001055int stats_dump_http(struct session *s, struct buffer *rep, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02001056{
Willy Tarreau91861262007-10-17 17:06:05 +02001057 struct proxy *px;
1058 struct chunk msg;
1059 unsigned int up;
1060
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001061 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +02001062
1063 switch (s->data_state) {
1064 case DATA_ST_INIT:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001065 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001066 "HTTP/1.0 200 OK\r\n"
1067 "Cache-Control: no-cache\r\n"
1068 "Connection: close\r\n"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001069 "Content-Type: %s\r\n",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001070 (s->data_ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html");
Willy Tarreau91861262007-10-17 17:06:05 +02001071
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001072 if (uri->refresh > 0 && !(s->data_ctx.stats.flags & STAT_NO_REFRESH))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001073 chunk_printf(&msg, "Refresh: %d\r\n",
Willy Tarreau91861262007-10-17 17:06:05 +02001074 uri->refresh);
1075
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001076 chunk_printf(&msg, "\r\n");
Willy Tarreau91861262007-10-17 17:06:05 +02001077
1078 s->txn.status = 200;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001079 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau56a560a2009-09-22 19:27:35 +02001080 return 0;
1081
Willy Tarreau91861262007-10-17 17:06:05 +02001082 if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is
1083 s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy
1084 if (!(s->flags & SN_FINST_MASK))
1085 s->flags |= SN_FINST_R;
1086
1087 if (s->txn.meth == HTTP_METH_HEAD) {
1088 /* that's all we return in case of HEAD request */
1089 s->data_state = DATA_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02001090 return 1;
1091 }
1092
1093 s->data_state = DATA_ST_HEAD; /* let's start producing data */
1094 /* fall through */
1095
1096 case DATA_ST_HEAD:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001097 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001098 /* WARNING! This must fit in the first buffer !!! */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001099 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001100 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
1101 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001102 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001103 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
1104 "<style type=\"text/css\"><!--\n"
1105 "body {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001106 " font-family: arial, helvetica, sans-serif;"
Willy Tarreau91861262007-10-17 17:06:05 +02001107 " font-size: 12px;"
1108 " font-weight: normal;"
1109 " color: black;"
1110 " background: white;"
1111 "}\n"
1112 "th,td {"
Willy Tarreaua94f2d22009-05-10 20:08:10 +02001113 " font-size: 10px;"
Willy Tarreau91861262007-10-17 17:06:05 +02001114 "}\n"
1115 "h1 {"
Willy Tarreauda6721b2009-07-15 10:07:05 +02001116 " font-size: x-large;"
Willy Tarreau91861262007-10-17 17:06:05 +02001117 " margin-bottom: 0.5em;"
1118 "}\n"
1119 "h2 {"
1120 " font-family: helvetica, arial;"
1121 " font-size: x-large;"
1122 " font-weight: bold;"
1123 " font-style: italic;"
1124 " color: #6020a0;"
1125 " margin-top: 0em;"
1126 " margin-bottom: 0em;"
1127 "}\n"
1128 "h3 {"
1129 " font-family: helvetica, arial;"
1130 " font-size: 16px;"
1131 " font-weight: bold;"
1132 " color: #b00040;"
1133 " background: #e8e8d0;"
1134 " margin-top: 0em;"
1135 " margin-bottom: 0em;"
1136 "}\n"
1137 "li {"
1138 " margin-top: 0.25em;"
1139 " margin-right: 2em;"
1140 "}\n"
1141 ".hr {margin-top: 0.25em;"
1142 " border-color: black;"
1143 " border-bottom-style: solid;"
1144 "}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001145 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001146 ".total {background: #20D0D0;color: #ffff80;}\n"
1147 ".frontend {background: #e8e8d0;}\n"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001148 ".socket {background: #d0d0d0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001149 ".backend {background: #e8e8d0;}\n"
1150 ".active0 {background: #ff9090;}\n"
1151 ".active1 {background: #ffd020;}\n"
1152 ".active2 {background: #ffffa0;}\n"
1153 ".active3 {background: #c0ffc0;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001154 ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */
1155 ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */
1156 ".active6 {background: #e0e0e0;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001157 ".backup0 {background: #ff9090;}\n"
1158 ".backup1 {background: #ff80ff;}\n"
1159 ".backup2 {background: #c060ff;}\n"
1160 ".backup3 {background: #b0d0ff;}\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001161 ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */
1162 ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */
1163 ".backup6 {background: #e0e0e0;}\n"
Cyril Bontécd19e512010-01-31 22:34:03 +01001164 ".maintain {background: #c07820;}\n"
Willy Tarreauda6721b2009-07-15 10:07:05 +02001165 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001166 "\n"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001167 "a.px:link {color: #ffff40; text-decoration: none;}"
1168 "a.px:visited {color: #ffff40; text-decoration: none;}"
1169 "a.px:hover {color: #ffffff; text-decoration: none;}"
1170 "a.lfsb:link {color: #000000; text-decoration: none;}"
1171 "a.lfsb:visited {color: #000000; text-decoration: none;}"
1172 "a.lfsb:hover {color: #505050; text-decoration: none;}"
1173 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001174 "table.tbl { border-collapse: collapse; border-style: none;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001175 "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"
1176 "table.tbl td.ac { text-align: center;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001177 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001178 "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 +02001179 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001180 "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 +02001181 "\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001182 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
1183 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
1184 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
Willy Tarreaue0454092010-02-26 12:29:07 +01001185 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001186 "-->\n"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001187 "</style></head>\n",
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001188 (uri->flags&ST_SHNODE) ? " on " : "",
1189 (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02001190 );
Willy Tarreau55bb8452007-10-17 18:44:57 +02001191 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001192 print_csv_header(&msg);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001193 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001194 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001195 return 0;
1196
1197 s->data_state = DATA_ST_INFO;
1198 /* fall through */
1199
1200 case DATA_ST_INFO:
1201 up = (now.tv_sec - start_date.tv_sec);
1202
1203 /* WARNING! this has to fit the first packet too.
1204 * We are around 3.5 kB, add adding entries will
1205 * become tricky if we want to support 4kB buffers !
1206 */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001207 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001208 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001209 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
1210 PRODUCT_NAME "%s</a></h1>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001211 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001212 "<hr width=\"100%%\" class=\"hr\">\n"
1213 "<h3>&gt; General process information</h3>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001214 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Willy Tarreaua8efd362008-01-03 10:19:15 +01001215 "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001216 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001217 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
1218 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
1219 "current conns = %d; current pipes = %d/%d<br>\n"
1220 "Running tasks: %d/%d<br>\n"
Willy Tarreau91861262007-10-17 17:06:05 +02001221 "</td><td align=\"center\" nowrap>\n"
1222 "<table class=\"lgd\"><tr>\n"
1223 "<td class=\"active3\">&nbsp;</td><td class=\"noborder\">active UP </td>"
1224 "<td class=\"backup3\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
1225 "</tr><tr>\n"
1226 "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>"
1227 "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>"
1228 "</tr><tr>\n"
1229 "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>"
1230 "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>"
1231 "</tr><tr>\n"
1232 "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001233 "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>"
Cyril Bontécd19e512010-01-31 22:34:03 +01001234 "</tr><tr>\n"
1235 "<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 +02001236 "</tr></table>\n"
Willy Tarreau2ea81932007-11-30 12:04:38 +01001237 "Note: UP with load-balancing disabled is reported as \"NOLB\"."
Willy Tarreau91861262007-10-17 17:06:05 +02001238 "</td>"
1239 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
1240 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
1241 "",
1242 (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001243 pid, (uri->flags&ST_SHNODE) ? " on " : "", (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
1244 (uri->flags&ST_SHDESC)? ": " : "", (uri->flags&ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
1245 pid, relative_pid, global.nbproc,
Willy Tarreau91861262007-10-17 17:06:05 +02001246 up / 86400, (up % 86400) / 3600,
1247 (up % 3600) / 60, (up % 60),
1248 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
1249 global.rlimit_memmax ? " MB" : "",
1250 global.rlimit_nofile,
Willy Tarreaua206fa92009-01-25 14:02:00 +01001251 global.maxsock, global.maxconn, global.maxpipes,
Willy Tarreauc7bdf092009-03-21 18:33:52 +01001252 actconn, pipes_used, pipes_used+pipes_free,
1253 run_queue_cur, nb_tasks_cur
Willy Tarreau91861262007-10-17 17:06:05 +02001254 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001255
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001256 if (s->data_ctx.stats.flags & STAT_HIDE_DOWN)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001257 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001258 "<li><a href=\"%s%s%s\">Show all servers</a><br>\n",
1259 uri->uri_prefix,
1260 "",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001261 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001262 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001263 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001264 "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n",
1265 uri->uri_prefix,
1266 ";up",
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001267 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02001268
Willy Tarreau55bb8452007-10-17 18:44:57 +02001269 if (uri->refresh > 0) {
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001270 if (s->data_ctx.stats.flags & STAT_NO_REFRESH)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001271 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001272 "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n",
1273 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001274 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02001275 "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001276 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001277 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001278 "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n",
1279 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001280 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
Willy Tarreau91861262007-10-17 17:06:05 +02001281 ";norefresh");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001282 }
Willy Tarreau91861262007-10-17 17:06:05 +02001283
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001284 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001285 "<li><a href=\"%s%s%s\">Refresh now</a><br>\n",
1286 uri->uri_prefix,
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001287 (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
1288 (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "");
Willy Tarreau91861262007-10-17 17:06:05 +02001289
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001290 chunk_printf(&msg,
Willy Tarreau5031e6a2007-10-18 11:05:48 +02001291 "<li><a href=\"%s;csv%s\">CSV export</a><br>\n",
1292 uri->uri_prefix,
1293 (uri->refresh > 0) ? ";norefresh" : "");
1294
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001295 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001296 "</ul></td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001297 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
1298 "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n"
1299 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
1300 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
1301 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
1302 "</ul>"
1303 "</td>"
1304 "</tr></table>\n"
1305 ""
1306 );
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001307
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001308 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001309 return 0;
1310 }
Willy Tarreau91861262007-10-17 17:06:05 +02001311
Willy Tarreau91861262007-10-17 17:06:05 +02001312 s->data_ctx.stats.px = proxy;
1313 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
1314 s->data_state = DATA_ST_LIST;
1315 /* fall through */
1316
1317 case DATA_ST_LIST:
1318 /* dump proxies */
1319 while (s->data_ctx.stats.px) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02001320 if (buffer_almost_full(rep))
1321 return 0;
Willy Tarreau91861262007-10-17 17:06:05 +02001322 px = s->data_ctx.stats.px;
1323 /* skip the disabled proxies and non-networked ones */
1324 if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001325 if (stats_dump_proxy(s, px, uri) == 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001326 return 0;
1327
1328 s->data_ctx.stats.px = px->next;
1329 s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
1330 }
1331 /* here, we just have reached the last proxy */
1332
1333 s->data_state = DATA_ST_END;
1334 /* fall through */
1335
1336 case DATA_ST_END:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001337 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001338 chunk_printf(&msg, "</body></html>\n");
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001339 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001340 return 0;
1341 }
Willy Tarreau91861262007-10-17 17:06:05 +02001342
1343 s->data_state = DATA_ST_FIN;
1344 /* fall through */
1345
1346 case DATA_ST_FIN:
Willy Tarreau91861262007-10-17 17:06:05 +02001347 return 1;
1348
1349 default:
1350 /* unknown state ! */
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001351 s->data_state = DATA_ST_FIN;
Willy Tarreau91861262007-10-17 17:06:05 +02001352 return -1;
1353 }
1354}
1355
1356
1357/*
1358 * Dumps statistics for a proxy.
1359 * Returns 0 if it had to stop dumping data because of lack of buffer space,
1360 * ot non-zero if everything completed.
1361 */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001362int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
Willy Tarreau91861262007-10-17 17:06:05 +02001363{
1364 struct buffer *rep = s->rep;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001365 struct server *sv, *svs; /* server and server-state, server-state=server or server->tracked */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001366 struct listener *l;
Willy Tarreau91861262007-10-17 17:06:05 +02001367 struct chunk msg;
1368
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001369 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau91861262007-10-17 17:06:05 +02001370
1371 switch (s->data_ctx.stats.px_st) {
1372 case DATA_ST_PX_INIT:
1373 /* we are on a new proxy */
1374
1375 if (uri && uri->scope) {
1376 /* we have a limited scope, we have to check the proxy name */
1377 struct stat_scope *scope;
1378 int len;
1379
1380 len = strlen(px->id);
1381 scope = uri->scope;
1382
1383 while (scope) {
1384 /* match exact proxy name */
1385 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
1386 break;
1387
1388 /* match '.' which means 'self' proxy */
Willy Tarreau1388a3a2007-10-18 16:38:37 +02001389 if (!strcmp(scope->px_id, ".") && px == s->be)
Willy Tarreau91861262007-10-17 17:06:05 +02001390 break;
1391 scope = scope->next;
1392 }
1393
1394 /* proxy name not found : don't dump anything */
1395 if (scope == NULL)
1396 return 1;
1397 }
1398
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001399 if ((s->data_ctx.stats.flags & STAT_BOUND) && (s->data_ctx.stats.iid != -1) &&
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001400 (px->uuid != s->data_ctx.stats.iid))
1401 return 1;
1402
Willy Tarreau91861262007-10-17 17:06:05 +02001403 s->data_ctx.stats.px_st = DATA_ST_PX_TH;
1404 /* fall through */
1405
1406 case DATA_ST_PX_TH:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001407 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau55bb8452007-10-17 18:44:57 +02001408 /* print a new table */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001409 chunk_printf(&msg,
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001410 "<table class=\"tbl\" width=\"100%%\">\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001411 "<tr class=\"titre\">"
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001412 "<th class=\"pxname\" width=\"10%%\"");
1413
1414 if (uri->flags&ST_SHLGNDS) {
1415 /* cap, mode, id */
1416 chunk_printf(&msg, " title=\"cap: %s, mode: %s, id: %d",
1417 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
1418 px->uuid);
1419
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001420 chunk_printf(&msg, "\"");
1421 }
1422
1423 chunk_printf(&msg,
Willy Tarreaue0454092010-02-26 12:29:07 +01001424 ">%s<a name=\"%s\"></a>"
1425 "<a class=px href=\"#%s\">%s</a>%s</th>"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001426 "<th class=\"%s\" width=\"90%%\">%s</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001427 "</tr>\n"
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001428 "</table>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001429 "<table class=\"tbl\" width=\"100%%\">\n"
1430 "<tr class=\"titre\">"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001431 "<th rowspan=2></th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001432 "<th colspan=3>Queue</th>"
1433 "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001434 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001435 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001436 "<th colspan=9>Server</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001437 "</tr>\n"
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001438 "<tr class=\"titre\">"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001439 "<th>Cur</th><th>Max</th><th>Limit</th>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001440 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001441 "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001442 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001443 "<th>Resp</th><th>Retr</th><th>Redis</th>"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001444 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001445 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
1446 "<th>Thrtle</th>\n"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001447 "</tr>",
Willy Tarreaue0454092010-02-26 12:29:07 +01001448 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001449 px->id, px->id, px->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01001450 (uri->flags & ST_SHLGNDS)?"</u>":"",
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02001451 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001452
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001453 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02001454 return 0;
1455 }
Willy Tarreau91861262007-10-17 17:06:05 +02001456
1457 s->data_ctx.stats.px_st = DATA_ST_PX_FE;
1458 /* fall through */
1459
1460 case DATA_ST_PX_FE:
1461 /* print the frontend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001462 if ((px->cap & PR_CAP_FE) &&
1463 (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_FE)))) {
1464 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001465 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001466 /* name, queue */
Krzysztof Piotr Oledzki516ed492009-10-22 22:48:09 +02001467 "<tr class=\"frontend\"><td class=ac>"
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02001468 "<a name=\"%s/Frontend\"></a>"
1469 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td><td colspan=3></td>"
Willy Tarreaub44939a2010-02-26 11:35:39 +01001470 "",
1471 px->id, px->id);
1472
1473 if (px->mode == PR_MODE_HTTP) {
1474 chunk_printf(&msg,
1475 /* sessions rate : current, max, limit */
Willy Tarreaue0454092010-02-26 12:29:07 +01001476 "<td title=\"Cur: %u req/s\"><u>%s</u></td><td title=\"Max: %u req/s\"><u>%s</u></td><td>%s</td>"
Willy Tarreaub44939a2010-02-26 11:35:39 +01001477 "",
1478 read_freq_ctr(&px->fe_req_per_sec),
1479 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
1480 px->counters.fe_rps_max,
1481 U2H2(px->counters.fe_sps_max),
1482 LIM2A2(px->fe_sps_lim, "-"));
1483 } else {
1484 chunk_printf(&msg,
1485 /* sessions rate : current, max, limit */
1486 "<td>%s</td><td>%s</td><td>%s</td>"
1487 "",
1488 U2H0(read_freq_ctr(&px->fe_sess_per_sec)),
1489 U2H1(px->counters.fe_sps_max), LIM2A2(px->fe_sps_lim, "-"));
1490 }
1491
1492 chunk_printf(&msg,
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001493 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001494 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001495 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001496 "",
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001497 U2H3(px->feconn), U2H4(px->counters.feconn_max), U2H5(px->maxconn));
1498
1499 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
1500 if (px->mode == PR_MODE_HTTP) {
1501 int i;
1502
Willy Tarreaub44939a2010-02-26 11:35:39 +01001503 chunk_printf(&msg, " title=\"%lld requests:", px->counters.cum_fe_req);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001504
1505 for (i = 1; i < 6; i++)
Willy Tarreau24657792010-02-26 10:30:28 +01001506 chunk_printf(&msg, " %dxx=%lld,", i, px->counters.fe.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001507
Willy Tarreau24657792010-02-26 10:30:28 +01001508 chunk_printf(&msg, " other=%lld\"", px->counters.fe.http.rsp[0]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001509 }
1510
1511 chunk_printf(&msg,
1512 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01001513 ">%s%s%s</td><td></td>"
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001514 /* bytes : in, out */
1515 "<td>%s</td><td>%s</td>"
1516 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01001517 (px->mode == PR_MODE_HTTP)?"<u>":"",
Willy Tarreaub36b4242010-06-04 20:59:39 +02001518 U2H6(px->counters.cum_fesess),
Willy Tarreaue0454092010-02-26 12:29:07 +01001519 (px->mode == PR_MODE_HTTP)?"</u>":"",
1520 U2H7(px->counters.bytes_in), U2H8(px->counters.bytes_out));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001521
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001522 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001523 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001524 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001525 /* errors : request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001526 "<td>%s</td><td></td><td></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001527 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001528 "<td></td><td></td>"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001529 /* server status : reflect frontend status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001530 "<td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001531 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001532 "<td class=ac colspan=8></td></tr>"
Willy Tarreau91861262007-10-17 17:06:05 +02001533 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001534 U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp),
1535 U2H2(px->counters.failed_req),
Willy Tarreau91861262007-10-17 17:06:05 +02001536 px->state == PR_STRUN ? "OPEN" :
1537 px->state == PR_STIDLE ? "FULL" : "STOP");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001538 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001539 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001540 /* pxid, name, queue cur, queue max, */
1541 "%s,FRONTEND,,,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001542 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001543 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001544 /* bytes : in, out */
1545 "%lld,%lld,"
1546 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001547 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001548 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02001549 "%lld,,,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001550 /* warnings: retries, redispatches */
1551 ",,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02001552 /* server status : reflect frontend status */
1553 "%s,"
1554 /* rest of server: nothing */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001555 ",,,,,,,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001556 /* pid, iid, sid, throttle, lbtot, tracked, type */
1557 "%d,%d,0,,,,%d,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001558 /* rate, rate_lim, rate_max */
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001559 "%u,%u,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001560 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001561 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02001562 px->id,
Willy Tarreaub36b4242010-06-04 20:59:39 +02001563 px->feconn, px->counters.feconn_max, px->maxconn, px->counters.cum_fesess,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001564 px->counters.bytes_in, px->counters.bytes_out,
1565 px->counters.denied_req, px->counters.denied_resp,
1566 px->counters.failed_req,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001567 px->state == PR_STRUN ? "OPEN" :
Willy Tarreaudcd47712007-11-04 23:35:08 +01001568 px->state == PR_STIDLE ? "FULL" : "STOP",
Willy Tarreau7f062c42009-03-05 18:43:00 +01001569 relative_pid, px->uuid, STATS_TYPE_FE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02001570 read_freq_ctr(&px->fe_sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001571 px->fe_sps_lim, px->counters.fe_sps_max);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001572
1573 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1574 if (px->mode == PR_MODE_HTTP) {
1575 int i;
1576
1577 for (i=1; i<6; i++)
Willy Tarreau24657792010-02-26 10:30:28 +01001578 chunk_printf(&msg, "%lld,", px->counters.fe.http.rsp[i]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001579
Willy Tarreau24657792010-02-26 10:30:28 +01001580 chunk_printf(&msg, "%lld,", px->counters.fe.http.rsp[0]);
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001581 } else {
1582 chunk_printf(&msg, ",,,,,,");
1583 }
1584
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001585 /* failed health analyses */
1586 chunk_printf(&msg, ",");
1587
Willy Tarreaud9b587f2010-02-26 10:05:55 +01001588 /* requests : req_rate, req_rate_max, req_tot, */
1589 chunk_printf(&msg, "%u,%u,%lld,",
1590 read_freq_ctr(&px->fe_req_per_sec),
1591 px->counters.fe_rps_max, px->counters.cum_fe_req);
1592
Willy Tarreauae526782010-03-04 20:34:23 +01001593 /* errors: cli_aborts, srv_aborts */
1594 chunk_printf(&msg, ",,");
1595
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02001596 /* finish with EOL */
1597 chunk_printf(&msg, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02001598 }
Willy Tarreau91861262007-10-17 17:06:05 +02001599
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02001600 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02001601 return 0;
1602 }
1603
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001604 s->data_ctx.stats.l = px->listen; /* may be NULL */
1605 s->data_ctx.stats.px_st = DATA_ST_PX_LI;
1606 /* fall through */
1607
1608 case DATA_ST_PX_LI:
1609 /* stats.l has been initialized above */
1610 for (; s->data_ctx.stats.l != NULL; s->data_ctx.stats.l = l->next) {
Willy Tarreau4e33d862009-10-11 23:35:10 +02001611 if (buffer_almost_full(rep))
1612 return 0;
1613
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001614 l = s->data_ctx.stats.l;
1615 if (!l->counters)
1616 continue;
1617
1618 if (s->data_ctx.stats.flags & STAT_BOUND) {
1619 if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SO)))
1620 break;
1621
1622 if (s->data_ctx.stats.sid != -1 && l->luid != s->data_ctx.stats.sid)
1623 continue;
1624 }
1625
1626 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001627 chunk_printf(&msg, "<tr class=socket><td class=ac");
1628
1629 if (uri->flags&ST_SHLGNDS) {
1630 char str[INET6_ADDRSTRLEN], *fmt = NULL;
1631 int port;
1632
1633 chunk_printf(&msg, " title=\"IP: ");
1634
1635 port = (l->addr.ss_family == AF_INET6)
1636 ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port)
1637 : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port);
1638
1639 if (l->addr.ss_family == AF_INET) {
1640 if (inet_ntop(AF_INET,
1641 (const void *)&((struct sockaddr_in *)&l->addr)->sin_addr,
1642 str, sizeof(str)))
1643 fmt = "%s:%d";
1644 } else {
1645 if (inet_ntop(AF_INET6,
1646 (const void *)&((struct sockaddr_in6 *)(&l->addr))->sin6_addr,
1647 str, sizeof(str)))
1648 fmt = "[%s]:%d";
1649 }
1650
1651 if (fmt)
1652 chunk_printf(&msg, fmt, str, port);
1653 else
1654 chunk_printf(&msg, "(%s)", strerror(errno));
1655
1656 /* id */
1657 chunk_printf(&msg, ", id: %d", l->luid);
1658
1659 chunk_printf(&msg, "\"");
1660 }
1661
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001662 chunk_printf(&msg,
1663 /* name, queue */
Willy Tarreaue0454092010-02-26 12:29:07 +01001664 ">%s<a name=\"%s/+%s\"></a>"
1665 "<a class=lfsb href=\"#%s/+%s\">%s</a></td><td colspan=3>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001666 /* sessions rate: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001667 "<td colspan=3>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001668 /* sessions: current, max, limit, total, lbtot */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001669 "<td>%s</td><td>%s</td><td>%s</td>"
1670 "<td>%s</td><td>&nbsp;</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001671 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001672 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001673 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01001674 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki2ec025d2010-01-04 11:33:32 +01001675 px->id, l->name, px->id, l->name, l->name,
Willy Tarreaue0454092010-02-26 12:29:07 +01001676 (uri->flags & ST_SHLGNDS)?"</u>":"",
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001677 U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn),
1678 U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out));
1679
1680 chunk_printf(&msg,
1681 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001682 "<td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001683 /* errors: request, connect, response */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001684 "<td>%s</td><td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001685 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001686 "<td></td><td></td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001687 /* server status: reflect listener status */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001688 "<td class=ac>%s</td>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001689 /* rest of server: nothing */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001690 "<td class=ac colspan=8></td></tr>"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001691 "",
1692 U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp),
1693 U2H2(l->counters->failed_req),
1694 (l->nbconn < l->maxconn) ? "OPEN" : "FULL");
1695 } else {
1696 chunk_printf(&msg,
1697 /* pxid, name, queue cur, queue max, */
1698 "%s,%s,,,"
1699 /* sessions: current, max, limit, total */
1700 "%d,%d,%d,%lld,"
1701 /* bytes: in, out */
1702 "%lld,%lld,"
1703 /* denied: req, resp */
1704 "%lld,%lld,"
1705 /* errors: request, connect, response */
1706 "%lld,,,"
1707 /* warnings: retries, redispatches */
1708 ",,"
1709 /* server status: reflect listener status */
1710 "%s,"
1711 /* rest of server: nothing */
1712 ",,,,,,,,"
1713 /* pid, iid, sid, throttle, lbtot, tracked, type */
1714 "%d,%d,%d,,,,%d,"
1715 /* rate, rate_lim, rate_max */
1716 ",,,"
1717 /* check_status, check_code, check_duration */
1718 ",,,"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001719 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1720 ",,,,,,"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001721 /* failed health analyses */
1722 ","
Willy Tarreaud9b587f2010-02-26 10:05:55 +01001723 /* requests : req_rate, req_rate_max, req_tot, */
1724 ",,,"
Willy Tarreauae526782010-03-04 20:34:23 +01001725 /* errors: cli_aborts, srv_aborts */
1726 ",,"
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001727 "\n",
1728 px->id, l->name,
1729 l->nbconn, l->counters->conn_max,
1730 l->maxconn, l->counters->cum_conn,
1731 l->counters->bytes_in, l->counters->bytes_out,
1732 l->counters->denied_req, l->counters->denied_resp,
1733 l->counters->failed_req,
1734 (l->nbconn < l->maxconn) ? "OPEN" : "FULL",
1735 relative_pid, px->uuid, l->luid, STATS_TYPE_SO);
1736 }
1737
1738 if (buffer_feed_chunk(rep, &msg) >= 0)
1739 return 0;
1740 }
1741
Willy Tarreau91861262007-10-17 17:06:05 +02001742 s->data_ctx.stats.sv = px->srv; /* may be NULL */
1743 s->data_ctx.stats.px_st = DATA_ST_PX_SV;
1744 /* fall through */
1745
1746 case DATA_ST_PX_SV:
1747 /* stats.sv has been initialized above */
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001748 for (; s->data_ctx.stats.sv != NULL; s->data_ctx.stats.sv = sv->next) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01001749 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 +02001750
Willy Tarreau4e33d862009-10-11 23:35:10 +02001751 if (buffer_almost_full(rep))
1752 return 0;
1753
Willy Tarreau91861262007-10-17 17:06:05 +02001754 sv = s->data_ctx.stats.sv;
1755
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001756 if (s->data_ctx.stats.flags & STAT_BOUND) {
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01001757 if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SV)))
1758 break;
1759
1760 if (s->data_ctx.stats.sid != -1 && sv->puid != s->data_ctx.stats.sid)
1761 continue;
1762 }
1763
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001764 if (sv->tracked)
1765 svs = sv->tracked;
1766 else
1767 svs = sv;
1768
Willy Tarreau91861262007-10-17 17:06:05 +02001769 /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001770 if (!(svs->state & SRV_CHECKED))
Willy Tarreau2ea81932007-11-30 12:04:38 +01001771 sv_state = 6;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001772 else if (svs->state & SRV_RUNNING) {
1773 if (svs->health == svs->rise + svs->fall - 1)
Willy Tarreau91861262007-10-17 17:06:05 +02001774 sv_state = 3; /* UP */
1775 else
1776 sv_state = 2; /* going down */
Willy Tarreau2ea81932007-11-30 12:04:38 +01001777
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001778 if (svs->state & SRV_GOINGDOWN)
Willy Tarreau2ea81932007-11-30 12:04:38 +01001779 sv_state += 2;
1780 }
Willy Tarreau91861262007-10-17 17:06:05 +02001781 else
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01001782 if (svs->health)
Willy Tarreau91861262007-10-17 17:06:05 +02001783 sv_state = 1; /* going up */
1784 else
1785 sv_state = 0; /* DOWN */
1786
Cyril Bonté0dae5852010-02-03 00:26:28 +01001787 if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (s->data_ctx.stats.flags & STAT_HIDE_DOWN)) {
Willy Tarreau91861262007-10-17 17:06:05 +02001788 /* do not report servers which are DOWN */
1789 s->data_ctx.stats.sv = sv->next;
1790 continue;
1791 }
1792
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01001793 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Willy Tarreau2ea81932007-11-30 12:04:38 +01001794 static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d &uarr;",
1795 "UP %d/%d &darr;", "UP",
1796 "NOLB %d/%d &darr;", "NOLB",
1797 "<i>no check</i>" };
Cyril Bonté0dae5852010-02-03 00:26:28 +01001798 if ((sv->state & SRV_MAINTAIN) || (svs->state & SRV_MAINTAIN)) {
Cyril Bontécd19e512010-01-31 22:34:03 +01001799 chunk_printf(&msg,
1800 /* name */
1801 "<tr class=\"maintain\"><td class=ac"
1802 );
1803 }
1804 else {
1805 chunk_printf(&msg,
1806 /* name */
1807 "<tr class=\"%s%d\"><td class=ac",
1808 (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state);
1809 }
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001810
1811 if (uri->flags&ST_SHLGNDS) {
1812 char str[INET6_ADDRSTRLEN];
1813
1814 chunk_printf(&msg, " title=\"IP: ");
1815
1816 /* IP */
1817 if (inet_ntop(sv->addr.sin_family, &sv->addr.sin_addr, str, sizeof(str)))
1818 chunk_printf(&msg, "%s:%d", str, htons(sv->addr.sin_port));
1819 else
1820 chunk_printf(&msg, "(%s)", strerror(errno));
1821
1822 /* id */
1823 chunk_printf(&msg, ", id: %d", sv->puid);
1824
1825 /* cookie */
1826 if (sv->cookie) {
1827 struct chunk src;
1828
1829 chunk_printf(&msg, ", cookie: '");
1830
1831 chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie));
1832 chunk_htmlencode(&msg, &src);
1833
1834 chunk_printf(&msg, "'");
1835 }
1836
1837 chunk_printf(&msg, "\"");
1838 }
1839
1840 chunk_printf(&msg,
Willy Tarreaue0454092010-02-26 12:29:07 +01001841 ">%s<a name=\"%s/%s\"></a>"
1842 "<a class=lfsb href=\"#%s/%s\">%s</a>%s</td>"
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02001843 /* queue : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001844 "<td>%s</td><td>%s</td><td>%s</td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02001845 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001846 "<td>%s</td><td>%s</td><td></td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001847 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001848 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001849 "<td"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001850 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01001851 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001852 px->id, sv->id, px->id, sv->id, sv->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01001853 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreauac68c5d2009-10-04 23:12:44 +02001854 U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"),
1855 U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max),
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001856 U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-"));
1857
1858 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
1859 if (px->mode == PR_MODE_HTTP) {
1860 int i;
1861
1862 chunk_printf(&msg, " title=\"rsp codes:");
1863
1864 for (i = 1; i < 6; i++)
1865 chunk_printf(&msg, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]);
1866
1867 chunk_printf(&msg, " other=%lld\"", sv->counters.p.http.rsp[0]);
1868 }
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02001869
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001870 chunk_printf(&msg,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001871 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01001872 ">%s%s%s</td><td>%s</td>",
1873 (px->mode == PR_MODE_HTTP)?"<u>":"",
1874 U2H0(sv->counters.cum_sess),
1875 (px->mode == PR_MODE_HTTP)?"</u>":"",
1876 U2H1(sv->counters.cum_lbconn));
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02001877
1878 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001879 /* bytes : in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001880 "<td>%s</td><td>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001881 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001882 "<td></td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01001883 /* errors : request, connect */
1884 "<td></td><td>%s</td>"
1885 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01001886 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02001887 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001888 "<td>%lld</td><td>%lld</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001889 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001890 U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out),
1891 U2H2(sv->counters.failed_secu),
Willy Tarreauae526782010-03-04 20:34:23 +01001892 U2H3(sv->counters.failed_conns),
Willy Tarreau6a8573e2010-03-05 18:15:23 +01001893 sv->counters.cli_aborts,
1894 sv->counters.srv_aborts,
Willy Tarreauae526782010-03-04 20:34:23 +01001895 U2H6(sv->counters.failed_resp),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001896 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01001897
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001898 /* status, lest check */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001899 chunk_printf(&msg, "<td class=ac>");
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001900
Cyril Bontécd19e512010-01-31 22:34:03 +01001901 if (sv->state & SRV_MAINTAIN) {
1902 chunk_printf(&msg, "%s ",
1903 human_time(now.tv_sec - sv->last_change, 1));
1904 chunk_printf(&msg, "MAINT");
1905 }
Cyril Bonté0dae5852010-02-03 00:26:28 +01001906 else if (svs != sv && svs->state & SRV_MAINTAIN) {
1907 chunk_printf(&msg, "%s ",
1908 human_time(now.tv_sec - svs->last_change, 1));
1909 chunk_printf(&msg, "MAINT(via)");
1910 }
Cyril Bontécd19e512010-01-31 22:34:03 +01001911 else if (svs->state & SRV_CHECKED) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001912 chunk_printf(&msg, "%s ",
Cyril Bonté0dae5852010-02-03 00:26:28 +01001913 human_time(now.tv_sec - svs->last_change, 1));
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001914
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001915 chunk_printf(&msg,
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001916 srv_hlt_st[sv_state],
1917 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
1918 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001919 }
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02001920
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001921 if (sv->state & SRV_CHECKED) {
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001922 chunk_printf(&msg, "</td><td class=ac title=\"%s",
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +02001923 get_check_status_description(sv->check_status));
1924
1925 if (*sv->check_desc) {
1926 struct chunk src;
1927
1928 chunk_printf(&msg, ": ");
1929
1930 chunk_initlen(&src, sv->check_desc, 0, strlen(sv->check_desc));
1931 chunk_htmlencode(&msg, &src);
1932 }
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001933
Willy Tarreaue0454092010-02-26 12:29:07 +01001934 chunk_printf(&msg, "\"><u> %s%s",
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001935 tv_iszero(&sv->check_start)?"":"* ",
1936 get_check_status_info(sv->check_status));
1937
1938 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001939 chunk_printf(&msg, "/%d", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001940
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001941 if (sv->check_status >= HCHK_STATUS_CHECKED && sv->check_duration >= 0)
Willy Tarreaue0454092010-02-26 12:29:07 +01001942 chunk_printf(&msg, " in %lums</u>", sv->check_duration);
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01001943 } else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001944 chunk_printf(&msg, "</td><td>");
Willy Tarreau91861262007-10-17 17:06:05 +02001945
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001946 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02001947 /* weight */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001948 "</td><td class=ac>%d</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001949 /* act, bck */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001950 "<td class=ac>%s</td><td class=ac>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02001951 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01001952 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau91861262007-10-17 17:06:05 +02001953 (sv->state & SRV_BACKUP) ? "-" : "Y",
1954 (sv->state & SRV_BACKUP) ? "Y" : "-");
1955
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001956 /* check failures: unique, fatal, down time */
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01001957 if (sv->state & SRV_CHECKED) {
Willy Tarreaue0454092010-02-26 12:29:07 +01001958 chunk_printf(&msg, "<td title=\"Failed Health Checks%s\"><u>%lld",
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01001959 svs->observe?"/Health Analyses":"", svs->counters.failed_checks);
1960
1961 if (svs->observe)
1962 chunk_printf(&msg, "/%lld", svs->counters.failed_hana);
1963
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001964 chunk_printf(&msg,
Willy Tarreaue0454092010-02-26 12:29:07 +01001965 "</u></td>"
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001966 "<td>%lld</td><td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001967 "",
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01001968 svs->counters.down_trans, human_time(srv_downtime(sv), 1));
Krzysztof Piotr Oledzki748196e2010-01-04 00:48:43 +01001969 } else if (sv != svs)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001970 chunk_printf(&msg,
Krzysztof Piotr Oledzki88a14af2010-01-05 18:33:01 +01001971 "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>",
1972 svs->proxy->id, svs->id, svs->proxy->id, svs->id);
Willy Tarreau55bb8452007-10-17 18:44:57 +02001973 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001974 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001975 "<td colspan=3></td>");
1976
1977 /* throttle */
1978 if ((sv->state & SRV_WARMINGUP) &&
1979 now.tv_sec < sv->last_change + sv->slowstart &&
1980 now.tv_sec >= sv->last_change) {
1981 unsigned int ratio;
1982 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001983 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001984 "<td class=ac>%d %%</td></tr>\n", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001985 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001986 chunk_printf(&msg,
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02001987 "<td class=ac>-</td></tr>\n");
Willy Tarreau4bab24d2007-11-30 18:16:29 +01001988 }
Willy Tarreau55bb8452007-10-17 18:44:57 +02001989 } else {
Willy Tarreau2ea81932007-11-30 12:04:38 +01001990 static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,",
1991 "UP %d/%d,", "UP,",
1992 "NOLB %d/%d,", "NOLB,",
1993 "no check," };
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02001994 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02001995 /* pxid, name */
1996 "%s,%s,"
1997 /* queue : current, max */
1998 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01001999 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002000 "%d,%d,%s,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002001 /* bytes : in, out */
2002 "%lld,%lld,"
2003 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002004 ",%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002005 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002006 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002007 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002008 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002009 "",
2010 px->id, sv->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002011 sv->nbpend, sv->counters.nbpend_max,
2012 sv->cur_sess, sv->counters.cur_sess_max, LIM2A0(sv->maxconn, ""), sv->counters.cum_sess,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002013 sv->counters.bytes_in, sv->counters.bytes_out,
2014 sv->counters.failed_secu,
2015 sv->counters.failed_conns, sv->counters.failed_resp,
2016 sv->counters.retries, sv->counters.redispatches);
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002017
Willy Tarreau55bb8452007-10-17 18:44:57 +02002018 /* status */
Cyril Bontécd19e512010-01-31 22:34:03 +01002019 if (sv->state & SRV_MAINTAIN) {
2020 chunk_printf(&msg, "MAINT,");
Cyril Bonté0dae5852010-02-03 00:26:28 +01002021 }
2022 else if (svs != sv && svs->state & SRV_MAINTAIN) {
2023 chunk_printf(&msg, "MAINT(via),");
2024 }
2025 else {
Cyril Bontécd19e512010-01-31 22:34:03 +01002026 chunk_printf(&msg,
2027 srv_hlt_st[sv_state],
2028 (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health),
2029 (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise));
2030 }
Willy Tarreau91861262007-10-17 17:06:05 +02002031
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002032 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002033 /* weight, active, backup */
2034 "%d,%d,%d,"
2035 "",
Willy Tarreau5542af62007-12-03 02:04:00 +01002036 (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002037 (sv->state & SRV_BACKUP) ? 0 : 1,
2038 (sv->state & SRV_BACKUP) ? 1 : 0);
2039
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002040 /* check failures: unique, fatal; last change, total downtime */
Willy Tarreau55bb8452007-10-17 18:44:57 +02002041 if (sv->state & SRV_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002042 chunk_printf(&msg,
Willy Tarreau3b88d442009-04-11 20:44:08 +02002043 "%lld,%lld,%d,%d,",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002044 sv->counters.failed_checks, sv->counters.down_trans,
Willy Tarreau1772ece2009-04-03 14:49:12 +02002045 (int)(now.tv_sec - sv->last_change), srv_downtime(sv));
Willy Tarreau55bb8452007-10-17 18:44:57 +02002046 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002047 chunk_printf(&msg,
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002048 ",,,,");
2049
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002050 /* queue limit, pid, iid, sid, */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002051 chunk_printf(&msg,
Willy Tarreaudcd47712007-11-04 23:35:08 +01002052 "%s,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002053 "%d,%d,%d,",
Willy Tarreaudcd47712007-11-04 23:35:08 +01002054 LIM2A0(sv->maxqueue, ""),
2055 relative_pid, px->uuid, sv->puid);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002056
2057 /* throttle */
2058 if ((sv->state & SRV_WARMINGUP) &&
2059 now.tv_sec < sv->last_change + sv->slowstart &&
2060 now.tv_sec >= sv->last_change) {
2061 unsigned int ratio;
2062 ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart);
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002063 chunk_printf(&msg, "%d", ratio);
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002064 }
2065
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002066 /* sessions: lbtot */
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002067 chunk_printf(&msg, ",%lld,", sv->counters.cum_lbconn);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002068
2069 /* tracked */
2070 if (sv->tracked)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002071 chunk_printf(&msg, "%s/%s,",
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002072 sv->tracked->proxy->id, sv->tracked->id);
2073 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002074 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01002075
Willy Tarreau7f062c42009-03-05 18:43:00 +01002076 /* type */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002077 chunk_printf(&msg, "%d,", STATS_TYPE_SV);
Willy Tarreau7f062c42009-03-05 18:43:00 +01002078
2079 /* rate */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002080 chunk_printf(&msg, "%u,,%u,",
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002081 read_freq_ctr(&sv->sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002082 sv->counters.sps_max);
Willy Tarreau7f062c42009-03-05 18:43:00 +01002083
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002084 if (sv->state & SRV_CHECKED) {
2085 /* check_status */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002086 chunk_printf(&msg, "%s,", get_check_status_info(sv->check_status));
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002087
2088 /* check_code */
2089 if (sv->check_status >= HCHK_STATUS_L57DATA)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002090 chunk_printf(&msg, "%u,", sv->check_code);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002091 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002092 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002093
2094 /* check_duration */
Krzysztof Piotr Oledzki034550b2010-01-05 18:44:44 +01002095 if (sv->check_status >= HCHK_STATUS_CHECKED)
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002096 chunk_printf(&msg, "%lu,", sv->check_duration);
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002097 else
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002098 chunk_printf(&msg, ",");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002099
2100 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002101 chunk_printf(&msg, ",,,");
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002102 }
2103
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002104 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2105 if (px->mode == PR_MODE_HTTP) {
2106 int i;
2107
2108 for (i=1; i<6; i++)
2109 chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[i]);
2110
2111 chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[0]);
2112 } else {
2113 chunk_printf(&msg, ",,,,,,");
2114 }
2115
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002116 /* failed health analyses */
2117 chunk_printf(&msg, "%lld,", sv->counters.failed_hana);
2118
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002119 /* requests : req_rate, req_rate_max, req_tot, */
2120 chunk_printf(&msg, ",,,");
2121
Willy Tarreauae526782010-03-04 20:34:23 +01002122 /* errors: cli_aborts, srv_aborts */
2123 chunk_printf(&msg, "%lld,%lld,",
2124 sv->counters.cli_aborts, sv->counters.srv_aborts);
2125
Willy Tarreau7f062c42009-03-05 18:43:00 +01002126 /* finish with EOL */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002127 chunk_printf(&msg, "\n");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002128 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002129 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002130 return 0;
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002131 } /* for sv */
Willy Tarreau91861262007-10-17 17:06:05 +02002132
2133 s->data_ctx.stats.px_st = DATA_ST_PX_BE;
2134 /* fall through */
2135
2136 case DATA_ST_PX_BE:
2137 /* print the backend */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002138 if ((px->cap & PR_CAP_BE) &&
2139 (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_BE)))) {
2140 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002141 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002142 /* name */
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002143 "<tr class=\"backend\"><td class=ac");
2144
2145 if (uri->flags&ST_SHLGNDS) {
2146 /* balancing */
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01002147 chunk_printf(&msg, " title=\"balancing: %s",
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002148 backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
Krzysztof Piotr Oledzkic0f0c862010-01-06 15:03:18 +01002149
2150 /* cookie */
2151 if (px->cookie_name) {
2152 struct chunk src;
2153
2154 chunk_printf(&msg, ", cookie: '");
2155
2156 chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name));
2157 chunk_htmlencode(&msg, &src);
2158
2159 chunk_printf(&msg, "'");
2160 }
2161
2162 chunk_printf(&msg, "\"");
2163
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01002164 }
2165
2166 chunk_printf(&msg,
Willy Tarreaue0454092010-02-26 12:29:07 +01002167 ">%s<a name=\"%s/Backend\"></a>"
2168 "<a class=lfsb href=\"#%s/Backend\">Backend</a>%s</td>"
Willy Tarreau91861262007-10-17 17:06:05 +02002169 /* queue : current, max */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002170 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002171 /* sessions rate : current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002172 "<td>%s</td><td>%s</td><td></td>"
Willy Tarreaua3e49422009-05-10 19:19:41 +02002173 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002174 (uri->flags & ST_SHLGNDS)?"<u>":"",
Krzysztof Piotr Oledzki1f672852009-10-24 14:24:30 +02002175 px->id, px->id,
Willy Tarreaue0454092010-02-26 12:29:07 +01002176 (uri->flags & ST_SHLGNDS)?"</u>":"",
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002177 U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->counters.nbpend_max),
2178 U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->counters.be_sps_max));
Willy Tarreaua3e49422009-05-10 19:19:41 +02002179
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002180 chunk_printf(&msg,
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002181 /* sessions: current, max, limit */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002182 "<td>%s</td><td>%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002183 "<td"
2184 "",
2185 U2H2(px->beconn), U2H3(px->counters.beconn_max), U2H4(px->fullconn));
2186
2187 /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */
2188 if (px->mode == PR_MODE_HTTP) {
2189 int i;
2190
2191 chunk_printf(&msg, " title=\"rsp codes:");
2192
2193 for (i = 1; i < 6; i++)
Willy Tarreau24657792010-02-26 10:30:28 +01002194 chunk_printf(&msg, " %dxx=%lld", i, px->counters.be.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002195
Willy Tarreau24657792010-02-26 10:30:28 +01002196 chunk_printf(&msg, " other=%lld\"", px->counters.be.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002197 }
2198
2199 chunk_printf(&msg,
2200 /* sessions: total, lbtot */
Willy Tarreaue0454092010-02-26 12:29:07 +01002201 ">%s%s%s</td><td>%s</td>"
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002202 /* bytes: in, out */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002203 "<td>%s</td><td>%s</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002204 "",
Willy Tarreaue0454092010-02-26 12:29:07 +01002205 (px->mode == PR_MODE_HTTP)?"<u>":"",
2206 U2H6(px->counters.cum_beconn),
2207 (px->mode == PR_MODE_HTTP)?"</u>":"",
2208 U2H7(px->counters.cum_lbconn),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002209 U2H8(px->counters.bytes_in), U2H9(px->counters.bytes_out));
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002210
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002211 chunk_printf(&msg,
Willy Tarreau91861262007-10-17 17:06:05 +02002212 /* denied: req, resp */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002213 "<td>%s</td><td>%s</td>"
Willy Tarreauae526782010-03-04 20:34:23 +01002214 /* errors : request, connect */
2215 "<td></td><td>%s</td>"
2216 /* errors : response */
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002217 "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002218 /* warnings: retries, redispatches */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002219 "<td>%lld</td><td>%lld</td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002220 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau91861262007-10-17 17:06:05 +02002221 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002222 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau91861262007-10-17 17:06:05 +02002223 * active and backups. */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002224 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
2225 "<td class=ac>%d</td><td class=ac>%d</td>"
Willy Tarreau0a6d2ef2009-03-29 14:46:01 +02002226 "",
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002227 U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp),
Willy Tarreauae526782010-03-04 20:34:23 +01002228 U2H2(px->counters.failed_conns),
Willy Tarreau6a8573e2010-03-05 18:15:23 +01002229 px->counters.cli_aborts,
2230 px->counters.srv_aborts,
Willy Tarreauae526782010-03-04 20:34:23 +01002231 U2H5(px->counters.failed_resp),
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002232 px->counters.retries, px->counters.redispatches,
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002233 human_time(now.tv_sec - px->last_change, 1),
Willy Tarreau2ea81932007-11-30 12:04:38 +01002234 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" :
2235 "<font color=\"red\"><b>DOWN</b></font>",
Willy Tarreau5542af62007-12-03 02:04:00 +01002236 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01002237 px->srv_act, px->srv_bck);
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002238
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002239 chunk_printf(&msg,
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002240 /* rest of backend: nothing, down transitions, total downtime, throttle */
Krzysztof Piotr Oledzkif2d2b1d2009-10-12 23:09:08 +02002241 "<td class=ac>&nbsp;</td><td>%d</td>"
2242 "<td>%s</td>"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002243 "<td></td>"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002244 "</tr>",
2245 px->down_trans,
2246 px->srv?human_time(be_downtime(px), 1):"&nbsp;");
Willy Tarreau55bb8452007-10-17 18:44:57 +02002247 } else {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002248 chunk_printf(&msg,
Willy Tarreau55bb8452007-10-17 18:44:57 +02002249 /* pxid, name */
2250 "%s,BACKEND,"
2251 /* queue : current, max */
2252 "%d,%d,"
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002253 /* sessions : current, max, limit, total */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002254 "%d,%d,%d,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002255 /* bytes : in, out */
2256 "%lld,%lld,"
2257 /* denied: req, resp */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002258 "%lld,%lld,"
Willy Tarreau55bb8452007-10-17 18:44:57 +02002259 /* errors : request, connect, response */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002260 ",%lld,%lld,"
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +02002261 /* warnings: retries, redispatches */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002262 "%lld,%lld,"
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002263 /* backend status: reflect backend status (up/down): we display UP
Willy Tarreau55bb8452007-10-17 18:44:57 +02002264 * if the backend has known working servers or if it has no server at
Krzysztof Oledzki85130942007-10-22 16:21:10 +02002265 * all (eg: for stats). Then we display the total weight, number of
Willy Tarreau55bb8452007-10-17 18:44:57 +02002266 * active and backups. */
2267 "%s,"
2268 "%d,%d,%d,"
Willy Tarreau4bab24d2007-11-30 18:16:29 +01002269 /* rest of backend: nothing, down transitions, last change, total downtime */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +02002270 ",%d,%d,%d,,"
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01002271 /* pid, iid, sid, throttle, lbtot, tracked, type */
Willy Tarreau3b88d442009-04-11 20:44:08 +02002272 "%d,%d,0,,%lld,,%d,"
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002273 /* rate, rate_lim, rate_max, */
2274 "%u,,%u,"
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02002275 /* check_status, check_code, check_duration */
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002276 ",,,",
Willy Tarreau55bb8452007-10-17 18:44:57 +02002277 px->id,
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002278 px->nbpend /* or px->totpend ? */, px->counters.nbpend_max,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002279 px->beconn, px->counters.beconn_max, px->fullconn, px->counters.cum_beconn,
2280 px->counters.bytes_in, px->counters.bytes_out,
2281 px->counters.denied_req, px->counters.denied_resp,
2282 px->counters.failed_conns, px->counters.failed_resp,
2283 px->counters.retries, px->counters.redispatches,
Willy Tarreau20697042007-11-15 23:26:18 +01002284 (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN",
Willy Tarreau5542af62007-12-03 02:04:00 +01002285 (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv,
Willy Tarreau20697042007-11-15 23:26:18 +01002286 px->srv_act, px->srv_bck,
Willy Tarreau1772ece2009-04-03 14:49:12 +02002287 px->down_trans, (int)(now.tv_sec - px->last_change),
Willy Tarreau20697042007-11-15 23:26:18 +01002288 px->srv?be_downtime(px):0,
Willy Tarreauddbb82f2007-12-05 10:34:49 +01002289 relative_pid, px->uuid,
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002290 px->counters.cum_lbconn, STATS_TYPE_BE,
Willy Tarreau8f208ec2009-05-10 19:01:49 +02002291 read_freq_ctr(&px->be_sess_per_sec),
Willy Tarreauac68c5d2009-10-04 23:12:44 +02002292 px->counters.be_sps_max);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002293
2294 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
2295 if (px->mode == PR_MODE_HTTP) {
2296 int i;
2297
2298 for (i=1; i<6; i++)
Willy Tarreau24657792010-02-26 10:30:28 +01002299 chunk_printf(&msg, "%lld,", px->counters.be.http.rsp[i]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002300
Willy Tarreau24657792010-02-26 10:30:28 +01002301 chunk_printf(&msg, "%lld,", px->counters.be.http.rsp[0]);
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002302 } else {
2303 chunk_printf(&msg, ",,,,,,");
2304 }
2305
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01002306 /* failed health analyses */
2307 chunk_printf(&msg, ",");
2308
Willy Tarreaud9b587f2010-02-26 10:05:55 +01002309 /* requests : req_rate, req_rate_max, req_tot, */
2310 chunk_printf(&msg, ",,,");
2311
Willy Tarreauae526782010-03-04 20:34:23 +01002312 /* errors: cli_aborts, srv_aborts */
2313 chunk_printf(&msg, "%lld,%lld,",
2314 px->counters.cli_aborts, px->counters.srv_aborts);
2315
Krzysztof Piotr Oledzki5fb18822009-10-13 21:14:09 +02002316 /* finish with EOL */
2317 chunk_printf(&msg, "\n");
2318
Willy Tarreau55bb8452007-10-17 18:44:57 +02002319 }
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002320 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau91861262007-10-17 17:06:05 +02002321 return 0;
2322 }
Willy Tarreaub1356cf2008-12-07 16:06:43 +01002323
Willy Tarreau91861262007-10-17 17:06:05 +02002324 s->data_ctx.stats.px_st = DATA_ST_PX_END;
2325 /* fall through */
2326
2327 case DATA_ST_PX_END:
Willy Tarreau39f7e6d2008-03-17 21:38:24 +01002328 if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002329 chunk_printf(&msg, "</table><p>\n");
Willy Tarreau91861262007-10-17 17:06:05 +02002330
Willy Tarreaub0c9bc42009-10-04 15:56:38 +02002331 if (buffer_feed_chunk(rep, &msg) >= 0)
Willy Tarreau55bb8452007-10-17 18:44:57 +02002332 return 0;
2333 }
Willy Tarreau91861262007-10-17 17:06:05 +02002334
2335 s->data_ctx.stats.px_st = DATA_ST_PX_FIN;
2336 /* fall through */
2337
2338 case DATA_ST_PX_FIN:
2339 return 1;
2340
2341 default:
2342 /* unknown state, we should put an abort() here ! */
2343 return 1;
2344 }
2345}
2346
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002347/* This function is called to send output to the response buffer. It dumps a
2348 * complete session state onto the output buffer <rep>. The session has to be
2349 * set in data_ctx.sess.target. It returns 0 if the output buffer is full and
2350 * it needs to be called again, otherwise non-zero. It is designed to be called
2351 * from stats_dump_sess_to_buffer() below.
2352 */
2353
2354/* returns 1 if dump is not complete */
2355int stats_dump_full_sess_to_buffer(struct session *s, struct buffer *rep)
2356{
2357 struct tm tm;
2358 struct chunk msg;
2359 struct session *sess;
2360 extern const char *monthname[12];
2361 char pn[INET6_ADDRSTRLEN];
2362
2363 chunk_init(&msg, trash, sizeof(trash));
2364 sess = s->data_ctx.sess.target;
2365
2366 if (s->data_ctx.sess.section > 0 && s->data_ctx.sess.uid != sess->uniq_id) {
2367 /* session changed, no need to go any further */
2368 chunk_printf(&msg, " *** session terminated while we were watching it ***\n");
2369 if (buffer_feed_chunk(rep, &msg) >= 0)
2370 return 0;
2371 s->data_ctx.sess.target = NULL;
2372 s->data_ctx.sess.uid = 0;
2373 return 1;
2374 }
2375
2376 switch (s->data_ctx.sess.section) {
2377 case 0: /* main status of the session */
2378 s->data_ctx.sess.uid = sess->uniq_id;
2379 s->data_ctx.sess.section = 1;
2380 /* fall through */
2381
2382 case 1:
2383 chunk_printf(&msg,
2384 "%p: id=%u, proto=%s",
2385 sess,
2386 sess->uniq_id,
2387 sess->listener->proto->name);
2388
2389 switch (sess->listener->proto->sock_family) {
2390 case AF_INET:
2391 inet_ntop(AF_INET,
2392 (const void *)&((struct sockaddr_in *)&sess->cli_addr)->sin_addr,
2393 pn, sizeof(pn));
2394
2395 chunk_printf(&msg,
2396 " source=%s:%d\n",
2397 pn,
2398 ntohs(((struct sockaddr_in *)&sess->cli_addr)->sin_port));
2399 break;
2400 case AF_INET6:
2401 inet_ntop(AF_INET6,
2402 (const void *)&((struct sockaddr_in6 *)(&sess->cli_addr))->sin6_addr,
2403 pn, sizeof(pn));
2404
2405 chunk_printf(&msg,
2406 " source=%s:%d\n",
2407 pn,
2408 ntohs(((struct sockaddr_in6 *)&sess->cli_addr)->sin6_port));
2409 break;
2410 case AF_UNIX:
2411 default:
2412 /* no more information to print right now */
2413 chunk_printf(&msg, "\n");
2414 break;
2415 }
2416
2417 chunk_printf(&msg,
2418 " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n",
Willy Tarreauee28de02010-06-01 09:51:00 +02002419 sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos);
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002420
2421 chunk_printf(&msg,
2422 " frontend=%s (id=%u mode=%s), listener=%s (id=%u)\n",
2423 sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp",
2424 sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?",
2425 sess->listener ? sess->listener->luid : 0);
2426
2427 chunk_printf(&msg,
2428 " backend=%s (id=%u mode=%s) server=%s (id=%u)\n",
2429 sess->be->id, sess->be->uuid, sess->be->mode ? "http" : "tcp",
2430 sess->srv ? sess->srv->id : "<none>",
2431 sess->srv ? sess->srv->puid : 0);
2432
2433 chunk_printf(&msg,
2434 " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s)\n",
2435 sess->task,
2436 sess->task->state,
2437 sess->task->nice, sess->task->calls,
2438 sess->task->expire ?
2439 tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" :
2440 human_time(TICKS_TO_MS(sess->task->expire - now_ms),
2441 TICKS_TO_MS(1000)) : "<NEVER>",
2442 task_in_rq(sess->task) ? ", running" : "");
2443
2444 get_localtime(sess->logs.accept_date.tv_sec, &tm);
2445 chunk_printf(&msg,
2446 " task created [%02d/%s/%04d:%02d:%02d:%02d.%06d] (age=%s)\n",
2447 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
2448 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec),
2449 human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1));
2450
2451 chunk_printf(&msg,
2452 " si[0]=%p (state=%d flags=0x%02x fd=%d exp=%s, et=0x%03x)\n",
2453 &sess->si[0],
2454 sess->si[0].state,
2455 sess->si[0].flags,
2456 sess->si[0].fd,
2457 sess->si[0].exp ?
2458 tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" :
2459 human_time(TICKS_TO_MS(sess->si[0].exp - now_ms),
2460 TICKS_TO_MS(1000)) : "<NEVER>",
2461 sess->si[0].err_type);
2462
2463 chunk_printf(&msg,
2464 " si[1]=%p (state=%d flags=0x%02x fd=%d exp=%s, et=0x%03x)\n",
2465 &sess->si[1],
2466 sess->si[1].state,
2467 sess->si[1].flags,
2468 sess->si[1].fd,
2469 sess->si[1].exp ?
2470 tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" :
2471 human_time(TICKS_TO_MS(sess->si[1].exp - now_ms),
2472 TICKS_TO_MS(1000)) : "<NEVER>",
2473 sess->si[1].err_type);
2474
2475 chunk_printf(&msg,
2476 " txn=%p (flags=0x%x meth=%d status=%d req.st=%d rsp.st=%d)\n",
2477 &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status,
2478 sess->txn.req.msg_state, sess->txn.rsp.msg_state);
2479
2480
2481 chunk_printf(&msg,
2482 " req=%p (f=0x%06x an=0x%x l=%d sndmx=%d pipe=%d fwd=%ld)\n"
2483 " an_exp=%s",
2484 sess->req,
2485 sess->req->flags, sess->req->analysers,
2486 sess->req->l, sess->req->send_max,
2487 sess->req->pipe ? sess->req->pipe->data : 0,
2488 sess->req->to_forward,
2489 sess->req->analyse_exp ?
2490 human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms),
2491 TICKS_TO_MS(1000)) : "<NEVER>");
2492
2493 chunk_printf(&msg,
2494 " rex=%s",
2495 sess->req->rex ?
2496 human_time(TICKS_TO_MS(sess->req->rex - now_ms),
2497 TICKS_TO_MS(1000)) : "<NEVER>");
2498
2499 chunk_printf(&msg,
2500 " wex=%s\n"
2501 " data=%p r=%d w=%d lr=%d total=%lld\n",
2502 sess->req->wex ?
2503 human_time(TICKS_TO_MS(sess->req->wex - now_ms),
2504 TICKS_TO_MS(1000)) : "<NEVER>",
2505 sess->req->data,
Willy Tarreau4e1554c2010-03-21 23:21:00 +01002506 (int)(sess->req->r - sess->req->data),
2507 (int)(sess->req->w - sess->req->data),
2508 (int)(sess->req->lr - sess->req->data),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002509 sess->req->total);
2510
2511 chunk_printf(&msg,
2512 " res=%p (f=0x%06x an=0x%x l=%d sndmx=%d pipe=%d fwd=%ld)\n"
2513 " an_exp=%s",
2514 sess->rep,
2515 sess->rep->flags, sess->rep->analysers,
2516 sess->rep->l, sess->rep->send_max,
2517 sess->rep->pipe ? sess->rep->pipe->data : 0,
2518 sess->rep->to_forward,
2519 sess->rep->analyse_exp ?
2520 human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms),
2521 TICKS_TO_MS(1000)) : "<NEVER>");
2522
2523 chunk_printf(&msg,
2524 " rex=%s",
2525 sess->rep->rex ?
2526 human_time(TICKS_TO_MS(sess->rep->rex - now_ms),
2527 TICKS_TO_MS(1000)) : "<NEVER>");
2528
2529 chunk_printf(&msg,
2530 " wex=%s\n"
2531 " data=%p r=%d w=%d lr=%d total=%lld\n",
2532 sess->rep->wex ?
2533 human_time(TICKS_TO_MS(sess->rep->wex - now_ms),
2534 TICKS_TO_MS(1000)) : "<NEVER>",
2535 sess->rep->data,
Willy Tarreau4e1554c2010-03-21 23:21:00 +01002536 (int)(sess->rep->r - sess->rep->data),
2537 (int)(sess->rep->w - sess->rep->data),
2538 (int)(sess->rep->lr - sess->rep->data),
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002539 sess->rep->total);
2540
2541 if (buffer_feed_chunk(rep, &msg) >= 0)
2542 return 0;
2543
2544 /* use other states to dump the contents */
2545 }
2546 /* end of dump */
2547 s->data_ctx.sess.uid = 0;
2548 return 1;
2549}
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002550
2551/* This function is called to send output to the response buffer.
2552 * It dumps the sessions states onto the output buffer <rep>.
2553 * Expects to be called with client socket shut down on input.
2554 * s->data_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002555 * It returns 0 as long as it does not complete, non-zero upon completion.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002556 */
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002557int stats_dump_sess_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002558{
2559 struct chunk msg;
2560
2561 if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) {
2562 /* If we're forced to shut down, we might have to remove our
2563 * reference to the last session being dumped.
2564 */
2565 if (s->data_state == DATA_ST_LIST) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002566 if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) {
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002567 LIST_DEL(&s->data_ctx.sess.bref.users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002568 LIST_INIT(&s->data_ctx.sess.bref.users);
2569 }
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002570 }
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002571 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002572 }
2573
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002574 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002575
2576 switch (s->data_state) {
2577 case DATA_ST_INIT:
2578 /* the function had not been called yet, let's prepare the
2579 * buffer for a response. We initialize the current session
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002580 * pointer to the first in the global list. When a target
2581 * session is being destroyed, it is responsible for updating
2582 * this pointer. We know we have reached the end when this
2583 * pointer points back to the head of the sessions list.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002584 */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002585 LIST_INIT(&s->data_ctx.sess.bref.users);
2586 s->data_ctx.sess.bref.ref = sessions.n;
2587 s->data_state = DATA_ST_LIST;
2588 /* fall through */
2589
2590 case DATA_ST_LIST:
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002591 /* first, let's detach the back-ref from a possible previous session */
2592 if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) {
2593 LIST_DEL(&s->data_ctx.sess.bref.users);
2594 LIST_INIT(&s->data_ctx.sess.bref.users);
2595 }
2596
2597 /* and start from where we stopped */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002598 while (s->data_ctx.sess.bref.ref != &sessions) {
2599 char pn[INET6_ADDRSTRLEN + strlen(":65535")];
2600 struct session *curr_sess;
2601
2602 curr_sess = LIST_ELEM(s->data_ctx.sess.bref.ref, struct session *, list);
2603
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002604 if (s->data_ctx.sess.target) {
2605 if (s->data_ctx.sess.target != curr_sess)
2606 goto next_sess;
2607
2608 LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users);
2609 /* call the proper dump() function and return if we're missing space */
2610 if (!stats_dump_full_sess_to_buffer(s, rep))
2611 return 0;
2612
2613 /* session dump complete */
2614 LIST_DEL(&s->data_ctx.sess.bref.users);
2615 LIST_INIT(&s->data_ctx.sess.bref.users);
2616 s->data_ctx.sess.target = NULL;
2617 break;
2618 }
2619
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002620 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002621 "%p: proto=%s",
2622 curr_sess,
2623 curr_sess->listener->proto->name);
2624
2625 switch (curr_sess->listener->proto->sock_family) {
2626 case AF_INET:
2627 inet_ntop(AF_INET,
2628 (const void *)&((struct sockaddr_in *)&curr_sess->cli_addr)->sin_addr,
2629 pn, sizeof(pn));
2630
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002631 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002632 " src=%s:%d fe=%s be=%s srv=%s",
2633 pn,
2634 ntohs(((struct sockaddr_in *)&curr_sess->cli_addr)->sin_port),
2635 curr_sess->fe->id,
2636 curr_sess->be->id,
2637 curr_sess->srv ? curr_sess->srv->id : "<none>"
2638 );
2639 break;
2640 case AF_INET6:
2641 inet_ntop(AF_INET6,
2642 (const void *)&((struct sockaddr_in6 *)(&curr_sess->cli_addr))->sin6_addr,
2643 pn, sizeof(pn));
2644
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002645 chunk_printf(&msg,
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002646 " src=%s:%d fe=%s be=%s srv=%s",
2647 pn,
2648 ntohs(((struct sockaddr_in6 *)&curr_sess->cli_addr)->sin6_port),
2649 curr_sess->fe->id,
2650 curr_sess->be->id,
2651 curr_sess->srv ? curr_sess->srv->id : "<none>"
2652 );
2653
2654 break;
2655 case AF_UNIX:
2656 /* no more information to print right now */
2657 break;
2658 }
2659
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002660 chunk_printf(&msg,
Willy Tarreau65671ab2009-10-04 14:24:59 +02002661 " ts=%02x age=%s calls=%d",
2662 curr_sess->task->state,
Willy Tarreau3884cba2009-03-28 17:54:35 +01002663 human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1),
2664 curr_sess->task->calls);
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002665
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002666 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002667 " rq[f=%06xh,l=%d,an=%02xh,rx=%s",
2668 curr_sess->req->flags,
2669 curr_sess->req->l,
2670 curr_sess->req->analysers,
2671 curr_sess->req->rex ?
2672 human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms),
2673 TICKS_TO_MS(1000)) : "");
2674
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002675 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002676 ",wx=%s",
2677 curr_sess->req->wex ?
2678 human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms),
2679 TICKS_TO_MS(1000)) : "");
2680
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002681 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002682 ",ax=%s]",
2683 curr_sess->req->analyse_exp ?
2684 human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms),
2685 TICKS_TO_MS(1000)) : "");
2686
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002687 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002688 " rp[f=%06xh,l=%d,an=%02xh,rx=%s",
2689 curr_sess->rep->flags,
2690 curr_sess->rep->l,
2691 curr_sess->rep->analysers,
2692 curr_sess->rep->rex ?
2693 human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms),
2694 TICKS_TO_MS(1000)) : "");
2695
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002696 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002697 ",wx=%s",
2698 curr_sess->rep->wex ?
2699 human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms),
2700 TICKS_TO_MS(1000)) : "");
2701
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002702 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002703 ",ax=%s]",
2704 curr_sess->rep->analyse_exp ?
2705 human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms),
2706 TICKS_TO_MS(1000)) : "");
2707
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002708 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002709 " s0=[%d,%1xh,fd=%d,ex=%s]",
2710 curr_sess->si[0].state,
2711 curr_sess->si[0].flags,
2712 curr_sess->si[0].fd,
2713 curr_sess->si[0].exp ?
2714 human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms),
2715 TICKS_TO_MS(1000)) : "");
2716
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002717 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002718 " s1=[%d,%1xh,fd=%d,ex=%s]",
2719 curr_sess->si[1].state,
2720 curr_sess->si[1].flags,
2721 curr_sess->si[1].fd,
2722 curr_sess->si[1].exp ?
2723 human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms),
2724 TICKS_TO_MS(1000)) : "");
2725
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002726 chunk_printf(&msg,
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002727 " exp=%s",
2728 curr_sess->task->expire ?
2729 human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms),
2730 TICKS_TO_MS(1000)) : "");
Willy Tarreau4726f532009-03-07 17:25:21 +01002731 if (task_in_rq(curr_sess->task))
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002732 chunk_printf(&msg, " run(nice=%d)", curr_sess->task->nice);
Willy Tarreauc6dcad62009-03-29 00:18:14 +01002733
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002734 chunk_printf(&msg, "\n");
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002735
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002736 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +01002737 /* let's try again later from this session. We add ourselves into
2738 * this session's users so that it can remove us upon termination.
2739 */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002740 LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users);
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002741 return 0;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002742 }
2743
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002744 next_sess:
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002745 s->data_ctx.sess.bref.ref = curr_sess->list.n;
2746 }
Willy Tarreau66dc20a2010-03-05 17:53:32 +01002747
2748 if (s->data_ctx.sess.target) {
2749 /* specified session not found */
2750 if (s->data_ctx.sess.section > 0)
2751 chunk_printf(&msg, " *** session terminated while we were watching it ***\n");
2752 else
2753 chunk_printf(&msg, "Session not found.\n");
2754
2755 if (buffer_feed_chunk(rep, &msg) >= 0)
2756 return 0;
2757
2758 s->data_ctx.sess.target = NULL;
2759 s->data_ctx.sess.uid = 0;
2760 return 1;
2761 }
2762
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002763 s->data_state = DATA_ST_FIN;
2764 /* fall through */
2765
2766 default:
2767 s->data_state = DATA_ST_FIN;
Willy Tarreau7e72a8f2009-10-03 23:55:14 +02002768 return 1;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002769 }
2770}
2771
Willy Tarreaud426a182010-03-05 14:58:26 +01002772/* print a line of text buffer (limited to 70 bytes) to <out>. The format is :
Willy Tarreau74808cb2009-03-04 15:53:18 +01002773 * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n>
2774 * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are
2775 * encoded in C format. Other non-printable chars are encoded "\xHH". Original
2776 * lines are respected within the limit of 70 output chars. Lines that are
2777 * continuation of a previous truncated line begin with "+" instead of " "
2778 * after the offset. The new pointer is returned.
2779 */
Willy Tarreaud426a182010-03-05 14:58:26 +01002780static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len,
2781 int *line, int ptr)
Willy Tarreau74808cb2009-03-04 15:53:18 +01002782{
2783 int end;
2784 unsigned char c;
2785
2786 end = out->len + 80;
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002787 if (end > out->size)
Willy Tarreau74808cb2009-03-04 15:53:18 +01002788 return ptr;
2789
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002790 chunk_printf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+');
Willy Tarreau74808cb2009-03-04 15:53:18 +01002791
Willy Tarreaud426a182010-03-05 14:58:26 +01002792 while (ptr < len && ptr < bsize) {
2793 c = buf[ptr];
Willy Tarreau787bbd92009-03-12 08:18:33 +01002794 if (isprint(c) && isascii(c) && c != '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002795 if (out->len > end - 2)
2796 break;
2797 out->str[out->len++] = c;
Willy Tarreau787bbd92009-03-12 08:18:33 +01002798 } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002799 if (out->len > end - 3)
2800 break;
2801 out->str[out->len++] = '\\';
2802 switch (c) {
2803 case '\t': c = 't'; break;
2804 case '\n': c = 'n'; break;
2805 case '\r': c = 'r'; break;
2806 case '\e': c = 'e'; break;
Willy Tarreau787bbd92009-03-12 08:18:33 +01002807 case '\\': c = '\\'; break;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002808 }
2809 out->str[out->len++] = c;
2810 } else {
2811 if (out->len > end - 5)
2812 break;
2813 out->str[out->len++] = '\\';
2814 out->str[out->len++] = 'x';
2815 out->str[out->len++] = hextab[(c >> 4) & 0xF];
2816 out->str[out->len++] = hextab[c & 0xF];
2817 }
Willy Tarreaud426a182010-03-05 14:58:26 +01002818 if (buf[ptr++] == '\n') {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002819 /* we had a line break, let's return now */
2820 out->str[out->len++] = '\n';
2821 *line = ptr;
2822 return ptr;
2823 }
2824 }
2825 /* we have an incomplete line, we return it as-is */
2826 out->str[out->len++] = '\n';
2827 return ptr;
2828}
2829
2830/* This function is called to send output to the response buffer.
2831 * It dumps the errors logged in proxies onto the output buffer <rep>.
2832 * Expects to be called with client socket shut down on input.
2833 * s->data_ctx must have been zeroed first, and the flags properly set.
Willy Tarreau61b34732009-10-03 23:49:35 +02002834 * It returns 0 as long as it does not complete, non-zero upon completion.
Willy Tarreau74808cb2009-03-04 15:53:18 +01002835 */
Willy Tarreau61b34732009-10-03 23:49:35 +02002836int stats_dump_errors_to_buffer(struct session *s, struct buffer *rep)
Willy Tarreau74808cb2009-03-04 15:53:18 +01002837{
2838 extern const char *monthname[12];
2839 struct chunk msg;
2840
Willy Tarreau61b34732009-10-03 23:49:35 +02002841 if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW)))
2842 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002843
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002844 chunk_init(&msg, trash, sizeof(trash));
Willy Tarreau74808cb2009-03-04 15:53:18 +01002845
2846 if (!s->data_ctx.errors.px) {
2847 /* the function had not been called yet, let's prepare the
2848 * buffer for a response.
2849 */
Willy Tarreau74808cb2009-03-04 15:53:18 +01002850 s->data_ctx.errors.px = proxy;
2851 s->data_ctx.errors.buf = 0;
2852 s->data_ctx.errors.bol = 0;
2853 s->data_ctx.errors.ptr = -1;
2854 }
2855
2856 /* we have two inner loops here, one for the proxy, the other one for
2857 * the buffer.
2858 */
2859 while (s->data_ctx.errors.px) {
2860 struct error_snapshot *es;
2861
2862 if (s->data_ctx.errors.buf == 0)
2863 es = &s->data_ctx.errors.px->invalid_req;
2864 else
2865 es = &s->data_ctx.errors.px->invalid_rep;
2866
2867 if (!es->when.tv_sec)
2868 goto next;
2869
2870 if (s->data_ctx.errors.iid >= 0 &&
2871 s->data_ctx.errors.px->uuid != s->data_ctx.errors.iid &&
2872 es->oe->uuid != s->data_ctx.errors.iid)
2873 goto next;
2874
2875 if (s->data_ctx.errors.ptr < 0) {
2876 /* just print headers now */
2877
2878 char pn[INET6_ADDRSTRLEN];
2879 struct tm tm;
2880
2881 get_localtime(es->when.tv_sec, &tm);
Willy Tarreau8811f8e2010-03-05 17:42:58 +01002882 chunk_printf(&msg, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
Willy Tarreau74808cb2009-03-04 15:53:18 +01002883 tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
Willy Tarreau1772ece2009-04-03 14:49:12 +02002884 tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
Willy Tarreau74808cb2009-03-04 15:53:18 +01002885
2886
2887 if (es->src.ss_family == AF_INET)
2888 inet_ntop(AF_INET,
2889 (const void *)&((struct sockaddr_in *)&es->src)->sin_addr,
2890 pn, sizeof(pn));
2891 else
2892 inet_ntop(AF_INET6,
2893 (const void *)&((struct sockaddr_in6 *)(&es->src))->sin6_addr,
2894 pn, sizeof(pn));
2895
2896 switch (s->data_ctx.errors.buf) {
2897 case 0:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002898 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01002899 " frontend %s (#%d): invalid request\n"
2900 " src %s, session #%d, backend %s (#%d), server %s (#%d)\n"
Willy Tarreau8811f8e2010-03-05 17:42:58 +01002901 " request length %d bytes, error at position %d:\n \n",
Willy Tarreau74808cb2009-03-04 15:53:18 +01002902 s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid,
Willy Tarreau3fd6cec2010-03-25 06:45:07 +01002903 pn, es->sid, (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>",
2904 (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1,
Willy Tarreau74808cb2009-03-04 15:53:18 +01002905 es->srv ? es->srv->id : "<NONE>",
2906 es->srv ? es->srv->puid : -1,
2907 es->len, es->pos);
2908 break;
2909 case 1:
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002910 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01002911 " backend %s (#%d) : invalid response\n"
2912 " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n"
Willy Tarreau8811f8e2010-03-05 17:42:58 +01002913 " response length %d bytes, error at position %d:\n \n",
Willy Tarreau74808cb2009-03-04 15:53:18 +01002914 s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid,
2915 pn, es->sid, es->oe->id, es->oe->uuid,
2916 es->srv ? es->srv->id : "<NONE>",
2917 es->srv ? es->srv->puid : -1,
2918 es->len, es->pos);
2919 break;
2920 }
2921
Willy Tarreau61b34732009-10-03 23:49:35 +02002922 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002923 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02002924 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002925 }
2926 s->data_ctx.errors.ptr = 0;
2927 s->data_ctx.errors.sid = es->sid;
2928 }
2929
2930 if (s->data_ctx.errors.sid != es->sid) {
2931 /* the snapshot changed while we were dumping it */
Krzysztof Piotr Oledzki78abe612009-09-27 13:23:20 +02002932 chunk_printf(&msg,
Willy Tarreau74808cb2009-03-04 15:53:18 +01002933 " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
Willy Tarreau61b34732009-10-03 23:49:35 +02002934 if (buffer_feed_chunk(rep, &msg) >= 0)
2935 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002936 goto next;
2937 }
2938
2939 /* OK, ptr >= 0, so we have to dump the current line */
Willy Tarreau61b34732009-10-03 23:49:35 +02002940 while (s->data_ctx.errors.ptr < es->len && s->data_ctx.errors.ptr < sizeof(es->buf)) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002941 int newptr;
2942 int newline;
2943
2944 newline = s->data_ctx.errors.bol;
Willy Tarreaud426a182010-03-05 14:58:26 +01002945 newptr = dump_text_line(&msg, es->buf, sizeof(es->buf), es->len, &newline, s->data_ctx.errors.ptr);
Willy Tarreau74808cb2009-03-04 15:53:18 +01002946 if (newptr == s->data_ctx.errors.ptr)
Willy Tarreau61b34732009-10-03 23:49:35 +02002947 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002948
Willy Tarreau61b34732009-10-03 23:49:35 +02002949 if (buffer_feed_chunk(rep, &msg) >= 0) {
Willy Tarreau74808cb2009-03-04 15:53:18 +01002950 /* Socket buffer full. Let's try again later from the same point */
Willy Tarreau61b34732009-10-03 23:49:35 +02002951 return 0;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002952 }
2953 s->data_ctx.errors.ptr = newptr;
2954 s->data_ctx.errors.bol = newline;
2955 };
2956 next:
2957 s->data_ctx.errors.bol = 0;
2958 s->data_ctx.errors.ptr = -1;
2959 s->data_ctx.errors.buf++;
2960 if (s->data_ctx.errors.buf > 1) {
2961 s->data_ctx.errors.buf = 0;
2962 s->data_ctx.errors.px = s->data_ctx.errors.px->next;
2963 }
2964 }
2965
2966 /* dump complete */
Willy Tarreau61b34732009-10-03 23:49:35 +02002967 return 1;
Willy Tarreau74808cb2009-03-04 15:53:18 +01002968}
2969
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01002970
Willy Tarreau10522fd2008-07-09 20:12:41 +02002971static struct cfg_kw_list cfg_kws = {{ },{
2972 { CFG_GLOBAL, "stats", stats_parse_global },
2973 { 0, NULL, NULL },
2974}};
2975
2976__attribute__((constructor))
2977static void __dumpstats_module_init(void)
2978{
2979 cfg_register_keywords(&cfg_kws);
2980}
2981
Willy Tarreau91861262007-10-17 17:06:05 +02002982/*
2983 * Local variables:
2984 * c-indent-level: 8
2985 * c-basic-offset: 8
2986 * End:
2987 */