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