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