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