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