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