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