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