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