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