Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Functions dedicated to statistics output |
| 3 | * |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 4 | * Copyright 2000-2009 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <ctype.h> |
| 14 | #include <errno.h> |
| 15 | #include <fcntl.h> |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 19 | #include <pwd.h> |
| 20 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 21 | |
| 22 | #include <sys/socket.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/types.h> |
| 25 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 26 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 27 | #include <common/compat.h> |
| 28 | #include <common/config.h> |
| 29 | #include <common/debug.h> |
| 30 | #include <common/memory.h> |
| 31 | #include <common/mini-clist.h> |
| 32 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 33 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 34 | #include <common/time.h> |
| 35 | #include <common/uri_auth.h> |
| 36 | #include <common/version.h> |
| 37 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 38 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | |
| 40 | #include <proto/backend.h> |
| 41 | #include <proto/buffers.h> |
| 42 | #include <proto/dumpstats.h> |
| 43 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 44 | #include <proto/freq_ctr.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 45 | #include <proto/pipe.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 46 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 47 | #include <proto/proxy.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 48 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 49 | #include <proto/server.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 50 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 51 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 52 | |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 53 | const char stats_sock_usage_msg[] = |
| 54 | "Unknown command. Please enter one of the following commands only :\n" |
| 55 | " show info : report information about the running process\n" |
| 56 | " show stat : report counters for each proxy and server\n" |
| 57 | " show errors : report last request and response errors for each proxy\n" |
| 58 | " show sess : report the list of current sessions\n" |
| 59 | "\n"; |
| 60 | |
| 61 | const struct chunk stats_sock_usage = { |
| 62 | .str = (char *)&stats_sock_usage_msg, |
| 63 | .len = sizeof(stats_sock_usage_msg)-1 |
| 64 | }; |
| 65 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 66 | /* This function parses a "stats" statement in the "global" section. It returns |
| 67 | * -1 if there is any error, otherwise zero. If it returns -1, it may write an |
| 68 | * error message into ther <err> buffer, for at most <errlen> bytes, trailing |
| 69 | * zero included. The trailing '\n' must not be written. The function must be |
| 70 | * called with <args> pointing to the first word after "stats". |
| 71 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 72 | static int stats_parse_global(char **args, int section_type, struct proxy *curpx, |
| 73 | struct proxy *defpx, char *err, int errlen) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 74 | { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 75 | args++; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 76 | if (!strcmp(args[0], "socket")) { |
| 77 | struct sockaddr_un su; |
| 78 | int cur_arg; |
| 79 | |
| 80 | if (*args[1] == 0) { |
| 81 | snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket"); |
| 82 | return -1; |
| 83 | } |
| 84 | |
| 85 | if (global.stats_sock.state != LI_NEW) { |
| 86 | snprintf(err, errlen, "'stats socket' already specified in global section"); |
| 87 | return -1; |
| 88 | } |
| 89 | |
| 90 | su.sun_family = AF_UNIX; |
| 91 | strncpy(su.sun_path, args[1], sizeof(su.sun_path)); |
| 92 | su.sun_path[sizeof(su.sun_path) - 1] = 0; |
| 93 | memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit |
| 94 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 95 | if (!global.stats_fe) { |
| 96 | if ((global.stats_fe = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 97 | snprintf(err, errlen, "out of memory"); |
| 98 | return -1; |
| 99 | } |
| 100 | |
| 101 | LIST_INIT(&global.stats_fe->pendconns); |
| 102 | LIST_INIT(&global.stats_fe->acl); |
| 103 | LIST_INIT(&global.stats_fe->block_cond); |
| 104 | LIST_INIT(&global.stats_fe->redirect_rules); |
| 105 | LIST_INIT(&global.stats_fe->mon_fail_cond); |
| 106 | LIST_INIT(&global.stats_fe->switching_rules); |
| 107 | LIST_INIT(&global.stats_fe->tcp_req.inspect_rules); |
| 108 | |
| 109 | /* Timeouts are defined as -1, so we cannot use the zeroed area |
| 110 | * as a default value. |
| 111 | */ |
| 112 | proxy_reset_timeouts(global.stats_fe); |
| 113 | |
| 114 | global.stats_fe->last_change = now.tv_sec; |
| 115 | global.stats_fe->id = strdup("GLOBAL"); |
| 116 | global.stats_fe->cap = PR_CAP_FE; |
| 117 | } |
| 118 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 119 | global.stats_sock.state = LI_INIT; |
Willy Tarreau | 6fb42e0 | 2007-10-28 17:02:33 +0100 | [diff] [blame] | 120 | global.stats_sock.options = LI_O_NONE; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 121 | global.stats_sock.accept = uxst_event_accept; |
Willy Tarreau | 104eb36 | 2009-08-16 18:51:29 +0200 | [diff] [blame] | 122 | global.stats_sock.handler = process_session; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 123 | global.stats_sock.analysers = AN_REQ_STATS_SOCK; |
Willy Tarreau | 2c9f5b1 | 2009-08-16 19:12:36 +0200 | [diff] [blame^] | 124 | global.stats_sock.nice = -64; /* we want to boost priority for local stats */ |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 125 | global.stats_sock.private = global.stats_fe; /* must point to the frontend */ |
| 126 | |
| 127 | global.stats_fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
| 128 | global.stats_sock.timeout = &global.stats_fe->timeout.client; |
| 129 | |
| 130 | global.stats_sock.next = global.stats_fe->listen; |
| 131 | global.stats_fe->listen = &global.stats_sock; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 132 | |
| 133 | cur_arg = 2; |
| 134 | while (*args[cur_arg]) { |
| 135 | if (!strcmp(args[cur_arg], "uid")) { |
| 136 | global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]); |
| 137 | cur_arg += 2; |
| 138 | } |
| 139 | else if (!strcmp(args[cur_arg], "gid")) { |
| 140 | global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]); |
| 141 | cur_arg += 2; |
| 142 | } |
| 143 | else if (!strcmp(args[cur_arg], "mode")) { |
| 144 | global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 145 | cur_arg += 2; |
| 146 | } |
| 147 | else if (!strcmp(args[cur_arg], "user")) { |
| 148 | struct passwd *user; |
| 149 | user = getpwnam(args[cur_arg + 1]); |
| 150 | if (!user) { |
| 151 | snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')", |
| 152 | args[cur_arg + 1]); |
| 153 | return -1; |
| 154 | } |
| 155 | global.stats_sock.perm.ux.uid = user->pw_uid; |
| 156 | cur_arg += 2; |
| 157 | } |
| 158 | else if (!strcmp(args[cur_arg], "group")) { |
| 159 | struct group *group; |
| 160 | group = getgrnam(args[cur_arg + 1]); |
| 161 | if (!group) { |
| 162 | snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')", |
| 163 | args[cur_arg + 1]); |
| 164 | return -1; |
| 165 | } |
| 166 | global.stats_sock.perm.ux.gid = group->gr_gid; |
| 167 | cur_arg += 2; |
| 168 | } |
| 169 | else { |
| 170 | snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', and 'mode'"); |
| 171 | return -1; |
| 172 | } |
| 173 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 174 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 175 | uxst_add_listener(&global.stats_sock); |
| 176 | global.maxsock++; |
| 177 | } |
| 178 | else if (!strcmp(args[0], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 179 | unsigned timeout; |
| 180 | const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS); |
| 181 | |
| 182 | if (res) { |
| 183 | snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res); |
| 184 | return -1; |
| 185 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 186 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 187 | if (!timeout) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 188 | snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'"); |
| 189 | return -1; |
| 190 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 191 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 192 | } |
| 193 | else if (!strcmp(args[0], "maxconn")) { |
| 194 | int maxconn = atol(args[1]); |
| 195 | |
| 196 | if (maxconn <= 0) { |
| 197 | snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'"); |
| 198 | return -1; |
| 199 | } |
| 200 | global.maxsock -= global.stats_sock.maxconn; |
| 201 | global.stats_sock.maxconn = maxconn; |
| 202 | global.maxsock += global.stats_sock.maxconn; |
| 203 | } |
| 204 | else { |
| 205 | snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section"); |
| 206 | return -1; |
| 207 | } |
| 208 | return 0; |
| 209 | } |
| 210 | |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 211 | int print_csv_header(struct chunk *msg, int size) |
| 212 | { |
| 213 | return chunk_printf(msg, size, |
| 214 | "# pxname,svname," |
| 215 | "qcur,qmax," |
| 216 | "scur,smax,slim,stot," |
| 217 | "bin,bout," |
| 218 | "dreq,dresp," |
| 219 | "ereq,econ,eresp," |
| 220 | "wretr,wredis," |
| 221 | "status,weight,act,bck," |
| 222 | "chkfail,chkdown,lastchg,downtime,qlimit," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 223 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 224 | "rate,rate_lim,rate_max," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 225 | "\n"); |
| 226 | } |
| 227 | |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 228 | /* Parses the request line in <cmd> and possibly starts dumping stats on |
| 229 | * s->rep with the hijack bit set. Returns 1 if OK, 0 in case of any error. |
| 230 | * The line is modified after parsing. |
| 231 | */ |
| 232 | int stats_sock_parse_request(struct session *s, char *line) |
| 233 | { |
| 234 | char *args[MAX_STATS_ARGS + 1]; |
| 235 | int arg; |
| 236 | |
| 237 | while (isspace((unsigned char)*line)) |
| 238 | line++; |
| 239 | |
| 240 | arg = 0; |
| 241 | args[arg] = line; |
| 242 | |
| 243 | while (*line && arg < MAX_STATS_ARGS) { |
| 244 | if (isspace((unsigned char)*line)) { |
| 245 | *line++ = '\0'; |
| 246 | |
| 247 | while (isspace((unsigned char)*line)) |
| 248 | line++; |
| 249 | |
| 250 | args[++arg] = line; |
| 251 | continue; |
| 252 | } |
| 253 | |
| 254 | line++; |
| 255 | } |
| 256 | |
| 257 | while (++arg <= MAX_STATS_ARGS) |
| 258 | args[arg] = line; |
| 259 | |
| 260 | if (strcmp(args[0], "show") == 0) { |
| 261 | if (strcmp(args[1], "stat") == 0) { |
| 262 | if (*args[2] && *args[3] && *args[4]) { |
| 263 | s->data_ctx.stats.flags |= STAT_BOUND; |
| 264 | s->data_ctx.stats.iid = atoi(args[2]); |
| 265 | s->data_ctx.stats.type = atoi(args[3]); |
| 266 | s->data_ctx.stats.sid = atoi(args[4]); |
| 267 | } |
| 268 | |
| 269 | s->data_ctx.stats.flags |= STAT_SHOW_STAT; |
| 270 | s->data_ctx.stats.flags |= STAT_FMT_CSV; |
| 271 | s->ana_state = STATS_ST_REP; |
| 272 | buffer_install_hijacker(s, s->rep, stats_dump_raw_to_buffer); |
| 273 | } |
| 274 | else if (strcmp(args[1], "info") == 0) { |
| 275 | s->data_ctx.stats.flags |= STAT_SHOW_INFO; |
| 276 | s->data_ctx.stats.flags |= STAT_FMT_CSV; |
| 277 | s->ana_state = STATS_ST_REP; |
| 278 | buffer_install_hijacker(s, s->rep, stats_dump_raw_to_buffer); |
| 279 | } |
| 280 | else if (strcmp(args[1], "sess") == 0) { |
| 281 | s->ana_state = STATS_ST_REP; |
| 282 | buffer_install_hijacker(s, s->rep, stats_dump_sess_to_buffer); |
| 283 | } |
| 284 | else if (strcmp(args[1], "errors") == 0) { |
| 285 | if (*args[2]) |
| 286 | s->data_ctx.errors.iid = atoi(args[2]); |
| 287 | else |
| 288 | s->data_ctx.errors.iid = -1; |
| 289 | s->data_ctx.errors.px = NULL; |
| 290 | s->ana_state = STATS_ST_REP; |
| 291 | buffer_install_hijacker(s, s->rep, stats_dump_errors_to_buffer); |
| 292 | } |
| 293 | else { /* neither "stat" nor "info" nor "sess" */ |
| 294 | return 0; |
| 295 | } |
| 296 | } |
| 297 | else { /* not "show" */ |
| 298 | return 0; |
| 299 | } |
| 300 | return 1; |
| 301 | } |
| 302 | |
| 303 | /* Processes the stats interpreter on the statistics socket. |
| 304 | * In order to ease the transition, we simply simulate the server status |
| 305 | * for now. It only knows states STATS_ST_INIT, STATS_ST_REQ, STATS_ST_REP, and |
| 306 | * STATS_ST_CLOSE. It removes its analyser bit from req->analysers once done. |
| 307 | * It always returns 0. |
| 308 | */ |
| 309 | int stats_sock_req_analyser(struct session *s, struct buffer *req, int an_bit) |
| 310 | { |
| 311 | char *line, *p; |
| 312 | |
| 313 | switch (s->ana_state) { |
| 314 | case STATS_ST_INIT: |
| 315 | /* Stats output not initialized yet */ |
| 316 | memset(&s->data_ctx.stats, 0, sizeof(s->data_ctx.stats)); |
| 317 | s->data_source = DATA_SRC_STATS; |
| 318 | s->ana_state = STATS_ST_REQ; |
| 319 | buffer_write_dis(s->req); |
| 320 | /* fall through */ |
| 321 | |
| 322 | case STATS_ST_REQ: |
| 323 | /* Now, stats are initialized, hijack is not set, and |
| 324 | * we are waiting for a complete request line. |
| 325 | */ |
| 326 | |
| 327 | line = s->req->data; |
| 328 | p = memchr(line, '\n', s->req->l); |
| 329 | |
| 330 | if (p) { |
| 331 | *p = '\0'; |
| 332 | if (!stats_sock_parse_request(s, line)) { |
| 333 | /* invalid request */ |
| 334 | stream_int_retnclose(s->req->prod, &stats_sock_usage); |
| 335 | s->ana_state = 0; |
| 336 | req->analysers = 0; |
| 337 | return 0; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /* processing a valid or incomplete request */ |
| 342 | if ((req->flags & BF_FULL) || /* invalid request */ |
| 343 | (req->flags & BF_READ_ERROR) || /* input error */ |
| 344 | (req->flags & BF_READ_TIMEOUT) || /* read timeout */ |
| 345 | tick_is_expired(req->analyse_exp, now_ms) || /* request timeout */ |
| 346 | (req->flags & BF_SHUTR)) { /* input closed */ |
| 347 | buffer_shutw_now(s->rep); |
| 348 | s->ana_state = 0; |
| 349 | req->analysers = 0; |
| 350 | return 0; |
| 351 | } |
| 352 | /* don't forward nor abort */ |
| 353 | req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */ |
| 354 | return 0; |
| 355 | |
| 356 | case STATS_ST_REP: |
| 357 | /* do nothing while response is being processed */ |
| 358 | return 0; |
| 359 | |
| 360 | case STATS_ST_CLOSE: |
| 361 | /* end of dump */ |
| 362 | s->req->analysers &= ~an_bit; |
| 363 | s->ana_state = 0; |
| 364 | break; |
| 365 | } |
| 366 | return 0; |
| 367 | } |
| 368 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 369 | /* |
| 370 | * Produces statistics data for the session <s>. Expects to be called with |
Willy Tarreau | 1ae3a05 | 2008-08-16 10:56:30 +0200 | [diff] [blame] | 371 | * client socket shut down on input. It *may* make use of informations from |
| 372 | * <uri>. s->data_ctx must have been zeroed first, and the flags properly set. |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 373 | * It returns 0 if it had to stop writing data and an I/O is needed, 1 if the |
| 374 | * dump is finished and the session must be closed, or -1 in case of any error. |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 375 | * It automatically clears the HIJACK bit from the response buffer. |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 376 | */ |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 377 | int stats_dump_raw(struct session *s, struct buffer *rep, struct uri_auth *uri) |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 378 | { |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 379 | struct proxy *px; |
| 380 | struct chunk msg; |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 381 | unsigned int up; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 382 | |
| 383 | msg.len = 0; |
| 384 | msg.str = trash; |
| 385 | |
| 386 | switch (s->data_state) { |
| 387 | case DATA_ST_INIT: |
| 388 | /* the function had not been called yet, let's prepare the |
| 389 | * buffer for a response. |
| 390 | */ |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 391 | stream_int_retnclose(rep->cons, &msg); |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 392 | s->data_state = DATA_ST_HEAD; |
| 393 | /* fall through */ |
| 394 | |
| 395 | case DATA_ST_HEAD: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 396 | if (s->data_ctx.stats.flags & STAT_SHOW_STAT) { |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 397 | print_csv_header(&msg, sizeof(trash)); |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 398 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 399 | return 0; |
| 400 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 401 | |
| 402 | s->data_state = DATA_ST_INFO; |
| 403 | /* fall through */ |
| 404 | |
| 405 | case DATA_ST_INFO: |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 406 | up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 407 | if (s->data_ctx.stats.flags & STAT_SHOW_INFO) { |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 408 | chunk_printf(&msg, sizeof(trash), |
| 409 | "Name: " PRODUCT_NAME "\n" |
| 410 | "Version: " HAPROXY_VERSION "\n" |
| 411 | "Release_date: " HAPROXY_DATE "\n" |
| 412 | "Nbproc: %d\n" |
| 413 | "Process_num: %d\n" |
| 414 | "Pid: %d\n" |
| 415 | "Uptime: %dd %dh%02dm%02ds\n" |
| 416 | "Uptime_sec: %d\n" |
| 417 | "Memmax_MB: %d\n" |
| 418 | "Ulimit-n: %d\n" |
| 419 | "Maxsock: %d\n" |
| 420 | "Maxconn: %d\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 421 | "Maxpipes: %d\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 422 | "CurrConns: %d\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 423 | "PipesUsed: %d\n" |
| 424 | "PipesFree: %d\n" |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 425 | "Tasks: %d\n" |
| 426 | "Run_queue: %d\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 427 | "", |
| 428 | global.nbproc, |
| 429 | relative_pid, |
| 430 | pid, |
| 431 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 432 | up, |
| 433 | global.rlimit_memmax, |
| 434 | global.rlimit_nofile, |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 435 | global.maxsock, global.maxconn, global.maxpipes, |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 436 | actconn, pipes_used, pipes_free, |
| 437 | nb_tasks_cur, run_queue_cur |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 438 | ); |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 439 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 440 | return 0; |
| 441 | } |
| 442 | |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 443 | s->data_ctx.stats.px = proxy; |
| 444 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 445 | |
| 446 | s->data_ctx.stats.sv = NULL; |
| 447 | s->data_ctx.stats.sv_st = 0; |
| 448 | |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 449 | s->data_state = DATA_ST_LIST; |
| 450 | /* fall through */ |
| 451 | |
| 452 | case DATA_ST_LIST: |
| 453 | /* dump proxies */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 454 | if (s->data_ctx.stats.flags & STAT_SHOW_STAT) { |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 455 | while (s->data_ctx.stats.px) { |
| 456 | px = s->data_ctx.stats.px; |
| 457 | /* skip the disabled proxies and non-networked ones */ |
| 458 | if (px->state != PR_STSTOPPED && |
| 459 | (px->cap & (PR_CAP_FE | PR_CAP_BE))) |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 460 | if (stats_dump_proxy(s, px, NULL) == 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 461 | return 0; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 462 | |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 463 | s->data_ctx.stats.px = px->next; |
| 464 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 465 | } |
| 466 | /* here, we just have reached the last proxy */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 467 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 468 | |
| 469 | s->data_state = DATA_ST_END; |
| 470 | /* fall through */ |
| 471 | |
| 472 | case DATA_ST_END: |
| 473 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 474 | /* fall through */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 475 | |
| 476 | case DATA_ST_FIN: |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 477 | buffer_stop_hijack(rep); |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 478 | return 1; |
| 479 | |
| 480 | default: |
| 481 | /* unknown state ! */ |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 482 | buffer_stop_hijack(rep); |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 483 | return -1; |
| 484 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | |
| 488 | /* This function is called to send output to the response buffer. It simply |
| 489 | * calls stats_dump_raw(), and releases the buffer's hijack bit when the dump |
Willy Tarreau | 01bf867 | 2008-12-07 18:03:29 +0100 | [diff] [blame] | 490 | * is finished. |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 491 | */ |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 492 | void stats_dump_raw_to_buffer(struct session *s, struct buffer *rep) |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 493 | { |
| 494 | if (s->ana_state != STATS_ST_REP) |
Willy Tarreau | 01bf867 | 2008-12-07 18:03:29 +0100 | [diff] [blame] | 495 | return; |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 496 | |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 497 | if (stats_dump_raw(s, rep, NULL) != 0) |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 498 | s->ana_state = STATS_ST_CLOSE; |
Willy Tarreau | 01bf867 | 2008-12-07 18:03:29 +0100 | [diff] [blame] | 499 | return; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | |
| 503 | /* |
| 504 | * Produces statistics data for the session <s>. Expects to be called with |
Willy Tarreau | 1ae3a05 | 2008-08-16 10:56:30 +0200 | [diff] [blame] | 505 | * client socket shut down on input. It stops by itself by unsetting the |
Willy Tarreau | 72b179a | 2008-08-28 16:01:32 +0200 | [diff] [blame] | 506 | * BF_HIJACK flag from the buffer, which it uses to keep on being called |
Willy Tarreau | 1ae3a05 | 2008-08-16 10:56:30 +0200 | [diff] [blame] | 507 | * when there is free space in the buffer, of simply by letting an empty buffer |
| 508 | * upon return.s->data_ctx must have been zeroed before the first call, and the |
| 509 | * flags set. It returns 0 if it had to stop writing data and an I/O is needed, |
| 510 | * 1 if the dump is finished and the session must be closed, or -1 in case of |
| 511 | * any error. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 512 | */ |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 513 | int stats_dump_http(struct session *s, struct buffer *rep, struct uri_auth *uri) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 514 | { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 515 | struct proxy *px; |
| 516 | struct chunk msg; |
| 517 | unsigned int up; |
| 518 | |
| 519 | msg.len = 0; |
| 520 | msg.str = trash; |
| 521 | |
| 522 | switch (s->data_state) { |
| 523 | case DATA_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 524 | chunk_printf(&msg, sizeof(trash), |
| 525 | "HTTP/1.0 200 OK\r\n" |
| 526 | "Cache-Control: no-cache\r\n" |
| 527 | "Connection: close\r\n" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 528 | "Content-Type: %s\r\n", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 529 | (s->data_ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 530 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 531 | if (uri->refresh > 0 && !(s->data_ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 532 | chunk_printf(&msg, sizeof(trash), "Refresh: %d\r\n", |
| 533 | uri->refresh); |
| 534 | |
| 535 | chunk_printf(&msg, sizeof(trash), "\r\n"); |
| 536 | |
| 537 | s->txn.status = 200; |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 538 | stream_int_retnclose(rep->cons, &msg); // send the start of the response. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 539 | msg.len = 0; |
| 540 | |
| 541 | if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is |
| 542 | s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy |
| 543 | if (!(s->flags & SN_FINST_MASK)) |
| 544 | s->flags |= SN_FINST_R; |
| 545 | |
| 546 | if (s->txn.meth == HTTP_METH_HEAD) { |
| 547 | /* that's all we return in case of HEAD request */ |
| 548 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 72b179a | 2008-08-28 16:01:32 +0200 | [diff] [blame] | 549 | buffer_stop_hijack(rep); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 550 | return 1; |
| 551 | } |
| 552 | |
| 553 | s->data_state = DATA_ST_HEAD; /* let's start producing data */ |
| 554 | /* fall through */ |
| 555 | |
| 556 | case DATA_ST_HEAD: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 557 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 558 | /* WARNING! This must fit in the first buffer !!! */ |
| 559 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 560 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 561 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 562 | "<style type=\"text/css\"><!--\n" |
| 563 | "body {" |
Willy Tarreau | a94f2d2 | 2009-05-10 20:08:10 +0200 | [diff] [blame] | 564 | " font-family: arial, helvetica, sans-serif;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 565 | " font-size: 12px;" |
| 566 | " font-weight: normal;" |
| 567 | " color: black;" |
| 568 | " background: white;" |
| 569 | "}\n" |
| 570 | "th,td {" |
Willy Tarreau | a94f2d2 | 2009-05-10 20:08:10 +0200 | [diff] [blame] | 571 | " font-size: 10px;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 572 | " align: center;" |
| 573 | "}\n" |
| 574 | "h1 {" |
Willy Tarreau | da6721b | 2009-07-15 10:07:05 +0200 | [diff] [blame] | 575 | " font-size: x-large;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 576 | " margin-bottom: 0.5em;" |
| 577 | "}\n" |
| 578 | "h2 {" |
| 579 | " font-family: helvetica, arial;" |
| 580 | " font-size: x-large;" |
| 581 | " font-weight: bold;" |
| 582 | " font-style: italic;" |
| 583 | " color: #6020a0;" |
| 584 | " margin-top: 0em;" |
| 585 | " margin-bottom: 0em;" |
| 586 | "}\n" |
| 587 | "h3 {" |
| 588 | " font-family: helvetica, arial;" |
| 589 | " font-size: 16px;" |
| 590 | " font-weight: bold;" |
| 591 | " color: #b00040;" |
| 592 | " background: #e8e8d0;" |
| 593 | " margin-top: 0em;" |
| 594 | " margin-bottom: 0em;" |
| 595 | "}\n" |
| 596 | "li {" |
| 597 | " margin-top: 0.25em;" |
| 598 | " margin-right: 2em;" |
| 599 | "}\n" |
| 600 | ".hr {margin-top: 0.25em;" |
| 601 | " border-color: black;" |
| 602 | " border-bottom-style: solid;" |
| 603 | "}\n" |
| 604 | ".pxname {background: #b00040;color: #ffff40;font-weight: bold;}\n" |
| 605 | ".titre {background: #20D0D0;color: #000000;font-weight: bold;}\n" |
| 606 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 607 | ".frontend {background: #e8e8d0;}\n" |
| 608 | ".backend {background: #e8e8d0;}\n" |
| 609 | ".active0 {background: #ff9090;}\n" |
| 610 | ".active1 {background: #ffd020;}\n" |
| 611 | ".active2 {background: #ffffa0;}\n" |
| 612 | ".active3 {background: #c0ffc0;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 613 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 614 | ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */ |
| 615 | ".active6 {background: #e0e0e0;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 616 | ".backup0 {background: #ff9090;}\n" |
| 617 | ".backup1 {background: #ff80ff;}\n" |
| 618 | ".backup2 {background: #c060ff;}\n" |
| 619 | ".backup3 {background: #b0d0ff;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 620 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 621 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 622 | ".backup6 {background: #e0e0e0;}\n" |
Willy Tarreau | da6721b | 2009-07-15 10:07:05 +0200 | [diff] [blame] | 623 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 624 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 625 | "table.tbl td { border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray;}\n" |
| 626 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
Willy Tarreau | da6721b | 2009-07-15 10:07:05 +0200 | [diff] [blame] | 627 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 628 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 629 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 630 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
| 631 | "-->\n" |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 632 | "</style></head>\n", |
| 633 | uri->node_name ? " on " : "", |
| 634 | uri->node_name ? uri->node_name : "" |
| 635 | ); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 636 | } else { |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 637 | print_csv_header(&msg, sizeof(trash)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 638 | } |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 639 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 640 | return 0; |
| 641 | |
| 642 | s->data_state = DATA_ST_INFO; |
| 643 | /* fall through */ |
| 644 | |
| 645 | case DATA_ST_INFO: |
| 646 | up = (now.tv_sec - start_date.tv_sec); |
| 647 | |
| 648 | /* WARNING! this has to fit the first packet too. |
| 649 | * We are around 3.5 kB, add adding entries will |
| 650 | * become tricky if we want to support 4kB buffers ! |
| 651 | */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 652 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 653 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 654 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 655 | PRODUCT_NAME "%s</a></h1>\n" |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 656 | "<h2>Statistics Report for pid %d%s%s</h2>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 657 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 658 | "<h3>> General process information</h3>\n" |
| 659 | "<table border=0 cols=4><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 660 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 661 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 662 | "<b>system limits :</b> memmax = %s%s ; ulimit-n = %d<br>\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 663 | "<b>maxsock = </b> %d ; <b>maxconn = </b> %d ; <b>maxpipes = </b> %d<br>\n" |
| 664 | "current conns = %d ; current pipes = %d/%d<br>\n" |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 665 | "Running tasks : %d/%d<br>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 666 | "</td><td align=\"center\" nowrap>\n" |
| 667 | "<table class=\"lgd\"><tr>\n" |
| 668 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 669 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 670 | "</tr><tr>\n" |
| 671 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 672 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 673 | "</tr><tr>\n" |
| 674 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 675 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 676 | "</tr><tr>\n" |
| 677 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 678 | "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 679 | "</tr></table>\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 680 | "Note: UP with load-balancing disabled is reported as \"NOLB\"." |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 681 | "</td>" |
| 682 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 683 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 684 | "", |
| 685 | (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING), |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 686 | pid, uri->node_name ? " on " : "", uri->node_name ? uri->node_name : "", |
| 687 | pid, |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 688 | relative_pid, global.nbproc, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 689 | up / 86400, (up % 86400) / 3600, |
| 690 | (up % 3600) / 60, (up % 60), |
| 691 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 692 | global.rlimit_memmax ? " MB" : "", |
| 693 | global.rlimit_nofile, |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 694 | global.maxsock, global.maxconn, global.maxpipes, |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 695 | actconn, pipes_used, pipes_used+pipes_free, |
| 696 | run_queue_cur, nb_tasks_cur |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 697 | ); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 698 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 699 | if (s->data_ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 700 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 701 | "<li><a href=\"%s%s%s\">Show all servers</a><br>\n", |
| 702 | uri->uri_prefix, |
| 703 | "", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 704 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 705 | else |
| 706 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 707 | "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 708 | uri->uri_prefix, |
| 709 | ";up", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 710 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 711 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 712 | if (uri->refresh > 0) { |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 713 | if (s->data_ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 714 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 715 | "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n", |
| 716 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 717 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 718 | ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 719 | else |
| 720 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 721 | "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n", |
| 722 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 723 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 724 | ";norefresh"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 725 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 726 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 727 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 728 | "<li><a href=\"%s%s%s\">Refresh now</a><br>\n", |
| 729 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 730 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 731 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 732 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 733 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 734 | "<li><a href=\"%s;csv%s\">CSV export</a><br>\n", |
| 735 | uri->uri_prefix, |
| 736 | (uri->refresh > 0) ? ";norefresh" : ""); |
| 737 | |
| 738 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 739 | "</td>" |
| 740 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 741 | "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 742 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 743 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 744 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 745 | "</ul>" |
| 746 | "</td>" |
| 747 | "</tr></table>\n" |
| 748 | "" |
| 749 | ); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 750 | |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 751 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 752 | return 0; |
| 753 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 754 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 755 | s->data_ctx.stats.px = proxy; |
| 756 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 757 | s->data_state = DATA_ST_LIST; |
| 758 | /* fall through */ |
| 759 | |
| 760 | case DATA_ST_LIST: |
| 761 | /* dump proxies */ |
| 762 | while (s->data_ctx.stats.px) { |
| 763 | px = s->data_ctx.stats.px; |
| 764 | /* skip the disabled proxies and non-networked ones */ |
| 765 | if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE))) |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 766 | if (stats_dump_proxy(s, px, uri) == 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 767 | return 0; |
| 768 | |
| 769 | s->data_ctx.stats.px = px->next; |
| 770 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 771 | } |
| 772 | /* here, we just have reached the last proxy */ |
| 773 | |
| 774 | s->data_state = DATA_ST_END; |
| 775 | /* fall through */ |
| 776 | |
| 777 | case DATA_ST_END: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 778 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 779 | chunk_printf(&msg, sizeof(trash), "</body></html>\n"); |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 780 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 781 | return 0; |
| 782 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 783 | |
| 784 | s->data_state = DATA_ST_FIN; |
| 785 | /* fall through */ |
| 786 | |
| 787 | case DATA_ST_FIN: |
Willy Tarreau | 72b179a | 2008-08-28 16:01:32 +0200 | [diff] [blame] | 788 | buffer_stop_hijack(rep); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 789 | return 1; |
| 790 | |
| 791 | default: |
| 792 | /* unknown state ! */ |
Willy Tarreau | 72b179a | 2008-08-28 16:01:32 +0200 | [diff] [blame] | 793 | buffer_stop_hijack(rep); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 794 | return -1; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | |
| 799 | /* |
| 800 | * Dumps statistics for a proxy. |
| 801 | * Returns 0 if it had to stop dumping data because of lack of buffer space, |
| 802 | * ot non-zero if everything completed. |
| 803 | */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 804 | int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 805 | { |
| 806 | struct buffer *rep = s->rep; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 807 | struct server *sv, *svs; /* server and server-state, server-state=server or server->tracked */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 808 | struct chunk msg; |
| 809 | |
| 810 | msg.len = 0; |
| 811 | msg.str = trash; |
| 812 | |
| 813 | switch (s->data_ctx.stats.px_st) { |
| 814 | case DATA_ST_PX_INIT: |
| 815 | /* we are on a new proxy */ |
| 816 | |
| 817 | if (uri && uri->scope) { |
| 818 | /* we have a limited scope, we have to check the proxy name */ |
| 819 | struct stat_scope *scope; |
| 820 | int len; |
| 821 | |
| 822 | len = strlen(px->id); |
| 823 | scope = uri->scope; |
| 824 | |
| 825 | while (scope) { |
| 826 | /* match exact proxy name */ |
| 827 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 828 | break; |
| 829 | |
| 830 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 831 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 832 | break; |
| 833 | scope = scope->next; |
| 834 | } |
| 835 | |
| 836 | /* proxy name not found : don't dump anything */ |
| 837 | if (scope == NULL) |
| 838 | return 1; |
| 839 | } |
| 840 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 841 | if ((s->data_ctx.stats.flags & STAT_BOUND) && (s->data_ctx.stats.iid != -1) && |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 842 | (px->uuid != s->data_ctx.stats.iid)) |
| 843 | return 1; |
| 844 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 845 | s->data_ctx.stats.px_st = DATA_ST_PX_TH; |
| 846 | /* fall through */ |
| 847 | |
| 848 | case DATA_ST_PX_TH: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 849 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 850 | /* print a new table */ |
| 851 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 852 | "<table cols=\"29\" class=\"tbl\" width=\"100%%\">\n" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 853 | "<tr align=\"center\" class=\"titre\">" |
| 854 | "<th colspan=2 class=\"pxname\">%s</th>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 855 | "<th colspan=27 class=\"empty\"></th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 856 | "</tr>\n" |
| 857 | "<tr align=\"center\" class=\"titre\">" |
| 858 | "<th rowspan=2></th>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 859 | "<th colspan=3>Queue</th>" |
| 860 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 861 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 862 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 863 | "<th colspan=8>Server</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 864 | "</tr>\n" |
| 865 | "<tr align=\"center\" class=\"titre\">" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 866 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 867 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 868 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 869 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 870 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 871 | "<th>Status</th><th>Wght</th><th>Act</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 872 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 873 | "<th>Thrtle</th>\n" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 874 | "</tr>", |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 875 | px->id); |
| 876 | |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 877 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 878 | return 0; |
| 879 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 880 | |
| 881 | s->data_ctx.stats.px_st = DATA_ST_PX_FE; |
| 882 | /* fall through */ |
| 883 | |
| 884 | case DATA_ST_PX_FE: |
| 885 | /* print the frontend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 886 | if ((px->cap & PR_CAP_FE) && |
| 887 | (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_FE)))) { |
| 888 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 889 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 890 | /* name, queue */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 891 | "<tr align=center class=\"frontend\"><td>Frontend</td><td colspan=3></td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 892 | /* sessions rate : current, max, limit */ |
| 893 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
| 894 | /* sessions : current, max, limit, total, lbtot */ |
| 895 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 896 | "<td align=right>%s</td><td align=right></td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 897 | /* bytes : in, out */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 898 | "<td align=right>%s</td><td align=right>%s</td>" |
| 899 | "", |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 900 | U2H0(read_freq_ctr(&px->fe_sess_per_sec)), |
| 901 | U2H1(px->fe_sps_max), LIM2A2(px->fe_sps_lim, "-"), |
| 902 | U2H3(px->feconn), U2H4(px->feconn_max), U2H5(px->maxconn), |
| 903 | U2H6(px->cum_feconn), U2H7(px->bytes_in), U2H8(px->bytes_out)); |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 904 | |
| 905 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 906 | /* denied: req, resp */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 907 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 908 | /* errors : request, connect, response */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 909 | "<td align=right>%s</td><td align=right></td><td align=right></td>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 910 | /* warnings: retries, redispatches */ |
| 911 | "<td align=right></td><td align=right></td>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 912 | /* server status : reflect frontend status */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 913 | "<td align=center>%s</td>" |
| 914 | /* rest of server: nothing */ |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 915 | "<td align=center colspan=7></td></tr>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 916 | "", |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 917 | U2H0(px->denied_req), U2H1(px->denied_resp), |
| 918 | U2H2(px->failed_req), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 919 | px->state == PR_STRUN ? "OPEN" : |
| 920 | px->state == PR_STIDLE ? "FULL" : "STOP"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 921 | } else { |
| 922 | chunk_printf(&msg, sizeof(trash), |
| 923 | /* pxid, name, queue cur, queue max, */ |
| 924 | "%s,FRONTEND,,," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 925 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 926 | "%d,%d,%d,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 927 | /* bytes : in, out */ |
| 928 | "%lld,%lld," |
| 929 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 930 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 931 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 932 | "%lld,,," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 933 | /* warnings: retries, redispatches */ |
| 934 | ",," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 935 | /* server status : reflect frontend status */ |
| 936 | "%s," |
| 937 | /* rest of server: nothing */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 938 | ",,,,,,,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 939 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 940 | "%d,%d,0,,,,%d," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 941 | /* rate, rate_lim, rate_max, */ |
| 942 | "%u,%u,%u," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 943 | "\n", |
| 944 | px->id, |
| 945 | px->feconn, px->feconn_max, px->maxconn, px->cum_feconn, |
| 946 | px->bytes_in, px->bytes_out, |
| 947 | px->denied_req, px->denied_resp, |
| 948 | px->failed_req, |
| 949 | px->state == PR_STRUN ? "OPEN" : |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 950 | px->state == PR_STIDLE ? "FULL" : "STOP", |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 951 | relative_pid, px->uuid, STATS_TYPE_FE, |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 952 | read_freq_ctr(&px->fe_sess_per_sec), |
| 953 | px->fe_sps_lim, px->fe_sps_max); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 954 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 955 | |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 956 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | s->data_ctx.stats.sv = px->srv; /* may be NULL */ |
| 961 | s->data_ctx.stats.px_st = DATA_ST_PX_SV; |
| 962 | /* fall through */ |
| 963 | |
| 964 | case DATA_ST_PX_SV: |
| 965 | /* stats.sv has been initialized above */ |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 966 | for (; s->data_ctx.stats.sv != NULL; s->data_ctx.stats.sv = sv->next) { |
| 967 | |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 968 | int sv_state; /* 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, 6=unchecked */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 969 | |
| 970 | sv = s->data_ctx.stats.sv; |
| 971 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 972 | if (s->data_ctx.stats.flags & STAT_BOUND) { |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 973 | if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SV))) |
| 974 | break; |
| 975 | |
| 976 | if (s->data_ctx.stats.sid != -1 && sv->puid != s->data_ctx.stats.sid) |
| 977 | continue; |
| 978 | } |
| 979 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 980 | if (sv->tracked) |
| 981 | svs = sv->tracked; |
| 982 | else |
| 983 | svs = sv; |
| 984 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 985 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 986 | if (!(svs->state & SRV_CHECKED)) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 987 | sv_state = 6; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 988 | else if (svs->state & SRV_RUNNING) { |
| 989 | if (svs->health == svs->rise + svs->fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 990 | sv_state = 3; /* UP */ |
| 991 | else |
| 992 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 993 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 994 | if (svs->state & SRV_GOINGDOWN) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 995 | sv_state += 2; |
| 996 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 997 | else |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 998 | if (svs->health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 999 | sv_state = 1; /* going up */ |
| 1000 | else |
| 1001 | sv_state = 0; /* DOWN */ |
| 1002 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1003 | if ((sv_state == 0) && (s->data_ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1004 | /* do not report servers which are DOWN */ |
| 1005 | s->data_ctx.stats.sv = sv->next; |
| 1006 | continue; |
| 1007 | } |
| 1008 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1009 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1010 | static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d ↑", |
| 1011 | "UP %d/%d ↓", "UP", |
| 1012 | "NOLB %d/%d ↓", "NOLB", |
| 1013 | "<i>no check</i>" }; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1014 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1015 | /* name */ |
| 1016 | "<tr align=\"center\" class=\"%s%d\"><td>%s</td>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1017 | /* queue : current, max, limit */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1018 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1019 | /* sessions rate : current, max, limit */ |
| 1020 | "<td align=right>%s</td><td align=right>%s</td><td align=right></td>" |
| 1021 | /* sessions : current, max, limit, total, lbtot */ |
| 1022 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1023 | "<td align=right>%s</td><td align=right>%s</td>" |
| 1024 | "", |
| 1025 | (sv->state & SRV_BACKUP) ? "backup" : "active", |
| 1026 | sv_state, sv->id, |
| 1027 | U2H0(sv->nbpend), U2H1(sv->nbpend_max), LIM2A2(sv->maxqueue, "-"), |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1028 | U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->sps_max), |
| 1029 | U2H5(sv->cur_sess), U2H6(sv->cur_sess_max), LIM2A7(sv->maxconn, "-"), |
| 1030 | U2H8(sv->cum_sess), U2H9(sv->cum_lbconn)); |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1031 | |
| 1032 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1033 | /* bytes : in, out */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1034 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1035 | /* denied: req, resp */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1036 | "<td align=right></td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1037 | /* errors : request, connect, response */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1038 | "<td align=right></td><td align=right>%s</td><td align=right>%s</td>\n" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1039 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1040 | "<td align=right>%lld</td><td align=right>%lld</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1041 | "", |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1042 | U2H0(sv->bytes_in), U2H1(sv->bytes_out), |
| 1043 | U2H2(sv->failed_secu), |
| 1044 | U2H3(sv->failed_conns), U2H4(sv->failed_resp), |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 1045 | sv->retries, sv->redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1046 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1047 | /* status */ |
| 1048 | chunk_printf(&msg, sizeof(trash), "<td nowrap>"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1049 | |
| 1050 | if (sv->state & SRV_CHECKED) |
| 1051 | chunk_printf(&msg, sizeof(trash), "%s ", |
| 1052 | human_time(now.tv_sec - sv->last_change, 1)); |
| 1053 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1054 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1055 | srv_hlt_st[sv_state], |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1056 | (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), |
| 1057 | (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1058 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1059 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1060 | /* weight */ |
| 1061 | "</td><td>%d</td>" |
| 1062 | /* act, bck */ |
| 1063 | "<td>%s</td><td>%s</td>" |
| 1064 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1065 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1066 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 1067 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 1068 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1069 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1070 | if (sv->state & SRV_CHECKED) |
| 1071 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1072 | "<td align=right>%lld</td><td align=right>%lld</td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1073 | "<td nowrap align=right>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1074 | "", |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1075 | svs->failed_checks, svs->down_trans, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1076 | human_time(srv_downtime(sv), 1)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1077 | else if (sv != svs) |
| 1078 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1079 | "<td nowrap colspan=3>via %s/%s</td>", svs->proxy->id, svs->id); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1080 | else |
| 1081 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1082 | "<td colspan=3></td>"); |
| 1083 | |
| 1084 | /* throttle */ |
| 1085 | if ((sv->state & SRV_WARMINGUP) && |
| 1086 | now.tv_sec < sv->last_change + sv->slowstart && |
| 1087 | now.tv_sec >= sv->last_change) { |
| 1088 | unsigned int ratio; |
| 1089 | ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); |
| 1090 | chunk_printf(&msg, sizeof(trash), |
| 1091 | "<td>%d %%</td></tr>\n", ratio); |
| 1092 | } else { |
| 1093 | chunk_printf(&msg, sizeof(trash), |
| 1094 | "<td>-</td></tr>\n"); |
| 1095 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1096 | } else { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1097 | static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,", |
| 1098 | "UP %d/%d,", "UP,", |
| 1099 | "NOLB %d/%d,", "NOLB,", |
| 1100 | "no check," }; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1101 | chunk_printf(&msg, sizeof(trash), |
| 1102 | /* pxid, name */ |
| 1103 | "%s,%s," |
| 1104 | /* queue : current, max */ |
| 1105 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1106 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1107 | "%d,%d,%s,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1108 | /* bytes : in, out */ |
| 1109 | "%lld,%lld," |
| 1110 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1111 | ",%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1112 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1113 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1114 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1115 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1116 | "", |
| 1117 | px->id, sv->id, |
| 1118 | sv->nbpend, sv->nbpend_max, |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 1119 | sv->cur_sess, sv->cur_sess_max, LIM2A0(sv->maxconn, ""), sv->cum_sess, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1120 | sv->bytes_in, sv->bytes_out, |
| 1121 | sv->failed_secu, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1122 | sv->failed_conns, sv->failed_resp, |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 1123 | sv->retries, sv->redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1124 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1125 | /* status */ |
| 1126 | chunk_printf(&msg, sizeof(trash), |
| 1127 | srv_hlt_st[sv_state], |
| 1128 | (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health), |
| 1129 | (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1130 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1131 | chunk_printf(&msg, sizeof(trash), |
| 1132 | /* weight, active, backup */ |
| 1133 | "%d,%d,%d," |
| 1134 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1135 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1136 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 1137 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 1138 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1139 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1140 | if (sv->state & SRV_CHECKED) |
| 1141 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1142 | "%lld,%lld,%d,%d,", |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1143 | sv->failed_checks, sv->down_trans, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1144 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1145 | else |
| 1146 | chunk_printf(&msg, sizeof(trash), |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1147 | ",,,,"); |
| 1148 | |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1149 | /* queue limit, pid, iid, sid, */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1150 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 1151 | "%s," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1152 | "%d,%d,%d,", |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 1153 | LIM2A0(sv->maxqueue, ""), |
| 1154 | relative_pid, px->uuid, sv->puid); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1155 | |
| 1156 | /* throttle */ |
| 1157 | if ((sv->state & SRV_WARMINGUP) && |
| 1158 | now.tv_sec < sv->last_change + sv->slowstart && |
| 1159 | now.tv_sec >= sv->last_change) { |
| 1160 | unsigned int ratio; |
| 1161 | ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1162 | chunk_printf(&msg, sizeof(trash), "%d", ratio); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1163 | } |
| 1164 | |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1165 | /* sessions: lbtot */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1166 | chunk_printf(&msg, sizeof(trash), ",%lld,", sv->cum_lbconn); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1167 | |
| 1168 | /* tracked */ |
| 1169 | if (sv->tracked) |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 1170 | chunk_printf(&msg, sizeof(trash), "%s/%s,", |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1171 | sv->tracked->proxy->id, sv->tracked->id); |
| 1172 | else |
| 1173 | chunk_printf(&msg, sizeof(trash), ","); |
| 1174 | |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 1175 | /* type */ |
| 1176 | chunk_printf(&msg, sizeof(trash), "%d,", STATS_TYPE_SV); |
| 1177 | |
| 1178 | /* rate */ |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 1179 | chunk_printf(&msg, sizeof(trash), "%u,,%u,", |
| 1180 | read_freq_ctr(&sv->sess_per_sec), |
| 1181 | sv->sps_max); |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 1182 | |
| 1183 | /* finish with EOL */ |
| 1184 | chunk_printf(&msg, sizeof(trash), "\n"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1185 | } |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 1186 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1187 | return 0; |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1188 | } /* for sv */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1189 | |
| 1190 | s->data_ctx.stats.px_st = DATA_ST_PX_BE; |
| 1191 | /* fall through */ |
| 1192 | |
| 1193 | case DATA_ST_PX_BE: |
| 1194 | /* print the backend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1195 | if ((px->cap & PR_CAP_BE) && |
| 1196 | (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_BE)))) { |
| 1197 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1198 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1199 | /* name */ |
| 1200 | "<tr align=center class=\"backend\"><td>Backend</td>" |
| 1201 | /* queue : current, max */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1202 | "<td align=right>%s</td><td align=right>%s</td><td></td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1203 | /* sessions rate : current, max, limit */ |
| 1204 | "<td align=right>%s</td><td align=right>%s</td><td align=right></td>" |
| 1205 | "", |
| 1206 | U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->nbpend_max), |
| 1207 | U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->be_sps_max)); |
| 1208 | |
| 1209 | chunk_printf(&msg, sizeof(trash), |
| 1210 | /* sessions : current, max, limit, total, lbtot */ |
| 1211 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1212 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1213 | /* bytes : in, out */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1214 | "<td align=right>%s</td><td align=right>%s</td>" |
| 1215 | "", |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1216 | U2H2(px->beconn), U2H3(px->beconn_max), U2H4(px->fullconn), |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1217 | U2H6(px->cum_beconn), U2H7(px->cum_lbconn), |
| 1218 | U2H8(px->bytes_in), U2H9(px->bytes_out)); |
| 1219 | |
| 1220 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1221 | /* denied: req, resp */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1222 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1223 | /* errors : request, connect, response */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1224 | "<td align=right></td><td align=right>%s</td><td align=right>%s</td>\n" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1225 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1226 | "<td align=right>%lld</td><td align=right>%lld</td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1227 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1228 | * if the backend has known working servers or if it has no server at |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1229 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1230 | * active and backups. */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1231 | "<td align=center nowrap>%s %s</td><td align=center>%d</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1232 | "<td align=center>%d</td><td align=center>%d</td>" |
| 1233 | "", |
| 1234 | U2H0(px->denied_req), U2H1(px->denied_resp), |
| 1235 | U2H2(px->failed_conns), U2H3(px->failed_resp), |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1236 | px->retries, px->redispatches, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1237 | human_time(now.tv_sec - px->last_change, 1), |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1238 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 1239 | "<font color=\"red\"><b>DOWN</b></font>", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1240 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 1241 | px->srv_act, px->srv_bck); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1242 | |
| 1243 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1244 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1245 | "<td align=center> </td><td align=\"right\">%d</td>" |
| 1246 | "<td align=\"right\" nowrap>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1247 | "<td></td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1248 | "</tr>", |
| 1249 | px->down_trans, |
| 1250 | px->srv?human_time(be_downtime(px), 1):" "); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1251 | } else { |
| 1252 | chunk_printf(&msg, sizeof(trash), |
| 1253 | /* pxid, name */ |
| 1254 | "%s,BACKEND," |
| 1255 | /* queue : current, max */ |
| 1256 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1257 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1258 | "%d,%d,%d,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1259 | /* bytes : in, out */ |
| 1260 | "%lld,%lld," |
| 1261 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1262 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1263 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1264 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1265 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1266 | "%lld,%lld," |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1267 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1268 | * if the backend has known working servers or if it has no server at |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1269 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1270 | * active and backups. */ |
| 1271 | "%s," |
| 1272 | "%d,%d,%d," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1273 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1274 | ",%d,%d,%d,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1275 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1276 | "%d,%d,0,,%lld,,%d," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 1277 | /* rate, rate_lim, rate_max, */ |
| 1278 | "%u,,%u," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1279 | "\n", |
| 1280 | px->id, |
| 1281 | px->nbpend /* or px->totpend ? */, px->nbpend_max, |
| 1282 | px->beconn, px->beconn_max, px->fullconn, px->cum_beconn, |
| 1283 | px->bytes_in, px->bytes_out, |
| 1284 | px->denied_req, px->denied_resp, |
| 1285 | px->failed_conns, px->failed_resp, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1286 | px->retries, px->redispatches, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 1287 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1288 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 1289 | px->srv_act, px->srv_bck, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1290 | px->down_trans, (int)(now.tv_sec - px->last_change), |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 1291 | px->srv?be_downtime(px):0, |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1292 | relative_pid, px->uuid, |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 1293 | px->cum_lbconn, STATS_TYPE_BE, |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 1294 | read_freq_ctr(&px->be_sess_per_sec), |
| 1295 | px->be_sps_max); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1296 | } |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 1297 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1298 | return 0; |
| 1299 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1300 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1301 | s->data_ctx.stats.px_st = DATA_ST_PX_END; |
| 1302 | /* fall through */ |
| 1303 | |
| 1304 | case DATA_ST_PX_END: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1305 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1306 | chunk_printf(&msg, sizeof(trash), "</table><p>\n"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1307 | |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 1308 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1309 | return 0; |
| 1310 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1311 | |
| 1312 | s->data_ctx.stats.px_st = DATA_ST_PX_FIN; |
| 1313 | /* fall through */ |
| 1314 | |
| 1315 | case DATA_ST_PX_FIN: |
| 1316 | return 1; |
| 1317 | |
| 1318 | default: |
| 1319 | /* unknown state, we should put an abort() here ! */ |
| 1320 | return 1; |
| 1321 | } |
| 1322 | } |
| 1323 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1324 | |
| 1325 | /* This function is called to send output to the response buffer. |
| 1326 | * It dumps the sessions states onto the output buffer <rep>. |
| 1327 | * Expects to be called with client socket shut down on input. |
| 1328 | * s->data_ctx must have been zeroed first, and the flags properly set. |
| 1329 | * It automatically clears the HIJACK bit from the response buffer. |
| 1330 | */ |
| 1331 | void stats_dump_sess_to_buffer(struct session *s, struct buffer *rep) |
| 1332 | { |
| 1333 | struct chunk msg; |
| 1334 | |
| 1335 | if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) { |
| 1336 | /* If we're forced to shut down, we might have to remove our |
| 1337 | * reference to the last session being dumped. |
| 1338 | */ |
| 1339 | if (s->data_state == DATA_ST_LIST) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1340 | if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1341 | LIST_DEL(&s->data_ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1342 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1343 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1344 | } |
| 1345 | s->data_state = DATA_ST_FIN; |
| 1346 | buffer_stop_hijack(rep); |
| 1347 | s->ana_state = STATS_ST_CLOSE; |
| 1348 | return; |
| 1349 | } |
| 1350 | |
| 1351 | if (s->ana_state != STATS_ST_REP) |
| 1352 | return; |
| 1353 | |
| 1354 | msg.len = 0; |
| 1355 | msg.str = trash; |
| 1356 | |
| 1357 | switch (s->data_state) { |
| 1358 | case DATA_ST_INIT: |
| 1359 | /* the function had not been called yet, let's prepare the |
| 1360 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1361 | * pointer to the first in the global list. When a target |
| 1362 | * session is being destroyed, it is responsible for updating |
| 1363 | * this pointer. We know we have reached the end when this |
| 1364 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1365 | */ |
| 1366 | stream_int_retnclose(rep->cons, &msg); |
| 1367 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1368 | s->data_ctx.sess.bref.ref = sessions.n; |
| 1369 | s->data_state = DATA_ST_LIST; |
| 1370 | /* fall through */ |
| 1371 | |
| 1372 | case DATA_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1373 | /* first, let's detach the back-ref from a possible previous session */ |
| 1374 | if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) { |
| 1375 | LIST_DEL(&s->data_ctx.sess.bref.users); |
| 1376 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1377 | } |
| 1378 | |
| 1379 | /* and start from where we stopped */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1380 | while (s->data_ctx.sess.bref.ref != &sessions) { |
| 1381 | char pn[INET6_ADDRSTRLEN + strlen(":65535")]; |
| 1382 | struct session *curr_sess; |
| 1383 | |
| 1384 | curr_sess = LIST_ELEM(s->data_ctx.sess.bref.ref, struct session *, list); |
| 1385 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1386 | chunk_printf(&msg, sizeof(trash), |
| 1387 | "%p: proto=%s", |
| 1388 | curr_sess, |
| 1389 | curr_sess->listener->proto->name); |
| 1390 | |
| 1391 | switch (curr_sess->listener->proto->sock_family) { |
| 1392 | case AF_INET: |
| 1393 | inet_ntop(AF_INET, |
| 1394 | (const void *)&((struct sockaddr_in *)&curr_sess->cli_addr)->sin_addr, |
| 1395 | pn, sizeof(pn)); |
| 1396 | |
| 1397 | chunk_printf(&msg, sizeof(trash), |
| 1398 | " src=%s:%d fe=%s be=%s srv=%s", |
| 1399 | pn, |
| 1400 | ntohs(((struct sockaddr_in *)&curr_sess->cli_addr)->sin_port), |
| 1401 | curr_sess->fe->id, |
| 1402 | curr_sess->be->id, |
| 1403 | curr_sess->srv ? curr_sess->srv->id : "<none>" |
| 1404 | ); |
| 1405 | break; |
| 1406 | case AF_INET6: |
| 1407 | inet_ntop(AF_INET6, |
| 1408 | (const void *)&((struct sockaddr_in6 *)(&curr_sess->cli_addr))->sin6_addr, |
| 1409 | pn, sizeof(pn)); |
| 1410 | |
| 1411 | chunk_printf(&msg, sizeof(trash), |
| 1412 | " src=%s:%d fe=%s be=%s srv=%s", |
| 1413 | pn, |
| 1414 | ntohs(((struct sockaddr_in6 *)&curr_sess->cli_addr)->sin6_port), |
| 1415 | curr_sess->fe->id, |
| 1416 | curr_sess->be->id, |
| 1417 | curr_sess->srv ? curr_sess->srv->id : "<none>" |
| 1418 | ); |
| 1419 | |
| 1420 | break; |
| 1421 | case AF_UNIX: |
| 1422 | /* no more information to print right now */ |
| 1423 | break; |
| 1424 | } |
| 1425 | |
| 1426 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1427 | " as=%d ts=%02x age=%s calls=%d", |
Willy Tarreau | 8a5c626 | 2008-12-08 00:16:21 +0100 | [diff] [blame] | 1428 | curr_sess->ana_state, curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 1429 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 1430 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1431 | |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1432 | chunk_printf(&msg, sizeof(trash), |
| 1433 | " rq[f=%06xh,l=%d,an=%02xh,rx=%s", |
| 1434 | curr_sess->req->flags, |
| 1435 | curr_sess->req->l, |
| 1436 | curr_sess->req->analysers, |
| 1437 | curr_sess->req->rex ? |
| 1438 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 1439 | TICKS_TO_MS(1000)) : ""); |
| 1440 | |
| 1441 | chunk_printf(&msg, sizeof(trash), |
| 1442 | ",wx=%s", |
| 1443 | curr_sess->req->wex ? |
| 1444 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 1445 | TICKS_TO_MS(1000)) : ""); |
| 1446 | |
| 1447 | chunk_printf(&msg, sizeof(trash), |
| 1448 | ",ax=%s]", |
| 1449 | curr_sess->req->analyse_exp ? |
| 1450 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 1451 | TICKS_TO_MS(1000)) : ""); |
| 1452 | |
| 1453 | chunk_printf(&msg, sizeof(trash), |
| 1454 | " rp[f=%06xh,l=%d,an=%02xh,rx=%s", |
| 1455 | curr_sess->rep->flags, |
| 1456 | curr_sess->rep->l, |
| 1457 | curr_sess->rep->analysers, |
| 1458 | curr_sess->rep->rex ? |
| 1459 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 1460 | TICKS_TO_MS(1000)) : ""); |
| 1461 | |
| 1462 | chunk_printf(&msg, sizeof(trash), |
| 1463 | ",wx=%s", |
| 1464 | curr_sess->rep->wex ? |
| 1465 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 1466 | TICKS_TO_MS(1000)) : ""); |
| 1467 | |
| 1468 | chunk_printf(&msg, sizeof(trash), |
| 1469 | ",ax=%s]", |
| 1470 | curr_sess->rep->analyse_exp ? |
| 1471 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 1472 | TICKS_TO_MS(1000)) : ""); |
| 1473 | |
| 1474 | chunk_printf(&msg, sizeof(trash), |
| 1475 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 1476 | curr_sess->si[0].state, |
| 1477 | curr_sess->si[0].flags, |
| 1478 | curr_sess->si[0].fd, |
| 1479 | curr_sess->si[0].exp ? |
| 1480 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 1481 | TICKS_TO_MS(1000)) : ""); |
| 1482 | |
| 1483 | chunk_printf(&msg, sizeof(trash), |
| 1484 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 1485 | curr_sess->si[1].state, |
| 1486 | curr_sess->si[1].flags, |
| 1487 | curr_sess->si[1].fd, |
| 1488 | curr_sess->si[1].exp ? |
| 1489 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 1490 | TICKS_TO_MS(1000)) : ""); |
| 1491 | |
| 1492 | chunk_printf(&msg, sizeof(trash), |
| 1493 | " exp=%s", |
| 1494 | curr_sess->task->expire ? |
| 1495 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 1496 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 1497 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1498 | chunk_printf(&msg, sizeof(trash), " run(nice=%d)", curr_sess->task->nice); |
| 1499 | |
| 1500 | chunk_printf(&msg, sizeof(trash), "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1501 | |
| 1502 | if (buffer_write_chunk(rep, &msg) >= 0) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1503 | /* let's try again later from this session. We add ourselves into |
| 1504 | * this session's users so that it can remove us upon termination. |
| 1505 | */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1506 | LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users); |
| 1507 | return; |
| 1508 | } |
| 1509 | |
| 1510 | s->data_ctx.sess.bref.ref = curr_sess->list.n; |
| 1511 | } |
| 1512 | s->data_state = DATA_ST_FIN; |
| 1513 | /* fall through */ |
| 1514 | |
| 1515 | default: |
| 1516 | s->data_state = DATA_ST_FIN; |
| 1517 | buffer_stop_hijack(rep); |
| 1518 | s->ana_state = STATS_ST_CLOSE; |
| 1519 | return; |
| 1520 | } |
| 1521 | } |
| 1522 | |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1523 | /* print a line of error buffer (limited to 70 bytes) to <out>. The format is : |
| 1524 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 1525 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 1526 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 1527 | * lines are respected within the limit of 70 output chars. Lines that are |
| 1528 | * continuation of a previous truncated line begin with "+" instead of " " |
| 1529 | * after the offset. The new pointer is returned. |
| 1530 | */ |
| 1531 | static int dump_error_line(struct chunk *out, int size, |
| 1532 | struct error_snapshot *err, int *line, int ptr) |
| 1533 | { |
| 1534 | int end; |
| 1535 | unsigned char c; |
| 1536 | |
| 1537 | end = out->len + 80; |
| 1538 | if (end > size) |
| 1539 | return ptr; |
| 1540 | |
| 1541 | chunk_printf(out, size, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
| 1542 | |
| 1543 | while (ptr < err->len) { |
| 1544 | c = err->buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 1545 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1546 | if (out->len > end - 2) |
| 1547 | break; |
| 1548 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 1549 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1550 | if (out->len > end - 3) |
| 1551 | break; |
| 1552 | out->str[out->len++] = '\\'; |
| 1553 | switch (c) { |
| 1554 | case '\t': c = 't'; break; |
| 1555 | case '\n': c = 'n'; break; |
| 1556 | case '\r': c = 'r'; break; |
| 1557 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 1558 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1559 | } |
| 1560 | out->str[out->len++] = c; |
| 1561 | } else { |
| 1562 | if (out->len > end - 5) |
| 1563 | break; |
| 1564 | out->str[out->len++] = '\\'; |
| 1565 | out->str[out->len++] = 'x'; |
| 1566 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 1567 | out->str[out->len++] = hextab[c & 0xF]; |
| 1568 | } |
| 1569 | if (err->buf[ptr++] == '\n') { |
| 1570 | /* we had a line break, let's return now */ |
| 1571 | out->str[out->len++] = '\n'; |
| 1572 | *line = ptr; |
| 1573 | return ptr; |
| 1574 | } |
| 1575 | } |
| 1576 | /* we have an incomplete line, we return it as-is */ |
| 1577 | out->str[out->len++] = '\n'; |
| 1578 | return ptr; |
| 1579 | } |
| 1580 | |
| 1581 | /* This function is called to send output to the response buffer. |
| 1582 | * It dumps the errors logged in proxies onto the output buffer <rep>. |
| 1583 | * Expects to be called with client socket shut down on input. |
| 1584 | * s->data_ctx must have been zeroed first, and the flags properly set. |
| 1585 | * It automatically clears the HIJACK bit from the response buffer. |
| 1586 | */ |
| 1587 | void stats_dump_errors_to_buffer(struct session *s, struct buffer *rep) |
| 1588 | { |
| 1589 | extern const char *monthname[12]; |
| 1590 | struct chunk msg; |
| 1591 | |
| 1592 | if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) { |
| 1593 | s->data_state = DATA_ST_FIN; |
| 1594 | buffer_stop_hijack(rep); |
| 1595 | s->ana_state = STATS_ST_CLOSE; |
| 1596 | return; |
| 1597 | } |
| 1598 | |
| 1599 | if (s->ana_state != STATS_ST_REP) |
| 1600 | return; |
| 1601 | |
| 1602 | msg.len = 0; |
| 1603 | msg.str = trash; |
| 1604 | |
| 1605 | if (!s->data_ctx.errors.px) { |
| 1606 | /* the function had not been called yet, let's prepare the |
| 1607 | * buffer for a response. |
| 1608 | */ |
| 1609 | stream_int_retnclose(rep->cons, &msg); |
| 1610 | s->data_ctx.errors.px = proxy; |
| 1611 | s->data_ctx.errors.buf = 0; |
| 1612 | s->data_ctx.errors.bol = 0; |
| 1613 | s->data_ctx.errors.ptr = -1; |
| 1614 | } |
| 1615 | |
| 1616 | /* we have two inner loops here, one for the proxy, the other one for |
| 1617 | * the buffer. |
| 1618 | */ |
| 1619 | while (s->data_ctx.errors.px) { |
| 1620 | struct error_snapshot *es; |
| 1621 | |
| 1622 | if (s->data_ctx.errors.buf == 0) |
| 1623 | es = &s->data_ctx.errors.px->invalid_req; |
| 1624 | else |
| 1625 | es = &s->data_ctx.errors.px->invalid_rep; |
| 1626 | |
| 1627 | if (!es->when.tv_sec) |
| 1628 | goto next; |
| 1629 | |
| 1630 | if (s->data_ctx.errors.iid >= 0 && |
| 1631 | s->data_ctx.errors.px->uuid != s->data_ctx.errors.iid && |
| 1632 | es->oe->uuid != s->data_ctx.errors.iid) |
| 1633 | goto next; |
| 1634 | |
| 1635 | if (s->data_ctx.errors.ptr < 0) { |
| 1636 | /* just print headers now */ |
| 1637 | |
| 1638 | char pn[INET6_ADDRSTRLEN]; |
| 1639 | struct tm tm; |
| 1640 | |
| 1641 | get_localtime(es->when.tv_sec, &tm); |
| 1642 | chunk_printf(&msg, sizeof(trash), "\n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
| 1643 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1644 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000)); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1645 | |
| 1646 | |
| 1647 | if (es->src.ss_family == AF_INET) |
| 1648 | inet_ntop(AF_INET, |
| 1649 | (const void *)&((struct sockaddr_in *)&es->src)->sin_addr, |
| 1650 | pn, sizeof(pn)); |
| 1651 | else |
| 1652 | inet_ntop(AF_INET6, |
| 1653 | (const void *)&((struct sockaddr_in6 *)(&es->src))->sin6_addr, |
| 1654 | pn, sizeof(pn)); |
| 1655 | |
| 1656 | switch (s->data_ctx.errors.buf) { |
| 1657 | case 0: |
| 1658 | chunk_printf(&msg, sizeof(trash), |
| 1659 | " frontend %s (#%d): invalid request\n" |
| 1660 | " src %s, session #%d, backend %s (#%d), server %s (#%d)\n" |
| 1661 | " request length %d bytes, error at position %d:\n\n", |
| 1662 | s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid, |
| 1663 | pn, es->sid, es->oe->id, es->oe->uuid, |
| 1664 | es->srv ? es->srv->id : "<NONE>", |
| 1665 | es->srv ? es->srv->puid : -1, |
| 1666 | es->len, es->pos); |
| 1667 | break; |
| 1668 | case 1: |
| 1669 | chunk_printf(&msg, sizeof(trash), |
| 1670 | " backend %s (#%d) : invalid response\n" |
| 1671 | " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n" |
| 1672 | " response length %d bytes, error at position %d:\n\n", |
| 1673 | s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid, |
| 1674 | pn, es->sid, es->oe->id, es->oe->uuid, |
| 1675 | es->srv ? es->srv->id : "<NONE>", |
| 1676 | es->srv ? es->srv->puid : -1, |
| 1677 | es->len, es->pos); |
| 1678 | break; |
| 1679 | } |
| 1680 | |
| 1681 | if (buffer_write_chunk(rep, &msg) >= 0) { |
| 1682 | /* Socket buffer full. Let's try again later from the same point */ |
| 1683 | return; |
| 1684 | } |
| 1685 | s->data_ctx.errors.ptr = 0; |
| 1686 | s->data_ctx.errors.sid = es->sid; |
| 1687 | } |
| 1688 | |
| 1689 | if (s->data_ctx.errors.sid != es->sid) { |
| 1690 | /* the snapshot changed while we were dumping it */ |
| 1691 | chunk_printf(&msg, sizeof(trash), |
| 1692 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
| 1693 | if (buffer_write_chunk(rep, &msg) >= 0) |
| 1694 | return; |
| 1695 | goto next; |
| 1696 | } |
| 1697 | |
| 1698 | /* OK, ptr >= 0, so we have to dump the current line */ |
| 1699 | while (s->data_ctx.errors.ptr < es->len) { |
| 1700 | int newptr; |
| 1701 | int newline; |
| 1702 | |
| 1703 | newline = s->data_ctx.errors.bol; |
| 1704 | newptr = dump_error_line(&msg, sizeof(trash), es, &newline, s->data_ctx.errors.ptr); |
| 1705 | if (newptr == s->data_ctx.errors.ptr) |
| 1706 | return; |
| 1707 | |
| 1708 | if (buffer_write_chunk(rep, &msg) >= 0) { |
| 1709 | /* Socket buffer full. Let's try again later from the same point */ |
| 1710 | return; |
| 1711 | } |
| 1712 | s->data_ctx.errors.ptr = newptr; |
| 1713 | s->data_ctx.errors.bol = newline; |
| 1714 | }; |
| 1715 | next: |
| 1716 | s->data_ctx.errors.bol = 0; |
| 1717 | s->data_ctx.errors.ptr = -1; |
| 1718 | s->data_ctx.errors.buf++; |
| 1719 | if (s->data_ctx.errors.buf > 1) { |
| 1720 | s->data_ctx.errors.buf = 0; |
| 1721 | s->data_ctx.errors.px = s->data_ctx.errors.px->next; |
| 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | /* dump complete */ |
| 1726 | buffer_stop_hijack(rep); |
| 1727 | s->ana_state = STATS_ST_CLOSE; |
| 1728 | } |
| 1729 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1730 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 1731 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 1732 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 1733 | { 0, NULL, NULL }, |
| 1734 | }}; |
| 1735 | |
| 1736 | __attribute__((constructor)) |
| 1737 | static void __dumpstats_module_init(void) |
| 1738 | { |
| 1739 | cfg_register_keywords(&cfg_kws); |
| 1740 | } |
| 1741 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1742 | /* |
| 1743 | * Local variables: |
| 1744 | * c-indent-level: 8 |
| 1745 | * c-basic-offset: 8 |
| 1746 | * End: |
| 1747 | */ |