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