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