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