Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Functions dedicated to statistics output |
| 3 | * |
| 4 | * Copyright 2000-2007 Willy Tarreau <w@1wt.eu> |
| 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 | |
| 26 | #include <common/compat.h> |
| 27 | #include <common/config.h> |
| 28 | #include <common/debug.h> |
| 29 | #include <common/memory.h> |
| 30 | #include <common/mini-clist.h> |
| 31 | #include <common/standard.h> |
| 32 | #include <common/time.h> |
| 33 | #include <common/uri_auth.h> |
| 34 | #include <common/version.h> |
| 35 | |
| 36 | #include <types/client.h> |
| 37 | #include <types/global.h> |
| 38 | #include <types/polling.h> |
| 39 | #include <types/proxy.h> |
| 40 | #include <types/server.h> |
| 41 | |
| 42 | #include <proto/backend.h> |
| 43 | #include <proto/buffers.h> |
| 44 | #include <proto/dumpstats.h> |
| 45 | #include <proto/fd.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 46 | #include <proto/proto_uxst.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 47 | #include <proto/senddata.h> |
| 48 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 49 | #include <proto/server.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 50 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 51 | /* This function parses a "stats" statement in the "global" section. It returns |
| 52 | * -1 if there is any error, otherwise zero. If it returns -1, it may write an |
| 53 | * error message into ther <err> buffer, for at most <errlen> bytes, trailing |
| 54 | * zero included. The trailing '\n' must not be written. The function must be |
| 55 | * called with <args> pointing to the first word after "stats". |
| 56 | */ |
| 57 | int stats_parse_global(const char **args, char *err, int errlen) |
| 58 | { |
| 59 | if (!strcmp(args[0], "socket")) { |
| 60 | struct sockaddr_un su; |
| 61 | int cur_arg; |
| 62 | |
| 63 | if (*args[1] == 0) { |
| 64 | snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket"); |
| 65 | return -1; |
| 66 | } |
| 67 | |
| 68 | if (global.stats_sock.state != LI_NEW) { |
| 69 | snprintf(err, errlen, "'stats socket' already specified in global section"); |
| 70 | return -1; |
| 71 | } |
| 72 | |
| 73 | su.sun_family = AF_UNIX; |
| 74 | strncpy(su.sun_path, args[1], sizeof(su.sun_path)); |
| 75 | su.sun_path[sizeof(su.sun_path) - 1] = 0; |
| 76 | memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit |
| 77 | |
| 78 | global.stats_sock.state = LI_INIT; |
Willy Tarreau | 6fb42e0 | 2007-10-28 17:02:33 +0100 | [diff] [blame] | 79 | global.stats_sock.options = LI_O_NONE; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 80 | global.stats_sock.accept = uxst_event_accept; |
| 81 | global.stats_sock.handler = process_uxst_stats; |
| 82 | global.stats_sock.private = NULL; |
| 83 | |
| 84 | cur_arg = 2; |
| 85 | while (*args[cur_arg]) { |
| 86 | if (!strcmp(args[cur_arg], "uid")) { |
| 87 | global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]); |
| 88 | cur_arg += 2; |
| 89 | } |
| 90 | else if (!strcmp(args[cur_arg], "gid")) { |
| 91 | global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]); |
| 92 | cur_arg += 2; |
| 93 | } |
| 94 | else if (!strcmp(args[cur_arg], "mode")) { |
| 95 | global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 96 | cur_arg += 2; |
| 97 | } |
| 98 | else if (!strcmp(args[cur_arg], "user")) { |
| 99 | struct passwd *user; |
| 100 | user = getpwnam(args[cur_arg + 1]); |
| 101 | if (!user) { |
| 102 | snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')", |
| 103 | args[cur_arg + 1]); |
| 104 | return -1; |
| 105 | } |
| 106 | global.stats_sock.perm.ux.uid = user->pw_uid; |
| 107 | cur_arg += 2; |
| 108 | } |
| 109 | else if (!strcmp(args[cur_arg], "group")) { |
| 110 | struct group *group; |
| 111 | group = getgrnam(args[cur_arg + 1]); |
| 112 | if (!group) { |
| 113 | snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')", |
| 114 | args[cur_arg + 1]); |
| 115 | return -1; |
| 116 | } |
| 117 | global.stats_sock.perm.ux.gid = group->gr_gid; |
| 118 | cur_arg += 2; |
| 119 | } |
| 120 | else { |
| 121 | snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', and 'mode'"); |
| 122 | return -1; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | uxst_add_listener(&global.stats_sock); |
| 127 | global.maxsock++; |
| 128 | } |
| 129 | else if (!strcmp(args[0], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 130 | unsigned timeout; |
| 131 | const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS); |
| 132 | |
| 133 | if (res) { |
| 134 | snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res); |
| 135 | return -1; |
| 136 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 137 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 138 | if (!timeout) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 139 | snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'"); |
| 140 | return -1; |
| 141 | } |
| 142 | __tv_from_ms(&global.stats_timeout, timeout); |
| 143 | } |
| 144 | else if (!strcmp(args[0], "maxconn")) { |
| 145 | int maxconn = atol(args[1]); |
| 146 | |
| 147 | if (maxconn <= 0) { |
| 148 | snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'"); |
| 149 | return -1; |
| 150 | } |
| 151 | global.maxsock -= global.stats_sock.maxconn; |
| 152 | global.stats_sock.maxconn = maxconn; |
| 153 | global.maxsock += global.stats_sock.maxconn; |
| 154 | } |
| 155 | else { |
| 156 | snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section"); |
| 157 | return -1; |
| 158 | } |
| 159 | return 0; |
| 160 | } |
| 161 | |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 162 | int print_csv_header(struct chunk *msg, int size) |
| 163 | { |
| 164 | return chunk_printf(msg, size, |
| 165 | "# pxname,svname," |
| 166 | "qcur,qmax," |
| 167 | "scur,smax,slim,stot," |
| 168 | "bin,bout," |
| 169 | "dreq,dresp," |
| 170 | "ereq,econ,eresp," |
| 171 | "wretr,wredis," |
| 172 | "status,weight,act,bck," |
| 173 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 174 | "pid,iid,sid,throttle," |
| 175 | "\n"); |
| 176 | } |
| 177 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 178 | /* |
| 179 | * Produces statistics data for the session <s>. Expects to be called with |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 180 | * s->cli_state == CL_STSHUTR. It *may* make use of informations from <uri> |
| 181 | * and <flags>. |
| 182 | * It returns 0 if it had to stop writing data and an I/O is needed, 1 if the |
| 183 | * dump is finished and the session must be closed, or -1 in case of any error. |
| 184 | */ |
| 185 | int stats_dump_raw(struct session *s, struct uri_auth *uri, int flags) |
| 186 | { |
| 187 | struct buffer *rep = s->rep; |
| 188 | struct proxy *px; |
| 189 | struct chunk msg; |
| 190 | |
| 191 | msg.len = 0; |
| 192 | msg.str = trash; |
| 193 | |
| 194 | switch (s->data_state) { |
| 195 | case DATA_ST_INIT: |
| 196 | /* the function had not been called yet, let's prepare the |
| 197 | * buffer for a response. |
| 198 | */ |
| 199 | client_retnclose(s, &msg); |
| 200 | s->data_state = DATA_ST_HEAD; |
| 201 | /* fall through */ |
| 202 | |
| 203 | case DATA_ST_HEAD: |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 204 | print_csv_header(&msg, sizeof(trash)); |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 205 | if (buffer_write_chunk(rep, &msg) != 0) |
| 206 | return 0; |
| 207 | |
| 208 | s->data_state = DATA_ST_INFO; |
| 209 | /* fall through */ |
| 210 | |
| 211 | case DATA_ST_INFO: |
| 212 | memset(&s->data_ctx, 0, sizeof(s->data_ctx)); |
| 213 | |
| 214 | s->data_ctx.stats.px = proxy; |
| 215 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 216 | s->data_state = DATA_ST_LIST; |
| 217 | /* fall through */ |
| 218 | |
| 219 | case DATA_ST_LIST: |
| 220 | /* dump proxies */ |
| 221 | while (s->data_ctx.stats.px) { |
| 222 | px = s->data_ctx.stats.px; |
| 223 | /* skip the disabled proxies and non-networked ones */ |
| 224 | if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE))) |
| 225 | if (stats_dump_proxy(s, px, NULL, 0) == 0) |
| 226 | return 0; |
| 227 | |
| 228 | s->data_ctx.stats.px = px->next; |
| 229 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 230 | } |
| 231 | /* here, we just have reached the last proxy */ |
| 232 | |
| 233 | s->data_state = DATA_ST_END; |
| 234 | /* fall through */ |
| 235 | |
| 236 | case DATA_ST_END: |
| 237 | s->data_state = DATA_ST_FIN; |
| 238 | return 1; |
| 239 | |
| 240 | case DATA_ST_FIN: |
| 241 | return 1; |
| 242 | |
| 243 | default: |
| 244 | /* unknown state ! */ |
| 245 | return -1; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | |
| 250 | /* |
| 251 | * Produces statistics data for the session <s>. Expects to be called with |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 252 | * s->cli_state == CL_STSHUTR. It stops by itself by unsetting the SN_SELF_GEN |
| 253 | * flag from the session, which it uses to keep on being called when there is |
| 254 | * free space in the buffer, of simply by letting an empty buffer upon return. |
| 255 | * It returns 0 if it had to stop writing data and an I/O is needed, 1 if the |
| 256 | * dump is finished and the session must be closed, or -1 in case of any error. |
| 257 | */ |
| 258 | int stats_dump_http(struct session *s, struct uri_auth *uri, int flags) |
| 259 | { |
| 260 | struct buffer *rep = s->rep; |
| 261 | struct proxy *px; |
| 262 | struct chunk msg; |
| 263 | unsigned int up; |
| 264 | |
| 265 | msg.len = 0; |
| 266 | msg.str = trash; |
| 267 | |
| 268 | switch (s->data_state) { |
| 269 | case DATA_ST_INIT: |
| 270 | /* the function had not been called yet */ |
| 271 | s->flags |= SN_SELF_GEN; // more data will follow |
| 272 | |
| 273 | chunk_printf(&msg, sizeof(trash), |
| 274 | "HTTP/1.0 200 OK\r\n" |
| 275 | "Cache-Control: no-cache\r\n" |
| 276 | "Connection: close\r\n" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 277 | "Content-Type: %s\r\n", |
| 278 | (flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 279 | |
| 280 | if (uri->refresh > 0 && !(s->flags & SN_STAT_NORFRSH)) |
| 281 | chunk_printf(&msg, sizeof(trash), "Refresh: %d\r\n", |
| 282 | uri->refresh); |
| 283 | |
| 284 | chunk_printf(&msg, sizeof(trash), "\r\n"); |
| 285 | |
| 286 | s->txn.status = 200; |
| 287 | client_retnclose(s, &msg); // send the start of the response. |
| 288 | msg.len = 0; |
| 289 | |
| 290 | if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is |
| 291 | s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy |
| 292 | if (!(s->flags & SN_FINST_MASK)) |
| 293 | s->flags |= SN_FINST_R; |
| 294 | |
| 295 | if (s->txn.meth == HTTP_METH_HEAD) { |
| 296 | /* that's all we return in case of HEAD request */ |
| 297 | s->data_state = DATA_ST_FIN; |
| 298 | s->flags &= ~SN_SELF_GEN; |
| 299 | return 1; |
| 300 | } |
| 301 | |
| 302 | s->data_state = DATA_ST_HEAD; /* let's start producing data */ |
| 303 | /* fall through */ |
| 304 | |
| 305 | case DATA_ST_HEAD: |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 306 | if (flags & STAT_FMT_HTML) { |
| 307 | /* WARNING! This must fit in the first buffer !!! */ |
| 308 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 309 | "<html><head><title>Statistics Report for " PRODUCT_NAME "</title>\n" |
| 310 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 311 | "<style type=\"text/css\"><!--\n" |
| 312 | "body {" |
| 313 | " font-family: helvetica, arial;" |
| 314 | " font-size: 12px;" |
| 315 | " font-weight: normal;" |
| 316 | " color: black;" |
| 317 | " background: white;" |
| 318 | "}\n" |
| 319 | "th,td {" |
| 320 | " font-size: 0.8em;" |
| 321 | " align: center;" |
| 322 | "}\n" |
| 323 | "h1 {" |
| 324 | " font-size: xx-large;" |
| 325 | " margin-bottom: 0.5em;" |
| 326 | "}\n" |
| 327 | "h2 {" |
| 328 | " font-family: helvetica, arial;" |
| 329 | " font-size: x-large;" |
| 330 | " font-weight: bold;" |
| 331 | " font-style: italic;" |
| 332 | " color: #6020a0;" |
| 333 | " margin-top: 0em;" |
| 334 | " margin-bottom: 0em;" |
| 335 | "}\n" |
| 336 | "h3 {" |
| 337 | " font-family: helvetica, arial;" |
| 338 | " font-size: 16px;" |
| 339 | " font-weight: bold;" |
| 340 | " color: #b00040;" |
| 341 | " background: #e8e8d0;" |
| 342 | " margin-top: 0em;" |
| 343 | " margin-bottom: 0em;" |
| 344 | "}\n" |
| 345 | "li {" |
| 346 | " margin-top: 0.25em;" |
| 347 | " margin-right: 2em;" |
| 348 | "}\n" |
| 349 | ".hr {margin-top: 0.25em;" |
| 350 | " border-color: black;" |
| 351 | " border-bottom-style: solid;" |
| 352 | "}\n" |
| 353 | ".pxname {background: #b00040;color: #ffff40;font-weight: bold;}\n" |
| 354 | ".titre {background: #20D0D0;color: #000000;font-weight: bold;}\n" |
| 355 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 356 | ".frontend {background: #e8e8d0;}\n" |
| 357 | ".backend {background: #e8e8d0;}\n" |
| 358 | ".active0 {background: #ff9090;}\n" |
| 359 | ".active1 {background: #ffd020;}\n" |
| 360 | ".active2 {background: #ffffa0;}\n" |
| 361 | ".active3 {background: #c0ffc0;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 362 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 363 | ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */ |
| 364 | ".active6 {background: #e0e0e0;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 365 | ".backup0 {background: #ff9090;}\n" |
| 366 | ".backup1 {background: #ff80ff;}\n" |
| 367 | ".backup2 {background: #c060ff;}\n" |
| 368 | ".backup3 {background: #b0d0ff;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 369 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 370 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 371 | ".backup6 {background: #e0e0e0;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 372 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 373 | "table.tbl td { border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray;}\n" |
| 374 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 375 | "table.tbl th.empty { border-style: none; empty-cells: hide;}\n" |
| 376 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 377 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 378 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
| 379 | "-->\n" |
| 380 | "</style></head>\n"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 381 | } else { |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 382 | print_csv_header(&msg, sizeof(trash)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 383 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 384 | if (buffer_write_chunk(rep, &msg) != 0) |
| 385 | return 0; |
| 386 | |
| 387 | s->data_state = DATA_ST_INFO; |
| 388 | /* fall through */ |
| 389 | |
| 390 | case DATA_ST_INFO: |
| 391 | up = (now.tv_sec - start_date.tv_sec); |
| 392 | |
| 393 | /* WARNING! this has to fit the first packet too. |
| 394 | * We are around 3.5 kB, add adding entries will |
| 395 | * become tricky if we want to support 4kB buffers ! |
| 396 | */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 397 | if (flags & STAT_FMT_HTML) { |
| 398 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 399 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 400 | PRODUCT_NAME "%s</a></h1>\n" |
| 401 | "<h2>Statistics Report for pid %d</h2>\n" |
| 402 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 403 | "<h3>> General process information</h3>\n" |
| 404 | "<table border=0 cols=4><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 405 | "<p><b>pid = </b> %d (nbproc = %d)<br>\n" |
| 406 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 407 | "<b>system limits :</b> memmax = %s%s ; ulimit-n = %d<br>\n" |
| 408 | "<b>maxsock = </b> %d<br>\n" |
| 409 | "<b>maxconn = </b> %d (current conns = %d)<br>\n" |
| 410 | "</td><td align=\"center\" nowrap>\n" |
| 411 | "<table class=\"lgd\"><tr>\n" |
| 412 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 413 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 414 | "</tr><tr>\n" |
| 415 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 416 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 417 | "</tr><tr>\n" |
| 418 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 419 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 420 | "</tr><tr>\n" |
| 421 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 422 | "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 423 | "</tr></table>\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 424 | "Note: UP with load-balancing disabled is reported as \"NOLB\"." |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 425 | "</td>" |
| 426 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 427 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 428 | "", |
| 429 | (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING), |
| 430 | pid, pid, global.nbproc, |
| 431 | up / 86400, (up % 86400) / 3600, |
| 432 | (up % 3600) / 60, (up % 60), |
| 433 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 434 | global.rlimit_memmax ? " MB" : "", |
| 435 | global.rlimit_nofile, |
| 436 | global.maxsock, |
| 437 | global.maxconn, |
| 438 | actconn |
| 439 | ); |
| 440 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 441 | if (s->flags & SN_STAT_HIDEDWN) |
| 442 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 443 | "<li><a href=\"%s%s%s\">Show all servers</a><br>\n", |
| 444 | uri->uri_prefix, |
| 445 | "", |
| 446 | (s->flags & SN_STAT_NORFRSH) ? ";norefresh" : ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 447 | else |
| 448 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 449 | "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 450 | uri->uri_prefix, |
| 451 | ";up", |
| 452 | (s->flags & SN_STAT_NORFRSH) ? ";norefresh" : ""); |
| 453 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 454 | if (uri->refresh > 0) { |
| 455 | if (s->flags & SN_STAT_NORFRSH) |
| 456 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 457 | "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n", |
| 458 | uri->uri_prefix, |
| 459 | (s->flags & SN_STAT_HIDEDWN) ? ";up" : "", |
| 460 | ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 461 | else |
| 462 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 463 | "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n", |
| 464 | uri->uri_prefix, |
| 465 | (s->flags & SN_STAT_HIDEDWN) ? ";up" : "", |
| 466 | ";norefresh"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 467 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 468 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 469 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 470 | "<li><a href=\"%s%s%s\">Refresh now</a><br>\n", |
| 471 | uri->uri_prefix, |
| 472 | (s->flags & SN_STAT_HIDEDWN) ? ";up" : "", |
| 473 | (s->flags & SN_STAT_NORFRSH) ? ";norefresh" : ""); |
| 474 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 475 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 476 | "<li><a href=\"%s;csv%s\">CSV export</a><br>\n", |
| 477 | uri->uri_prefix, |
| 478 | (uri->refresh > 0) ? ";norefresh" : ""); |
| 479 | |
| 480 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 481 | "</td>" |
| 482 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 483 | "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 484 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 485 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 486 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 487 | "</ul>" |
| 488 | "</td>" |
| 489 | "</tr></table>\n" |
| 490 | "" |
| 491 | ); |
| 492 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 493 | if (buffer_write_chunk(rep, &msg) != 0) |
| 494 | return 0; |
| 495 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 496 | |
| 497 | memset(&s->data_ctx, 0, sizeof(s->data_ctx)); |
| 498 | |
| 499 | s->data_ctx.stats.px = proxy; |
| 500 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 501 | s->data_state = DATA_ST_LIST; |
| 502 | /* fall through */ |
| 503 | |
| 504 | case DATA_ST_LIST: |
| 505 | /* dump proxies */ |
| 506 | while (s->data_ctx.stats.px) { |
| 507 | px = s->data_ctx.stats.px; |
| 508 | /* skip the disabled proxies and non-networked ones */ |
| 509 | if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE))) |
| 510 | if (stats_dump_proxy(s, px, uri, flags) == 0) |
| 511 | return 0; |
| 512 | |
| 513 | s->data_ctx.stats.px = px->next; |
| 514 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 515 | } |
| 516 | /* here, we just have reached the last proxy */ |
| 517 | |
| 518 | s->data_state = DATA_ST_END; |
| 519 | /* fall through */ |
| 520 | |
| 521 | case DATA_ST_END: |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 522 | if (flags & STAT_FMT_HTML) { |
| 523 | chunk_printf(&msg, sizeof(trash), "</body></html>\n"); |
| 524 | if (buffer_write_chunk(rep, &msg) != 0) |
| 525 | return 0; |
| 526 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 527 | |
| 528 | s->data_state = DATA_ST_FIN; |
| 529 | /* fall through */ |
| 530 | |
| 531 | case DATA_ST_FIN: |
| 532 | s->flags &= ~SN_SELF_GEN; |
| 533 | return 1; |
| 534 | |
| 535 | default: |
| 536 | /* unknown state ! */ |
| 537 | s->flags &= ~SN_SELF_GEN; |
| 538 | return -1; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | |
| 543 | /* |
| 544 | * Dumps statistics for a proxy. |
| 545 | * Returns 0 if it had to stop dumping data because of lack of buffer space, |
| 546 | * ot non-zero if everything completed. |
| 547 | */ |
| 548 | int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri, int flags) |
| 549 | { |
| 550 | struct buffer *rep = s->rep; |
| 551 | struct server *sv; |
| 552 | struct chunk msg; |
| 553 | |
| 554 | msg.len = 0; |
| 555 | msg.str = trash; |
| 556 | |
| 557 | switch (s->data_ctx.stats.px_st) { |
| 558 | case DATA_ST_PX_INIT: |
| 559 | /* we are on a new proxy */ |
| 560 | |
| 561 | if (uri && uri->scope) { |
| 562 | /* we have a limited scope, we have to check the proxy name */ |
| 563 | struct stat_scope *scope; |
| 564 | int len; |
| 565 | |
| 566 | len = strlen(px->id); |
| 567 | scope = uri->scope; |
| 568 | |
| 569 | while (scope) { |
| 570 | /* match exact proxy name */ |
| 571 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 572 | break; |
| 573 | |
| 574 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 575 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 576 | break; |
| 577 | scope = scope->next; |
| 578 | } |
| 579 | |
| 580 | /* proxy name not found : don't dump anything */ |
| 581 | if (scope == NULL) |
| 582 | return 1; |
| 583 | } |
| 584 | |
| 585 | s->data_ctx.stats.px_st = DATA_ST_PX_TH; |
| 586 | /* fall through */ |
| 587 | |
| 588 | case DATA_ST_PX_TH: |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 589 | if (flags & STAT_FMT_HTML) { |
| 590 | /* print a new table */ |
| 591 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 592 | "<table cols=\"25\" class=\"tbl\" width=\"100%%\">\n" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 593 | "<tr align=\"center\" class=\"titre\">" |
| 594 | "<th colspan=2 class=\"pxname\">%s</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 595 | "<th colspan=22 class=\"empty\"></th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 596 | "</tr>\n" |
| 597 | "<tr align=\"center\" class=\"titre\">" |
| 598 | "<th rowspan=2></th>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 599 | "<th colspan=3>Queue</th><th colspan=4>Sessions</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 600 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 601 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 602 | "<th colspan=8>Server</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 603 | "</tr>\n" |
| 604 | "<tr align=\"center\" class=\"titre\">" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 605 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 606 | "<th>Limit</th><th>Cumul</th><th>In</th><th>Out</th>" |
| 607 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 608 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 609 | "<th>Status</th><th>Wght</th><th>Act</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 610 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 611 | "<th>Thrtle</th>\n" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 612 | "</tr>", |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 613 | px->id); |
| 614 | |
| 615 | if (buffer_write_chunk(rep, &msg) != 0) |
| 616 | return 0; |
| 617 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 618 | |
| 619 | s->data_ctx.stats.px_st = DATA_ST_PX_FE; |
| 620 | /* fall through */ |
| 621 | |
| 622 | case DATA_ST_PX_FE: |
| 623 | /* print the frontend */ |
| 624 | if (px->cap & PR_CAP_FE) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 625 | if (flags & STAT_FMT_HTML) { |
| 626 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 627 | /* name, queue */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 628 | "<tr align=center class=\"frontend\"><td>Frontend</td><td colspan=3></td>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 629 | /* sessions : current, max, limit, cumul */ |
| 630 | "<td align=right>%d</td><td align=right>%d</td>" |
| 631 | "<td align=right>%d</td><td align=right>%d</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 632 | /* bytes : in, out */ |
| 633 | "<td align=right>%lld</td><td align=right>%lld</td>" |
| 634 | /* denied: req, resp */ |
| 635 | "<td align=right>%d</td><td align=right>%d</td>" |
| 636 | /* errors : request, connect, response */ |
| 637 | "<td align=right>%d</td><td align=right></td><td align=right></td>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 638 | /* warnings: retries, redispatches */ |
| 639 | "<td align=right></td><td align=right></td>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 640 | /* server status : reflect frontend status */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 641 | "<td align=center>%s</td>" |
| 642 | /* rest of server: nothing */ |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 643 | "<td align=center colspan=7></td></tr>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 644 | "", |
| 645 | px->feconn, px->feconn_max, px->maxconn, px->cum_feconn, |
| 646 | px->bytes_in, px->bytes_out, |
| 647 | px->denied_req, px->denied_resp, |
| 648 | px->failed_req, |
| 649 | px->state == PR_STRUN ? "OPEN" : |
| 650 | px->state == PR_STIDLE ? "FULL" : "STOP"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 651 | } else { |
| 652 | chunk_printf(&msg, sizeof(trash), |
| 653 | /* pxid, name, queue cur, queue max, */ |
| 654 | "%s,FRONTEND,,," |
| 655 | /* sessions : current, max, limit, cumul */ |
| 656 | "%d,%d,%d,%d," |
| 657 | /* bytes : in, out */ |
| 658 | "%lld,%lld," |
| 659 | /* denied: req, resp */ |
| 660 | "%d,%d," |
| 661 | /* errors : request, connect, response */ |
| 662 | "%d,,," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 663 | /* warnings: retries, redispatches */ |
| 664 | ",," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 665 | /* server status : reflect frontend status */ |
| 666 | "%s," |
| 667 | /* rest of server: nothing */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 668 | ",,,,,,,," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 669 | /* pid, iid, sid, throttle, */ |
| 670 | "%d,%d,0,," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 671 | "\n", |
| 672 | px->id, |
| 673 | px->feconn, px->feconn_max, px->maxconn, px->cum_feconn, |
| 674 | px->bytes_in, px->bytes_out, |
| 675 | px->denied_req, px->denied_resp, |
| 676 | px->failed_req, |
| 677 | px->state == PR_STRUN ? "OPEN" : |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 678 | px->state == PR_STIDLE ? "FULL" : "STOP", |
| 679 | relative_pid, px->uuid); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 680 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 681 | |
| 682 | if (buffer_write_chunk(rep, &msg) != 0) |
| 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | s->data_ctx.stats.sv = px->srv; /* may be NULL */ |
| 687 | s->data_ctx.stats.px_st = DATA_ST_PX_SV; |
| 688 | /* fall through */ |
| 689 | |
| 690 | case DATA_ST_PX_SV: |
| 691 | /* stats.sv has been initialized above */ |
| 692 | while (s->data_ctx.stats.sv != NULL) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 693 | 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] | 694 | |
| 695 | sv = s->data_ctx.stats.sv; |
| 696 | |
| 697 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
| 698 | if (!(sv->state & SRV_CHECKED)) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 699 | sv_state = 6; |
| 700 | else if (sv->state & SRV_RUNNING) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 701 | if (sv->health == sv->rise + sv->fall - 1) |
| 702 | sv_state = 3; /* UP */ |
| 703 | else |
| 704 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 705 | |
| 706 | if (sv->state & SRV_GOINGDOWN) |
| 707 | sv_state += 2; |
| 708 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 709 | else |
| 710 | if (sv->health) |
| 711 | sv_state = 1; /* going up */ |
| 712 | else |
| 713 | sv_state = 0; /* DOWN */ |
| 714 | |
| 715 | if ((sv_state == 0) && (s->flags & SN_STAT_HIDEDWN)) { |
| 716 | /* do not report servers which are DOWN */ |
| 717 | s->data_ctx.stats.sv = sv->next; |
| 718 | continue; |
| 719 | } |
| 720 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 721 | if (flags & STAT_FMT_HTML) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 722 | static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d ↑", |
| 723 | "UP %d/%d ↓", "UP", |
| 724 | "NOLB %d/%d ↓", "NOLB", |
| 725 | "<i>no check</i>" }; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 726 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 727 | /* name */ |
| 728 | "<tr align=\"center\" class=\"%s%d\"><td>%s</td>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 729 | /* queue : current, max, limit */ |
| 730 | "<td align=right>%d</td><td align=right>%d</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 731 | /* sessions : current, max, limit, cumul */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 732 | "<td align=right>%d</td><td align=right>%d</td>" |
| 733 | "<td align=right>%s</td><td align=right>%d</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 734 | /* bytes : in, out */ |
| 735 | "<td align=right>%lld</td><td align=right>%lld</td>" |
| 736 | /* denied: req, resp */ |
| 737 | "<td align=right></td><td align=right>%d</td>" |
| 738 | /* errors : request, connect, response */ |
| 739 | "<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 740 | /* warnings: retries, redispatches */ |
| 741 | "<td align=right>%d</td><td align=right></td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 742 | "", |
| 743 | (sv->state & SRV_BACKUP) ? "backup" : "active", |
| 744 | sv_state, sv->id, |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 745 | sv->nbpend, sv->nbpend_max, LIM2A0(sv->maxqueue, "-"), |
| 746 | sv->cur_sess, sv->cur_sess_max, LIM2A1(sv->maxconn, "-"), sv->cum_sess, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 747 | sv->bytes_in, sv->bytes_out, |
| 748 | sv->failed_secu, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 749 | sv->failed_conns, sv->failed_resp, |
| 750 | sv->retries); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 751 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 752 | /* status */ |
| 753 | chunk_printf(&msg, sizeof(trash), "<td nowrap>"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 754 | |
| 755 | if (sv->state & SRV_CHECKED) |
| 756 | chunk_printf(&msg, sizeof(trash), "%s ", |
| 757 | human_time(now.tv_sec - sv->last_change, 1)); |
| 758 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 759 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 760 | srv_hlt_st[sv_state], |
| 761 | (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health), |
| 762 | (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise)); |
| 763 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 764 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 765 | /* weight */ |
| 766 | "</td><td>%d</td>" |
| 767 | /* act, bck */ |
| 768 | "<td>%s</td><td>%s</td>" |
| 769 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame^] | 770 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 771 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 772 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 773 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 774 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 775 | if (sv->state & SRV_CHECKED) |
| 776 | chunk_printf(&msg, sizeof(trash), |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 777 | "<td align=right>%d</td><td align=right>%d</td>" |
| 778 | "<td nowrap align=right>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 779 | "", |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 780 | sv->failed_checks, sv->down_trans, |
| 781 | human_time(srv_downtime(sv), 1)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 782 | else |
| 783 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 784 | "<td colspan=3></td>"); |
| 785 | |
| 786 | /* throttle */ |
| 787 | if ((sv->state & SRV_WARMINGUP) && |
| 788 | now.tv_sec < sv->last_change + sv->slowstart && |
| 789 | now.tv_sec >= sv->last_change) { |
| 790 | unsigned int ratio; |
| 791 | ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); |
| 792 | chunk_printf(&msg, sizeof(trash), |
| 793 | "<td>%d %%</td></tr>\n", ratio); |
| 794 | } else { |
| 795 | chunk_printf(&msg, sizeof(trash), |
| 796 | "<td>-</td></tr>\n"); |
| 797 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 798 | } else { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 799 | static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,", |
| 800 | "UP %d/%d,", "UP,", |
| 801 | "NOLB %d/%d,", "NOLB,", |
| 802 | "no check," }; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 803 | chunk_printf(&msg, sizeof(trash), |
| 804 | /* pxid, name */ |
| 805 | "%s,%s," |
| 806 | /* queue : current, max */ |
| 807 | "%d,%d," |
| 808 | /* sessions : current, max, limit, cumul */ |
| 809 | "%d,%d,%s,%d," |
| 810 | /* bytes : in, out */ |
| 811 | "%lld,%lld," |
| 812 | /* denied: req, resp */ |
| 813 | ",%d," |
| 814 | /* errors : request, connect, response */ |
| 815 | ",%d,%d," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 816 | /* warnings: retries, redispatches */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 817 | "%d,," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 818 | "", |
| 819 | px->id, sv->id, |
| 820 | sv->nbpend, sv->nbpend_max, |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 821 | 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] | 822 | sv->bytes_in, sv->bytes_out, |
| 823 | sv->failed_secu, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 824 | sv->failed_conns, sv->failed_resp, |
| 825 | sv->retries); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 826 | |
| 827 | /* status */ |
| 828 | chunk_printf(&msg, sizeof(trash), |
| 829 | srv_hlt_st[sv_state], |
| 830 | (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health), |
| 831 | (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 832 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 833 | chunk_printf(&msg, sizeof(trash), |
| 834 | /* weight, active, backup */ |
| 835 | "%d,%d,%d," |
| 836 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame^] | 837 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 838 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 839 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 840 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 841 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 842 | if (sv->state & SRV_CHECKED) |
| 843 | chunk_printf(&msg, sizeof(trash), |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 844 | "%d,%d,%d,%d,", |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 845 | sv->failed_checks, sv->down_trans, |
| 846 | now.tv_sec - sv->last_change, srv_downtime(sv)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 847 | else |
| 848 | chunk_printf(&msg, sizeof(trash), |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 849 | ",,,,"); |
| 850 | |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 851 | /* queue limit, pid, iid, sid, */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 852 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 853 | "%s," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 854 | "%d,%d,%d,", |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 855 | LIM2A0(sv->maxqueue, ""), |
| 856 | relative_pid, px->uuid, sv->puid); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 857 | |
| 858 | /* throttle */ |
| 859 | if ((sv->state & SRV_WARMINGUP) && |
| 860 | now.tv_sec < sv->last_change + sv->slowstart && |
| 861 | now.tv_sec >= sv->last_change) { |
| 862 | unsigned int ratio; |
| 863 | ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); |
| 864 | chunk_printf(&msg, sizeof(trash), "%d", ratio); |
| 865 | } |
| 866 | |
| 867 | /* ',' then EOL */ |
| 868 | chunk_printf(&msg, sizeof(trash), ",\n"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 869 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 870 | if (buffer_write_chunk(rep, &msg) != 0) |
| 871 | return 0; |
| 872 | |
| 873 | s->data_ctx.stats.sv = sv->next; |
| 874 | } /* while sv */ |
| 875 | |
| 876 | s->data_ctx.stats.px_st = DATA_ST_PX_BE; |
| 877 | /* fall through */ |
| 878 | |
| 879 | case DATA_ST_PX_BE: |
| 880 | /* print the backend */ |
| 881 | if (px->cap & PR_CAP_BE) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 882 | if (flags & STAT_FMT_HTML) { |
| 883 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 884 | /* name */ |
| 885 | "<tr align=center class=\"backend\"><td>Backend</td>" |
| 886 | /* queue : current, max */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 887 | "<td align=right>%d</td><td align=right>%d</td><td></td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 888 | /* sessions : current, max, limit, cumul. */ |
| 889 | "<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td><td align=right>%d</td>" |
| 890 | /* bytes : in, out */ |
| 891 | "<td align=right>%lld</td><td align=right>%lld</td>" |
| 892 | /* denied: req, resp */ |
| 893 | "<td align=right>%d</td><td align=right>%d</td>" |
| 894 | /* errors : request, connect, response */ |
| 895 | "<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 896 | /* warnings: retries, redispatches */ |
| 897 | "<td align=right>%d</td><td align=right>%d</td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 898 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 899 | * 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] | 900 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 901 | * active and backups. */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 902 | "<td align=center nowrap>%s %s</td><td align=center>%d</td>" |
| 903 | "<td align=center>%d</td><td align=center>%d</td>", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 904 | px->nbpend /* or px->totpend ? */, px->nbpend_max, |
| 905 | px->beconn, px->beconn_max, px->fullconn, px->cum_beconn, |
| 906 | px->bytes_in, px->bytes_out, |
| 907 | px->denied_req, px->denied_resp, |
| 908 | px->failed_conns, px->failed_resp, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 909 | px->retries, px->redispatches, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 910 | human_time(now.tv_sec - px->last_change, 1), |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 911 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 912 | "<font color=\"red\"><b>DOWN</b></font>", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame^] | 913 | (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] | 914 | px->srv_act, px->srv_bck); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 915 | |
| 916 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 917 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 918 | "<td align=center> </td><td align=\"right\">%d</td>" |
| 919 | "<td align=\"right\" nowrap>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 920 | "<td></td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 921 | "</tr>", |
| 922 | px->down_trans, |
| 923 | px->srv?human_time(be_downtime(px), 1):" "); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 924 | } else { |
| 925 | chunk_printf(&msg, sizeof(trash), |
| 926 | /* pxid, name */ |
| 927 | "%s,BACKEND," |
| 928 | /* queue : current, max */ |
| 929 | "%d,%d," |
| 930 | /* sessions : current, max, limit, cumul */ |
| 931 | "%d,%d,%d,%d," |
| 932 | /* bytes : in, out */ |
| 933 | "%lld,%lld," |
| 934 | /* denied: req, resp */ |
| 935 | "%d,%d," |
| 936 | /* errors : request, connect, response */ |
| 937 | ",%d,%d," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 938 | /* warnings: retries, redispatches */ |
| 939 | "%d,%d," |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 940 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 941 | * 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] | 942 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 943 | * active and backups. */ |
| 944 | "%s," |
| 945 | "%d,%d,%d," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 946 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 947 | ",%d,%d,%d,," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 948 | /* pid, iid, sid, throttle, */ |
| 949 | "%d,%d,0,," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 950 | "\n", |
| 951 | px->id, |
| 952 | px->nbpend /* or px->totpend ? */, px->nbpend_max, |
| 953 | px->beconn, px->beconn_max, px->fullconn, px->cum_beconn, |
| 954 | px->bytes_in, px->bytes_out, |
| 955 | px->denied_req, px->denied_resp, |
| 956 | px->failed_conns, px->failed_resp, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 957 | px->retries, px->redispatches, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 958 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame^] | 959 | (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] | 960 | px->srv_act, px->srv_bck, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 961 | px->down_trans, now.tv_sec - px->last_change, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 962 | px->srv?be_downtime(px):0, |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 963 | relative_pid, px->uuid); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 964 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 965 | if (buffer_write_chunk(rep, &msg) != 0) |
| 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | s->data_ctx.stats.px_st = DATA_ST_PX_END; |
| 970 | /* fall through */ |
| 971 | |
| 972 | case DATA_ST_PX_END: |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 973 | if (flags & STAT_FMT_HTML) { |
| 974 | chunk_printf(&msg, sizeof(trash), "</table><p>\n"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 975 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 976 | if (buffer_write_chunk(rep, &msg) != 0) |
| 977 | return 0; |
| 978 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 979 | |
| 980 | s->data_ctx.stats.px_st = DATA_ST_PX_FIN; |
| 981 | /* fall through */ |
| 982 | |
| 983 | case DATA_ST_PX_FIN: |
| 984 | return 1; |
| 985 | |
| 986 | default: |
| 987 | /* unknown state, we should put an abort() here ! */ |
| 988 | return 1; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | /* |
| 993 | * Local variables: |
| 994 | * c-indent-level: 8 |
| 995 | * c-basic-offset: 8 |
| 996 | * End: |
| 997 | */ |