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