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