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