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