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