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