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