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 | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 27 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 28 | #include <common/compat.h> |
| 29 | #include <common/config.h> |
| 30 | #include <common/debug.h> |
| 31 | #include <common/memory.h> |
| 32 | #include <common/mini-clist.h> |
| 33 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 34 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 35 | #include <common/time.h> |
| 36 | #include <common/uri_auth.h> |
| 37 | #include <common/version.h> |
| 38 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | |
| 41 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 42 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 43 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 44 | #include <proto/compression.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 | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 51 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 52 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 53 | #include <proto/proxy.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 54 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 55 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 56 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 57 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 58 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 59 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 60 | #ifdef USE_OPENSSL |
| 61 | #include <proto/ssl_sock.h> |
| 62 | #endif |
| 63 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 64 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 65 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 66 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 67 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 68 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 69 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 70 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 71 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 72 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 73 | * cli_io_handler() |
| 74 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 75 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 76 | * -> stats_dump_info_to_buffer() // "show info" |
| 77 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 78 | * -> stats_dump_csv_header() |
| 79 | * -> stats_dump_proxy_to_buffer() |
| 80 | * -> stats_dump_fe_stats() |
| 81 | * -> stats_dump_li_stats() |
| 82 | * -> stats_dump_sv_stats() |
| 83 | * -> stats_dump_be_stats() |
| 84 | * |
| 85 | * http_stats_io_handler() |
| 86 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 87 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 88 | * -> stats_dump_html_head() // emits the HTML headers |
| 89 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 90 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 91 | * -> stats_dump_html_px_hdr() |
| 92 | * -> stats_dump_fe_stats() |
| 93 | * -> stats_dump_li_stats() |
| 94 | * -> stats_dump_sv_stats() |
| 95 | * -> stats_dump_be_stats() |
| 96 | * -> stats_dump_html_px_end() |
| 97 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 98 | */ |
| 99 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 100 | static struct si_applet cli_applet; |
| 101 | |
| 102 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 103 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 104 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 105 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 106 | " help : this message\n" |
| 107 | " prompt : toggle interactive mode with prompt\n" |
| 108 | " quit : disconnect\n" |
| 109 | " show info : report information about the running process\n" |
| 110 | " show stat : report counters for each proxy and server\n" |
| 111 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 112 | " 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] | 113 | " 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] | 114 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 115 | " set weight : change a server's weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 116 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 117 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 118 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 119 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 120 | " disable : put a server or frontend in maintenance mode\n" |
| 121 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 122 | " 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] | 123 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 124 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 125 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 126 | "Permission denied\n" |
| 127 | ""; |
| 128 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 129 | /* data transmission states for the stats responses */ |
| 130 | enum { |
| 131 | STAT_ST_INIT = 0, |
| 132 | STAT_ST_HEAD, |
| 133 | STAT_ST_INFO, |
| 134 | STAT_ST_LIST, |
| 135 | STAT_ST_END, |
| 136 | STAT_ST_FIN, |
| 137 | }; |
| 138 | |
| 139 | /* data transmission states for the stats responses inside a proxy */ |
| 140 | enum { |
| 141 | STAT_PX_ST_INIT = 0, |
| 142 | STAT_PX_ST_TH, |
| 143 | STAT_PX_ST_FE, |
| 144 | STAT_PX_ST_LI, |
| 145 | STAT_PX_ST_SV, |
| 146 | STAT_PX_ST_BE, |
| 147 | STAT_PX_ST_END, |
| 148 | STAT_PX_ST_FIN, |
| 149 | }; |
| 150 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 151 | extern const char *stat_status_codes[]; |
| 152 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 153 | /* This function is called from the session-level accept() in order to instanciate |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 154 | * a new stats socket. It returns a positive value upon success, 0 if the session |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 155 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 156 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 157 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 158 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 159 | s->target = &cli_applet.obj_type; |
Willy Tarreau | 4171e9e | 2013-12-01 12:32:30 +0100 | [diff] [blame] | 160 | /* no need to initialize the applet, it will start with st0=st1 = 0 */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 161 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 162 | tv_zero(&s->logs.tv_request); |
| 163 | s->logs.t_queue = 0; |
| 164 | s->logs.t_connect = 0; |
| 165 | s->logs.t_data = 0; |
| 166 | s->logs.t_close = 0; |
| 167 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 168 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 169 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 170 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 171 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 172 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 173 | if (s->listener->timeout) { |
| 174 | s->req->rto = *s->listener->timeout; |
| 175 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 176 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 177 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 180 | /* allocate a new stats frontend named <name>, and return it |
| 181 | * (or NULL in case of lack of memory). |
| 182 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 183 | 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] | 184 | { |
| 185 | struct proxy *fe; |
| 186 | |
| 187 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 188 | if (!fe) |
| 189 | return NULL; |
| 190 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 191 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 192 | fe->next = proxy; |
| 193 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 194 | fe->last_change = now.tv_sec; |
| 195 | fe->id = strdup("GLOBAL"); |
| 196 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 197 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 198 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 199 | fe->conf.file = strdup(file); |
| 200 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 201 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 202 | |
| 203 | /* the stats frontend is the only one able to assign ID #0 */ |
| 204 | fe->conf.id.key = fe->uuid = 0; |
| 205 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 206 | return fe; |
| 207 | } |
| 208 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 209 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 210 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 211 | * error message into the <err> buffer which will be preallocated. The trailing |
| 212 | * '\n' must not be written. The function must be called with <args> pointing to |
| 213 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 214 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 215 | 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] | 216 | struct proxy *defpx, const char *file, int line, |
| 217 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 218 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 219 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 220 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 221 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 222 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 223 | int cur_arg; |
| 224 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 225 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 226 | 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] | 227 | return -1; |
| 228 | } |
| 229 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 230 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 231 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 232 | 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] | 233 | return -1; |
| 234 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 235 | } |
| 236 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 237 | 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] | 238 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 239 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 240 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 241 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 242 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 243 | return -1; |
| 244 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 245 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 246 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 247 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 248 | static int bind_dumped; |
| 249 | struct bind_kw *kw; |
| 250 | |
| 251 | kw = bind_find_kw(args[cur_arg]); |
| 252 | if (kw) { |
| 253 | if (!kw->parse) { |
| 254 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 255 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 256 | return -1; |
| 257 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 258 | |
| 259 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 260 | if (err && *err) |
| 261 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 262 | else |
| 263 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 264 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 265 | return -1; |
| 266 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 267 | |
| 268 | cur_arg += 1 + kw->skip; |
| 269 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 270 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 271 | |
| 272 | if (!bind_dumped) { |
| 273 | bind_dump_kws(err); |
| 274 | indent_msg(err, 4); |
| 275 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 276 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 277 | |
| 278 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 279 | args[0], args[1], args[cur_arg], |
| 280 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 281 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 282 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 283 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 284 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 285 | l->maxconn = global.stats_fe->maxconn; |
| 286 | l->backlog = global.stats_fe->backlog; |
| 287 | l->timeout = &global.stats_fe->timeout.client; |
| 288 | l->accept = session_accept; |
| 289 | l->handler = process_session; |
| 290 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 291 | l->nice = -64; /* we want to boost priority for local stats */ |
| 292 | global.maxsock += l->maxconn; |
| 293 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 294 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 295 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 296 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 297 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 298 | |
| 299 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 300 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 301 | return -1; |
| 302 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 303 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 304 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 305 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 306 | return -1; |
| 307 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 308 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 309 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 310 | 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] | 311 | return -1; |
| 312 | } |
| 313 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 314 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 315 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 316 | else if (!strcmp(args[1], "maxconn")) { |
| 317 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 318 | |
| 319 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 320 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 321 | return -1; |
| 322 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 323 | |
| 324 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 325 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 326 | 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] | 327 | return -1; |
| 328 | } |
| 329 | } |
| 330 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 331 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 332 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 333 | int cur_arg = 2; |
| 334 | unsigned int set = 0; |
| 335 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 336 | if (!global.stats_fe) { |
| 337 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 338 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 339 | return -1; |
| 340 | } |
| 341 | } |
| 342 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 343 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 344 | unsigned int low, high; |
| 345 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 346 | if (strcmp(args[cur_arg], "all") == 0) { |
| 347 | set = 0; |
| 348 | break; |
| 349 | } |
| 350 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 351 | set |= 0x55555555; |
| 352 | } |
| 353 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 354 | set |= 0xAAAAAAAA; |
| 355 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 356 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 357 | char *dash = strchr(args[cur_arg], '-'); |
| 358 | |
| 359 | low = high = str2uic(args[cur_arg]); |
| 360 | if (dash) |
| 361 | high = str2uic(dash + 1); |
| 362 | |
| 363 | if (high < low) { |
| 364 | unsigned int swap = low; |
| 365 | low = high; |
| 366 | high = swap; |
| 367 | } |
| 368 | |
| 369 | if (low < 1 || high > 32) { |
| 370 | memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n", |
| 371 | args[0], args[1]); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 372 | return -1; |
| 373 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 374 | |
| 375 | while (low <= high) |
| 376 | set |= 1 << (low++ - 1); |
| 377 | } |
| 378 | else { |
| 379 | memprintf(err, |
| 380 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 381 | args[0], args[1]); |
| 382 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 383 | } |
| 384 | cur_arg++; |
| 385 | } |
| 386 | global.stats_fe->bind_proc = set; |
| 387 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 388 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 389 | memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 390 | return -1; |
| 391 | } |
| 392 | return 0; |
| 393 | } |
| 394 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 395 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 396 | * for clearing it if needed. |
| 397 | */ |
| 398 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 399 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 400 | chunk_appendf(&trash, |
| 401 | "# pxname,svname," |
| 402 | "qcur,qmax," |
| 403 | "scur,smax,slim,stot," |
| 404 | "bin,bout," |
| 405 | "dreq,dresp," |
| 406 | "ereq,econ,eresp," |
| 407 | "wretr,wredis," |
| 408 | "status,weight,act,bck," |
| 409 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 410 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 411 | "rate,rate_lim,rate_max," |
| 412 | "check_status,check_code,check_duration," |
| 413 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 414 | "req_rate,req_rate_max,req_tot," |
| 415 | "cli_abrt,srv_abrt," |
| 416 | "comp_in,comp_out,comp_byp,comp_rsp," |
| 417 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 418 | } |
| 419 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 420 | /* print a string of text buffer to <out>. The format is : |
| 421 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 422 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 423 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 424 | */ |
| 425 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 426 | { |
| 427 | unsigned char c; |
| 428 | int ptr = 0; |
| 429 | |
| 430 | while (buf[ptr] && ptr < bsize) { |
| 431 | c = buf[ptr]; |
| 432 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 433 | if (out->len > out->size - 1) |
| 434 | break; |
| 435 | out->str[out->len++] = c; |
| 436 | } |
| 437 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 438 | if (out->len > out->size - 2) |
| 439 | break; |
| 440 | out->str[out->len++] = '\\'; |
| 441 | switch (c) { |
| 442 | case ' ': c = ' '; break; |
| 443 | case '\t': c = 't'; break; |
| 444 | case '\n': c = 'n'; break; |
| 445 | case '\r': c = 'r'; break; |
| 446 | case '\e': c = 'e'; break; |
| 447 | case '\\': c = '\\'; break; |
| 448 | } |
| 449 | out->str[out->len++] = c; |
| 450 | } |
| 451 | else { |
| 452 | if (out->len > out->size - 4) |
| 453 | break; |
| 454 | out->str[out->len++] = '\\'; |
| 455 | out->str[out->len++] = 'x'; |
| 456 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 457 | out->str[out->len++] = hextab[c & 0xF]; |
| 458 | } |
| 459 | ptr++; |
| 460 | } |
| 461 | |
| 462 | return ptr; |
| 463 | } |
| 464 | |
| 465 | /* print a buffer in hexa. |
| 466 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 467 | */ |
| 468 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 469 | { |
| 470 | unsigned char c; |
| 471 | int ptr = 0; |
| 472 | |
| 473 | while (ptr < bsize) { |
| 474 | c = buf[ptr]; |
| 475 | |
| 476 | if (out->len > out->size - 2) |
| 477 | break; |
| 478 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 479 | out->str[out->len++] = hextab[c & 0xF]; |
| 480 | |
| 481 | ptr++; |
| 482 | } |
| 483 | return ptr; |
| 484 | } |
| 485 | |
| 486 | /* Dump the status of a table to a stream interface's |
| 487 | * read buffer. It returns 0 if the output buffer is full |
| 488 | * and needs to be called again, otherwise non-zero. |
| 489 | */ |
| 490 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 491 | struct proxy *proxy, struct proxy *target) |
| 492 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 493 | struct session *s = session_from_task(si->owner); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 494 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 495 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 496 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 497 | |
| 498 | /* any other information should be dumped here */ |
| 499 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 500 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 501 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 502 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 503 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 504 | return 0; |
| 505 | |
| 506 | return 1; |
| 507 | } |
| 508 | |
| 509 | /* Dump the a table entry to a stream interface's |
| 510 | * read buffer. It returns 0 if the output buffer is full |
| 511 | * and needs to be called again, otherwise non-zero. |
| 512 | */ |
| 513 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 514 | struct proxy *proxy, struct stksess *entry) |
| 515 | { |
| 516 | int dt; |
| 517 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 518 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 519 | |
| 520 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 521 | char addr[INET_ADDRSTRLEN]; |
| 522 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 523 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 524 | } |
| 525 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 526 | char addr[INET6_ADDRSTRLEN]; |
| 527 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 528 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 529 | } |
| 530 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 531 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 532 | } |
| 533 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 534 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 535 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 536 | } |
| 537 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 538 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 539 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 540 | } |
| 541 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 542 | chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 543 | |
| 544 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 545 | void *ptr; |
| 546 | |
| 547 | if (proxy->table.data_ofs[dt] == 0) |
| 548 | continue; |
| 549 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 550 | chunk_appendf(msg, " %s(%d)=", stktable_data_types[dt].name, proxy->table.data_arg[dt].u); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 551 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 552 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 553 | |
| 554 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 555 | switch (stktable_data_types[dt].std_type) { |
| 556 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 557 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 558 | break; |
| 559 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 560 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 561 | break; |
| 562 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 563 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 564 | break; |
| 565 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 566 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 567 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 568 | proxy->table.data_arg[dt].u)); |
| 569 | break; |
| 570 | } |
| 571 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 572 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 573 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 574 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 575 | return 0; |
| 576 | |
| 577 | return 1; |
| 578 | } |
| 579 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 580 | 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] | 581 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 582 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 583 | struct appctx *appctx = __objt_appctx(si->end); |
| 584 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 585 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 586 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 587 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 588 | long long value; |
| 589 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 590 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 591 | void *ptr; |
| 592 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 593 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 594 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 595 | |
| 596 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 597 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 598 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 599 | return; |
| 600 | } |
| 601 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 602 | switch (px->table.type) { |
| 603 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 604 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 605 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 606 | break; |
| 607 | case STKTABLE_TYPE_IPV6: |
| 608 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 609 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 610 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 611 | case STKTABLE_TYPE_INTEGER: |
| 612 | { |
| 613 | char *endptr; |
| 614 | unsigned long val; |
| 615 | errno = 0; |
| 616 | val = strtoul(args[4], &endptr, 10); |
| 617 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 618 | (errno != 0 && val == 0) || endptr == args[4] || |
| 619 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 620 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 621 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 622 | return; |
| 623 | } |
| 624 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 625 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 626 | break; |
| 627 | } |
| 628 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 629 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 630 | static_table_key->key = args[4]; |
| 631 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 632 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 633 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 634 | switch (action) { |
| 635 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 636 | appctx->ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 637 | break; |
| 638 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 639 | appctx->ctx.cli.msg = "Removing keys from ip tables of type other than ip, ipv6, string and integer is not supported\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 640 | break; |
| 641 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 642 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 643 | break; |
| 644 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 645 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 646 | return; |
| 647 | } |
| 648 | |
| 649 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 650 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 651 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 652 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 653 | return; |
| 654 | } |
| 655 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 656 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 657 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 658 | switch (action) { |
| 659 | case STAT_CLI_O_TAB: |
| 660 | if (!ts) |
| 661 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 662 | chunk_reset(&trash); |
| 663 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 664 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 665 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 666 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 667 | |
| 668 | case STAT_CLI_O_CLR: |
| 669 | if (!ts) |
| 670 | return; |
| 671 | if (ts->ref_cnt) { |
| 672 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 673 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 674 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 675 | return; |
| 676 | } |
| 677 | stksess_kill(&px->table, ts); |
| 678 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 679 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 680 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 681 | if (ts) |
| 682 | stktable_touch(&px->table, ts, 1); |
| 683 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 684 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 685 | if (!ts) { |
| 686 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 687 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 688 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 689 | return; |
| 690 | } |
| 691 | stktable_store(&px->table, ts, 1); |
| 692 | } |
| 693 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 694 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 695 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 696 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 697 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 698 | return; |
| 699 | } |
| 700 | |
| 701 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 702 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 703 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 704 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 705 | return; |
| 706 | } |
| 707 | |
| 708 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 709 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 710 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 711 | return; |
| 712 | } |
| 713 | |
| 714 | if (!*args[cur_arg+1] || strl2llrc(args[cur_arg+1], strlen(args[cur_arg+1]), &value) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 715 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 716 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 717 | return; |
| 718 | } |
| 719 | |
| 720 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 721 | |
| 722 | switch (stktable_data_types[data_type].std_type) { |
| 723 | case STD_T_SINT: |
| 724 | stktable_data_cast(ptr, std_t_sint) = value; |
| 725 | break; |
| 726 | case STD_T_UINT: |
| 727 | stktable_data_cast(ptr, std_t_uint) = value; |
| 728 | break; |
| 729 | case STD_T_ULL: |
| 730 | stktable_data_cast(ptr, std_t_ull) = value; |
| 731 | break; |
| 732 | case STD_T_FRQP: |
| 733 | /* We set both the current and previous values. That way |
| 734 | * the reported frequency is stable during all the period |
| 735 | * then slowly fades out. This allows external tools to |
| 736 | * push measures without having to update them too often. |
| 737 | */ |
| 738 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 739 | frqp->curr_tick = now_ms; |
| 740 | frqp->prev_ctr = 0; |
| 741 | frqp->curr_ctr = value; |
| 742 | break; |
| 743 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 744 | } |
| 745 | break; |
| 746 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 747 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 748 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 749 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 750 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 751 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 752 | } |
| 753 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 754 | 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] | 755 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 756 | struct appctx *appctx = __objt_appctx(si->end); |
| 757 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 758 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 759 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 760 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 761 | return; |
| 762 | } |
| 763 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 764 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 765 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 766 | if (appctx->ctx.table.data_type < 0) { |
| 767 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 768 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 769 | return; |
| 770 | } |
| 771 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 772 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 773 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 774 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 775 | return; |
| 776 | } |
| 777 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 778 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 779 | if (appctx->ctx.table.data_op < 0) { |
| 780 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 781 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 782 | return; |
| 783 | } |
| 784 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 785 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 786 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 787 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 788 | return; |
| 789 | } |
| 790 | } |
| 791 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 792 | 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] | 793 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 794 | struct appctx *appctx = __objt_appctx(si->end); |
| 795 | |
| 796 | appctx->ctx.table.data_type = -1; |
| 797 | appctx->st2 = STAT_ST_INIT; |
| 798 | appctx->ctx.table.target = NULL; |
| 799 | appctx->ctx.table.proxy = NULL; |
| 800 | appctx->ctx.table.entry = NULL; |
| 801 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 802 | |
| 803 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 804 | appctx->ctx.table.target = find_stktable(args[2]); |
| 805 | if (!appctx->ctx.table.target) { |
| 806 | appctx->ctx.cli.msg = "No such table\n"; |
| 807 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 808 | return; |
| 809 | } |
| 810 | } |
| 811 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 812 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 813 | goto err_args; |
| 814 | return; |
| 815 | } |
| 816 | |
| 817 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 818 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 819 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 820 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 821 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 822 | goto err_args; |
| 823 | |
| 824 | return; |
| 825 | |
| 826 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 827 | switch (action) { |
| 828 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 829 | appctx->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] | 830 | break; |
| 831 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 832 | appctx->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] | 833 | break; |
| 834 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 835 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 836 | break; |
| 837 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 838 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 839 | } |
| 840 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 841 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 842 | * adequate error messages and returns NULL. This function also expects the session |
| 843 | * level to be admin. |
| 844 | */ |
| 845 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 846 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 847 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 848 | struct proxy *px; |
| 849 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 850 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 851 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 852 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 853 | return NULL; |
| 854 | } |
| 855 | |
| 856 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 857 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 858 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 859 | return NULL; |
| 860 | } |
| 861 | |
| 862 | px = findproxy(arg, PR_CAP_FE); |
| 863 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 864 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 865 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 866 | return NULL; |
| 867 | } |
| 868 | return px; |
| 869 | } |
| 870 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 871 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 872 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 873 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 874 | * the <arg> is modified to remove the '/'. |
| 875 | */ |
| 876 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 877 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 878 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 879 | struct proxy *px; |
| 880 | struct server *sv; |
| 881 | char *line; |
| 882 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 883 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 884 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 885 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 886 | return NULL; |
| 887 | } |
| 888 | |
| 889 | /* split "backend/server" and make <line> point to server */ |
| 890 | for (line = arg; *line; line++) |
| 891 | if (*line == '/') { |
| 892 | *line++ = '\0'; |
| 893 | break; |
| 894 | } |
| 895 | |
| 896 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 897 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 898 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 899 | return NULL; |
| 900 | } |
| 901 | |
| 902 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 903 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 904 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 905 | return NULL; |
| 906 | } |
| 907 | |
| 908 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 909 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 910 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 911 | return NULL; |
| 912 | } |
| 913 | |
| 914 | return sv; |
| 915 | } |
| 916 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 917 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 918 | * called from an applet running in a stream interface. The function returns 1 |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 919 | * if the request was understood, otherwise zero. It sets appctx->st0 to a value |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 920 | * designating the function which will have to process the request, which can |
| 921 | * 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] | 922 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 923 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 924 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 925 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 926 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 927 | char *args[MAX_STATS_ARGS + 1]; |
| 928 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame^] | 929 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 930 | |
| 931 | while (isspace((unsigned char)*line)) |
| 932 | line++; |
| 933 | |
| 934 | arg = 0; |
| 935 | args[arg] = line; |
| 936 | |
| 937 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame^] | 938 | if (*line == '\\') { |
| 939 | line++; |
| 940 | if (*line == '\0') |
| 941 | break; |
| 942 | } |
| 943 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 944 | *line++ = '\0'; |
| 945 | |
| 946 | while (isspace((unsigned char)*line)) |
| 947 | line++; |
| 948 | |
| 949 | args[++arg] = line; |
| 950 | continue; |
| 951 | } |
| 952 | |
| 953 | line++; |
| 954 | } |
| 955 | |
| 956 | while (++arg <= MAX_STATS_ARGS) |
| 957 | args[arg] = line; |
| 958 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame^] | 959 | /* remove \ */ |
| 960 | arg = 0; |
| 961 | while (*args[arg] != '\0') { |
| 962 | j = 0; |
| 963 | for (i=0; args[arg][i] != '\0'; i++) { |
| 964 | if (args[arg][i] == '\\') |
| 965 | continue; |
| 966 | args[arg][j] = args[arg][i]; |
| 967 | j++; |
| 968 | } |
| 969 | args[arg][j] = '\0'; |
| 970 | arg++; |
| 971 | } |
| 972 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 973 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 974 | if (strcmp(args[0], "show") == 0) { |
| 975 | if (strcmp(args[1], "stat") == 0) { |
| 976 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 977 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 978 | appctx->ctx.stats.iid = atoi(args[2]); |
| 979 | appctx->ctx.stats.type = atoi(args[3]); |
| 980 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 981 | } |
| 982 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 983 | appctx->st2 = STAT_ST_INIT; |
| 984 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 985 | } |
| 986 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 987 | appctx->st2 = STAT_ST_INIT; |
| 988 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 989 | } |
| 990 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 991 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 992 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 993 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 994 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 995 | return 1; |
| 996 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 997 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 998 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 999 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1000 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1001 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1002 | appctx->ctx.sess.target = NULL; |
| 1003 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1004 | appctx->ctx.sess.pos = 0; |
| 1005 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1006 | } |
| 1007 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1008 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1009 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1010 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1011 | return 1; |
| 1012 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1013 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1014 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1015 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1016 | appctx->ctx.errors.iid = -1; |
| 1017 | appctx->ctx.errors.px = NULL; |
| 1018 | appctx->st2 = STAT_ST_INIT; |
| 1019 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1020 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1021 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1022 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1023 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1024 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1025 | return 0; |
| 1026 | } |
| 1027 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1028 | else if (strcmp(args[0], "clear") == 0) { |
| 1029 | if (strcmp(args[1], "counters") == 0) { |
| 1030 | struct proxy *px; |
| 1031 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1032 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1033 | int clrall = 0; |
| 1034 | |
| 1035 | if (strcmp(args[2], "all") == 0) |
| 1036 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1037 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1038 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1039 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1040 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1041 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1042 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1043 | return 1; |
| 1044 | } |
| 1045 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1046 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1047 | if (clrall) { |
| 1048 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1049 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1050 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1051 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1052 | px->be_counters.conn_max = 0; |
| 1053 | px->be_counters.p.http.rps_max = 0; |
| 1054 | px->be_counters.sps_max = 0; |
| 1055 | px->be_counters.cps_max = 0; |
| 1056 | px->be_counters.nbpend_max = 0; |
| 1057 | |
| 1058 | px->fe_counters.conn_max = 0; |
| 1059 | px->fe_counters.p.http.rps_max = 0; |
| 1060 | px->fe_counters.sps_max = 0; |
| 1061 | px->fe_counters.cps_max = 0; |
| 1062 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1063 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1064 | |
| 1065 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1066 | if (clrall) |
| 1067 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1068 | else { |
| 1069 | sv->counters.cur_sess_max = 0; |
| 1070 | sv->counters.nbpend_max = 0; |
| 1071 | sv->counters.sps_max = 0; |
| 1072 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1073 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1074 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1075 | if (li->counters) { |
| 1076 | if (clrall) |
| 1077 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1078 | else |
| 1079 | li->counters->conn_max = 0; |
| 1080 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1081 | } |
| 1082 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1083 | global.cps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1084 | return 1; |
| 1085 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1086 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1087 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1088 | /* end of processing */ |
| 1089 | return 1; |
| 1090 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1091 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1092 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1093 | return 0; |
| 1094 | } |
| 1095 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1096 | else if (strcmp(args[0], "get") == 0) { |
| 1097 | if (strcmp(args[1], "weight") == 0) { |
| 1098 | struct proxy *px; |
| 1099 | struct server *sv; |
| 1100 | |
| 1101 | /* split "backend/server" and make <line> point to server */ |
| 1102 | for (line = args[2]; *line; line++) |
| 1103 | if (*line == '/') { |
| 1104 | *line++ = '\0'; |
| 1105 | break; |
| 1106 | } |
| 1107 | |
| 1108 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1109 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1110 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1111 | return 1; |
| 1112 | } |
| 1113 | |
| 1114 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1115 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1116 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1117 | return 1; |
| 1118 | } |
| 1119 | |
| 1120 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1121 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1122 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1123 | return 1; |
| 1124 | } |
| 1125 | else { /* not "get weight" */ |
| 1126 | return 0; |
| 1127 | } |
| 1128 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1129 | else if (strcmp(args[0], "set") == 0) { |
| 1130 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1131 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1132 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1133 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1134 | sv = expect_server_admin(s, si, args[2]); |
| 1135 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1136 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1137 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1138 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1139 | /* |
| 1140 | * The user-weight may now be zero and thus |
| 1141 | * the server considered to be draining. |
| 1142 | * Update the server's drain state as necessary. |
| 1143 | */ |
| 1144 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1145 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1146 | appctx->ctx.cli.msg = warning; |
| 1147 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1148 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1149 | return 1; |
| 1150 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1151 | else if (strcmp(args[1], "timeout") == 0) { |
| 1152 | if (strcmp(args[2], "cli") == 0) { |
| 1153 | unsigned timeout; |
| 1154 | const char *res; |
| 1155 | |
| 1156 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1157 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1158 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1159 | return 1; |
| 1160 | } |
| 1161 | |
| 1162 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1163 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1164 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1165 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1166 | return 1; |
| 1167 | } |
| 1168 | |
| 1169 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1170 | return 1; |
| 1171 | } |
| 1172 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1173 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1174 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1175 | return 1; |
| 1176 | } |
| 1177 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1178 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1179 | if (strcmp(args[2], "frontend") == 0) { |
| 1180 | struct proxy *px; |
| 1181 | struct listener *l; |
| 1182 | int v; |
| 1183 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1184 | px = expect_frontend_admin(s, si, args[3]); |
| 1185 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1186 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1187 | |
| 1188 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1189 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1190 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1191 | return 1; |
| 1192 | } |
| 1193 | |
| 1194 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1195 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1196 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1197 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1198 | return 1; |
| 1199 | } |
| 1200 | |
| 1201 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1202 | * its listeners. The blocked ones will be dequeued. |
| 1203 | */ |
| 1204 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1205 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1206 | l->maxconn = v; |
| 1207 | if (l->state == LI_FULL) |
| 1208 | resume_listener(l); |
| 1209 | } |
| 1210 | |
| 1211 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1212 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1213 | |
| 1214 | return 1; |
| 1215 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1216 | else if (strcmp(args[2], "global") == 0) { |
| 1217 | int v; |
| 1218 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1219 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1220 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1221 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1222 | return 1; |
| 1223 | } |
| 1224 | |
| 1225 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1226 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1227 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1228 | return 1; |
| 1229 | } |
| 1230 | |
| 1231 | v = atoi(args[3]); |
| 1232 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1233 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1234 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1235 | return 1; |
| 1236 | } |
| 1237 | |
| 1238 | /* check for unlimited values */ |
| 1239 | if (v <= 0) |
| 1240 | v = global.hardmaxconn; |
| 1241 | |
| 1242 | global.maxconn = v; |
| 1243 | |
| 1244 | /* Dequeues all of the listeners waiting for a resource */ |
| 1245 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1246 | dequeue_all_listeners(&global_listener_queue); |
| 1247 | |
| 1248 | return 1; |
| 1249 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1250 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1251 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1252 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1253 | return 1; |
| 1254 | } |
| 1255 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1256 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1257 | if (strcmp(args[2], "connections") == 0) { |
| 1258 | if (strcmp(args[3], "global") == 0) { |
| 1259 | int v; |
| 1260 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1261 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1262 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1263 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1264 | return 1; |
| 1265 | } |
| 1266 | |
| 1267 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1268 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1269 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1270 | return 1; |
| 1271 | } |
| 1272 | |
| 1273 | v = atoi(args[4]); |
| 1274 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1275 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1276 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1277 | return 1; |
| 1278 | } |
| 1279 | |
| 1280 | global.cps_lim = v; |
| 1281 | |
| 1282 | /* Dequeues all of the listeners waiting for a resource */ |
| 1283 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1284 | dequeue_all_listeners(&global_listener_queue); |
| 1285 | |
| 1286 | return 1; |
| 1287 | } |
| 1288 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1289 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1290 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1291 | return 1; |
| 1292 | } |
| 1293 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1294 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1295 | if (strcmp(args[3], "global") == 0) { |
| 1296 | int v; |
| 1297 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1298 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1299 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1300 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1301 | return 1; |
| 1302 | } |
| 1303 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1304 | v = atoi(args[4]); |
| 1305 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1306 | } |
| 1307 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1308 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1309 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1310 | return 1; |
| 1311 | } |
| 1312 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1313 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1314 | appctx->ctx.cli.msg = "'set rate-limit' supports 'connections' and 'http-compression'.\n"; |
| 1315 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1316 | return 1; |
| 1317 | } |
| 1318 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1319 | else if (strcmp(args[1], "table") == 0) { |
| 1320 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1321 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1322 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1323 | return 0; |
| 1324 | } |
| 1325 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1326 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1327 | if (strcmp(args[1], "agent") == 0) { |
| 1328 | struct server *sv; |
| 1329 | |
| 1330 | sv = expect_server_admin(s, si, args[2]); |
| 1331 | if (!sv) |
| 1332 | return 1; |
| 1333 | |
| 1334 | sv->agent.state &= ~CHK_STATE_DISABLED; |
| 1335 | |
| 1336 | return 1; |
| 1337 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1338 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1339 | struct server *sv; |
| 1340 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1341 | sv = expect_server_admin(s, si, args[2]); |
| 1342 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1343 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1344 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1345 | if (sv->state & SRV_MAINTAIN) { |
| 1346 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1347 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1348 | /* If this server tracks the status of another one, |
| 1349 | * we must restore the good status. |
| 1350 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1351 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1352 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1353 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1354 | } else { |
| 1355 | sv->state &= ~SRV_MAINTAIN; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1356 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1357 | } |
| 1358 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1359 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1360 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1361 | } |
| 1362 | } |
| 1363 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1364 | return 1; |
| 1365 | } |
| 1366 | else if (strcmp(args[1], "frontend") == 0) { |
| 1367 | struct proxy *px; |
| 1368 | |
| 1369 | px = expect_frontend_admin(s, si, args[2]); |
| 1370 | if (!px) |
| 1371 | return 1; |
| 1372 | |
| 1373 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1374 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1375 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1376 | return 1; |
| 1377 | } |
| 1378 | |
| 1379 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1380 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1381 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1382 | return 1; |
| 1383 | } |
| 1384 | |
| 1385 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1386 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1387 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1388 | return 1; |
| 1389 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1390 | return 1; |
| 1391 | } |
| 1392 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1393 | appctx->ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1394 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1395 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1396 | } |
| 1397 | } |
| 1398 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1399 | if (strcmp(args[1], "agent") == 0) { |
| 1400 | struct server *sv; |
| 1401 | |
| 1402 | sv = expect_server_admin(s, si, args[2]); |
| 1403 | if (!sv) |
| 1404 | return 1; |
| 1405 | |
| 1406 | sv->agent.state |= CHK_STATE_DISABLED; |
| 1407 | |
| 1408 | return 1; |
| 1409 | } |
| 1410 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1411 | struct server *sv; |
| 1412 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1413 | sv = expect_server_admin(s, si, args[2]); |
| 1414 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1415 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1416 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1417 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1418 | /* Not already in maintenance, we can change the server state */ |
| 1419 | sv->state |= SRV_MAINTAIN; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1420 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1421 | } |
| 1422 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1423 | return 1; |
| 1424 | } |
| 1425 | else if (strcmp(args[1], "frontend") == 0) { |
| 1426 | struct proxy *px; |
| 1427 | |
| 1428 | px = expect_frontend_admin(s, si, args[2]); |
| 1429 | if (!px) |
| 1430 | return 1; |
| 1431 | |
| 1432 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1433 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1434 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1435 | return 1; |
| 1436 | } |
| 1437 | |
| 1438 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1439 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1440 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1441 | return 1; |
| 1442 | } |
| 1443 | |
| 1444 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1445 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1446 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1447 | return 1; |
| 1448 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1449 | return 1; |
| 1450 | } |
| 1451 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1452 | appctx->ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1453 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1454 | return 1; |
| 1455 | } |
| 1456 | } |
| 1457 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1458 | if (strcmp(args[1], "frontend") == 0) { |
| 1459 | struct proxy *px; |
| 1460 | |
| 1461 | px = expect_frontend_admin(s, si, args[2]); |
| 1462 | if (!px) |
| 1463 | return 1; |
| 1464 | |
| 1465 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1466 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1467 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1468 | return 1; |
| 1469 | } |
| 1470 | |
| 1471 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1472 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1473 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1474 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1475 | stop_proxy(px); |
| 1476 | return 1; |
| 1477 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1478 | else if (strcmp(args[1], "session") == 0) { |
| 1479 | struct session *sess, *ptr; |
| 1480 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1481 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1482 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1483 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1484 | return 1; |
| 1485 | } |
| 1486 | |
| 1487 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1488 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1489 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1490 | return 1; |
| 1491 | } |
| 1492 | |
| 1493 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1494 | |
| 1495 | /* first, look for the requested session in the session table */ |
| 1496 | list_for_each_entry(sess, &sessions, list) { |
| 1497 | if (sess == ptr) |
| 1498 | break; |
| 1499 | } |
| 1500 | |
| 1501 | /* do we have the session ? */ |
| 1502 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1503 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1504 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1505 | return 1; |
| 1506 | } |
| 1507 | |
| 1508 | session_shutdown(sess, SN_ERR_KILLED); |
| 1509 | return 1; |
| 1510 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1511 | else if (strcmp(args[1], "sessions") == 0) { |
| 1512 | if (strcmp(args[2], "server") == 0) { |
| 1513 | struct server *sv; |
| 1514 | struct session *sess, *sess_bck; |
| 1515 | |
| 1516 | sv = expect_server_admin(s, si, args[3]); |
| 1517 | if (!sv) |
| 1518 | return 1; |
| 1519 | |
| 1520 | /* kill all the session that are on this server */ |
| 1521 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1522 | if (sess->srv_conn == sv) |
| 1523 | session_shutdown(sess, SN_ERR_KILLED); |
| 1524 | |
| 1525 | return 1; |
| 1526 | } |
| 1527 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1528 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1529 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1530 | return 1; |
| 1531 | } |
| 1532 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1533 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1534 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1535 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1536 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1537 | } |
| 1538 | } |
| 1539 | 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] | 1540 | return 0; |
| 1541 | } |
| 1542 | return 1; |
| 1543 | } |
| 1544 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1545 | /* 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] | 1546 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 1547 | * state machine handling requests and various responses. We read a request, |
| 1548 | * then we process it and send the response, and we possibly display a prompt. |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1549 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 1550 | * STAT_CLI_* constants. appctx->st1 is used to indicate whether prompt is enabled |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1551 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1552 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 1553 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1554 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1555 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1556 | struct channel *req = si->ob; |
| 1557 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1558 | int reql; |
| 1559 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1560 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1561 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 1562 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1563 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1564 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1565 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1566 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1567 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 1568 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1569 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1570 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1571 | /* Let's close for real now. We just close the request |
| 1572 | * side, the conditions below will complete if needed. |
| 1573 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1574 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1575 | break; |
| 1576 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1577 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1578 | /* ensure we have some output room left in the event we |
| 1579 | * would want to return some info right after parsing. |
| 1580 | */ |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1581 | if (buffer_almost_full(si->ib->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1582 | break; |
| 1583 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1584 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1585 | if (reql <= 0) { /* closed or EOL not found */ |
| 1586 | if (reql == 0) |
| 1587 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1588 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1589 | continue; |
| 1590 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1591 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1592 | /* seek for a possible semi-colon. If we find one, we |
| 1593 | * replace it with an LF and skip only this part. |
| 1594 | */ |
| 1595 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1596 | if (trash.str[len] == ';') { |
| 1597 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1598 | reql = len + 1; |
| 1599 | break; |
| 1600 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1601 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1602 | /* now it is time to check that we have a full line, |
| 1603 | * remove the trailing \n and possibly \r, then cut the |
| 1604 | * line. |
| 1605 | */ |
| 1606 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1607 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1608 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1609 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1610 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1611 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1612 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1613 | len--; |
| 1614 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1615 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1616 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1617 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1618 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1619 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1620 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1621 | continue; |
| 1622 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1623 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1624 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1625 | else if (strcmp(trash.str, "help") == 0 || |
| 1626 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1627 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 1628 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1629 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1630 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1631 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1632 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1633 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1634 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1635 | /* if prompt is disabled, print help on empty lines, |
| 1636 | * so that the user at least knows how to enable |
| 1637 | * prompt and find help. |
| 1638 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1639 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 1640 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1641 | } |
| 1642 | |
| 1643 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1644 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1645 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1646 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1647 | 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] | 1648 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1649 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1650 | continue; |
| 1651 | } |
| 1652 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1653 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1654 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1655 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 1656 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1657 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1658 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1659 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1660 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1661 | break; |
| 1662 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1663 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1664 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1665 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1666 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1667 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1668 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1669 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1670 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1671 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1672 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1673 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1674 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1675 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1676 | if (stats_table_request(si, appctx->st0)) |
| 1677 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1678 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1679 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1680 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1681 | break; |
| 1682 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1683 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1684 | /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1685 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 1686 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 1687 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1688 | } |
| 1689 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1690 | /* If the output functions are still there, it means they require more room. */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1691 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1692 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1693 | |
| 1694 | /* Now we close the output if one of the writers did so, |
| 1695 | * or if we're not in interactive mode and the request |
| 1696 | * buffer is empty. This still allows pipelined requests |
| 1697 | * to be sent in non-interactive mode. |
| 1698 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1699 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 1700 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1701 | continue; |
| 1702 | } |
| 1703 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1704 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1705 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1706 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1707 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1708 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1709 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST) && (appctx->st0 != STAT_CLI_GETREQ)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1710 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 1711 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1712 | /* 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] | 1713 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 1714 | * we forward the close to the request side so that it flows upstream to |
| 1715 | * the client. |
| 1716 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1717 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1718 | } |
| 1719 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1720 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && (appctx->st0 < STAT_CLI_OUTPUT)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1721 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 1722 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 1723 | /* We have no more processing to do, and nothing more to send, and |
| 1724 | * the client side has closed. So we'll forward this state downstream |
| 1725 | * on the response buffer. |
| 1726 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1727 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1728 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1732 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1733 | |
| 1734 | /* we don't want to expire timeouts while we're processing requests */ |
| 1735 | si->ib->rex = TICK_ETERNITY; |
| 1736 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1737 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1738 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1739 | 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] | 1740 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1741 | 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] | 1742 | |
| 1743 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 1744 | /* check that we have released everything then unregister */ |
| 1745 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1746 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1747 | } |
| 1748 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1749 | /* This function dumps information onto the stream interface's read buffer. |
| 1750 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 1751 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1752 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1753 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1754 | { |
| 1755 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 1756 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1757 | chunk_printf(&trash, |
| 1758 | "Name: " PRODUCT_NAME "\n" |
| 1759 | "Version: " HAPROXY_VERSION "\n" |
| 1760 | "Release_date: " HAPROXY_DATE "\n" |
| 1761 | "Nbproc: %d\n" |
| 1762 | "Process_num: %d\n" |
| 1763 | "Pid: %d\n" |
| 1764 | "Uptime: %dd %dh%02dm%02ds\n" |
| 1765 | "Uptime_sec: %d\n" |
| 1766 | "Memmax_MB: %d\n" |
| 1767 | "Ulimit-n: %d\n" |
| 1768 | "Maxsock: %d\n" |
| 1769 | "Maxconn: %d\n" |
| 1770 | "Hard_maxconn: %d\n" |
| 1771 | "Maxpipes: %d\n" |
| 1772 | "CurrConns: %d\n" |
| 1773 | "PipesUsed: %d\n" |
| 1774 | "PipesFree: %d\n" |
| 1775 | "ConnRate: %d\n" |
| 1776 | "ConnRateLimit: %d\n" |
| 1777 | "MaxConnRate: %d\n" |
| 1778 | "CompressBpsIn: %u\n" |
| 1779 | "CompressBpsOut: %u\n" |
| 1780 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1781 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1782 | "ZlibMemUsage: %ld\n" |
| 1783 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1784 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1785 | "Tasks: %d\n" |
| 1786 | "Run_queue: %d\n" |
| 1787 | "Idle_pct: %d\n" |
| 1788 | "node: %s\n" |
| 1789 | "description: %s\n" |
| 1790 | "", |
| 1791 | global.nbproc, |
| 1792 | relative_pid, |
| 1793 | pid, |
| 1794 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 1795 | up, |
| 1796 | global.rlimit_memmax, |
| 1797 | global.rlimit_nofile, |
| 1798 | global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes, |
| 1799 | actconn, pipes_used, pipes_free, |
| 1800 | read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max, |
| 1801 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 1802 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1803 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1804 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1805 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1806 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 1807 | global.node, global.desc ? global.desc : "" |
| 1808 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1809 | |
| 1810 | if (bi_putchk(si->ib, &trash) == -1) |
| 1811 | return 0; |
| 1812 | |
| 1813 | return 1; |
| 1814 | } |
| 1815 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1816 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 1817 | * the state from stream interface <si>. The caller is responsible for clearing |
| 1818 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1819 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1820 | static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px) |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1821 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1822 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1823 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1824 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1825 | if (!(px->cap & PR_CAP_FE)) |
| 1826 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1827 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1828 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE))) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1829 | return 0; |
| 1830 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1831 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1832 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1833 | /* name, queue */ |
| 1834 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1835 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1836 | if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1837 | /* Column sub-heading for Enable or Disable server */ |
| 1838 | chunk_appendf(&trash, "<td></td>"); |
| 1839 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1840 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1841 | chunk_appendf(&trash, |
| 1842 | "<td class=ac>" |
| 1843 | "<a name=\"%s/Frontend\"></a>" |
| 1844 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 1845 | "<td colspan=3></td>" |
| 1846 | "", |
| 1847 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1848 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1849 | chunk_appendf(&trash, |
| 1850 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1851 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1852 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 1853 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 1854 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1855 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 1856 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 1857 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1858 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1859 | if (px->mode == PR_MODE_HTTP) |
| 1860 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1861 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1862 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1863 | |
| 1864 | chunk_appendf(&trash, |
| 1865 | "</table></div></u></td>" |
| 1866 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1867 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1868 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 1869 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 1870 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1871 | U2H(px->fe_counters.sps_max), |
| 1872 | U2H(px->fe_counters.cps_max), |
| 1873 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1874 | |
| 1875 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1876 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1877 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1878 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1879 | |
| 1880 | chunk_appendf(&trash, |
| 1881 | "</table></div></u></td>" |
| 1882 | /* sessions rate : limit */ |
| 1883 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1884 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1885 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1886 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1887 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1888 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1889 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1890 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 1891 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1892 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1893 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 1894 | U2H(px->fe_counters.cum_sess), |
| 1895 | U2H(px->fe_counters.cum_conn), |
| 1896 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1897 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1898 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1899 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1900 | chunk_appendf(&trash, |
| 1901 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 1902 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 1903 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 1904 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1905 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 1906 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 1907 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 1908 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 1909 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 1910 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1911 | U2H(px->fe_counters.p.http.cum_req), |
| 1912 | U2H(px->fe_counters.p.http.rsp[1]), |
| 1913 | U2H(px->fe_counters.p.http.rsp[2]), |
| 1914 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1915 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1916 | (int)(100*px->fe_counters.p.http.comp_rsp/px->fe_counters.p.http.rsp[2]) : 0, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1917 | U2H(px->fe_counters.p.http.rsp[3]), |
| 1918 | U2H(px->fe_counters.p.http.rsp[4]), |
| 1919 | U2H(px->fe_counters.p.http.rsp[5]), |
| 1920 | U2H(px->fe_counters.p.http.rsp[0]), |
| 1921 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1922 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1923 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1924 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1925 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1926 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1927 | "<td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1928 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1929 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1930 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1931 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1932 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1933 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1934 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1935 | "<td>%s%s<div class=tips>compression: in=%lld out=%lld bypassed=%lld savings=%d%%</div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1936 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1937 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1938 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 1939 | px->fe_counters.comp_in ? |
| 1940 | (int)((px->fe_counters.comp_in - px->fe_counters.comp_out)*100/px->fe_counters.comp_in) : 0, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1941 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1942 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1943 | chunk_appendf(&trash, |
| 1944 | /* denied: req, resp */ |
| 1945 | "<td>%s</td><td>%s</td>" |
| 1946 | /* errors : request, connect, response */ |
| 1947 | "<td>%s</td><td></td><td></td>" |
| 1948 | /* warnings: retries, redispatches */ |
| 1949 | "<td></td><td></td>" |
| 1950 | /* server status : reflect frontend status */ |
| 1951 | "<td class=ac>%s</td>" |
| 1952 | /* rest of server: nothing */ |
| 1953 | "<td class=ac colspan=8></td></tr>" |
| 1954 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1955 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 1956 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1957 | px->state == PR_STREADY ? "OPEN" : |
| 1958 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1959 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1960 | else { /* CSV mode */ |
| 1961 | chunk_appendf(&trash, |
| 1962 | /* pxid, name, queue cur, queue max, */ |
| 1963 | "%s,FRONTEND,,," |
| 1964 | /* sessions : current, max, limit, total */ |
| 1965 | "%d,%d,%d,%lld," |
| 1966 | /* bytes : in, out */ |
| 1967 | "%lld,%lld," |
| 1968 | /* denied: req, resp */ |
| 1969 | "%lld,%lld," |
| 1970 | /* errors : request, connect, response */ |
| 1971 | "%lld,,," |
| 1972 | /* warnings: retries, redispatches */ |
| 1973 | ",," |
| 1974 | /* server status : reflect frontend status */ |
| 1975 | "%s," |
| 1976 | /* rest of server: nothing */ |
| 1977 | ",,,,,,,," |
| 1978 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 1979 | "%d,%d,0,,,,%d," |
| 1980 | /* rate, rate_lim, rate_max */ |
| 1981 | "%u,%u,%u," |
| 1982 | /* check_status, check_code, check_duration */ |
| 1983 | ",,,", |
| 1984 | px->id, |
| 1985 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 1986 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 1987 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 1988 | px->fe_counters.failed_req, |
| 1989 | px->state == PR_STREADY ? "OPEN" : |
| 1990 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 1991 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 1992 | read_freq_ctr(&px->fe_sess_per_sec), |
| 1993 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1994 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1995 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1996 | if (px->mode == PR_MODE_HTTP) { |
| 1997 | for (i=1; i<6; i++) |
| 1998 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 1999 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2000 | } |
| 2001 | else |
| 2002 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2003 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2004 | /* failed health analyses */ |
| 2005 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2006 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2007 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2008 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2009 | read_freq_ctr(&px->fe_req_per_sec), |
| 2010 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2011 | |
| 2012 | /* errors: cli_aborts, srv_aborts */ |
| 2013 | chunk_appendf(&trash, ",,"); |
| 2014 | |
| 2015 | /* compression: in, out, bypassed */ |
| 2016 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2017 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2018 | |
| 2019 | /* compression: comp_rsp */ |
| 2020 | chunk_appendf(&trash, "%lld,", |
| 2021 | px->fe_counters.p.http.comp_rsp); |
| 2022 | |
| 2023 | /* finish with EOL */ |
| 2024 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2025 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2026 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2027 | } |
| 2028 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2029 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2030 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2031 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2032 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2033 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2034 | static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2035 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2036 | struct appctx *appctx = __objt_appctx(si->end); |
| 2037 | |
| 2038 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2039 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2040 | if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2041 | /* Column sub-heading for Enable or Disable server */ |
| 2042 | chunk_appendf(&trash, "<td></td>"); |
| 2043 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2044 | chunk_appendf(&trash, |
| 2045 | /* frontend name, listener name */ |
| 2046 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2047 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2048 | "", |
| 2049 | px->id, l->name, |
| 2050 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2051 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2052 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2053 | if (flags & ST_SHLGNDS) { |
| 2054 | char str[INET6_ADDRSTRLEN]; |
| 2055 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2056 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2057 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2058 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2059 | port = get_host_port(&l->addr); |
| 2060 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2061 | case AF_INET: |
| 2062 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2063 | break; |
| 2064 | case AF_INET6: |
| 2065 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2066 | break; |
| 2067 | case AF_UNIX: |
| 2068 | chunk_appendf(&trash, "unix, "); |
| 2069 | break; |
| 2070 | case -1: |
| 2071 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2072 | break; |
| 2073 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2074 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2075 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2076 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2077 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2078 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2079 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2080 | /* queue */ |
| 2081 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2082 | /* sessions rate: current, max, limit */ |
| 2083 | "<td colspan=3> </td>" |
| 2084 | /* sessions: current, max, limit, total, lbtot */ |
| 2085 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2086 | "<td>%s</td><td> </td>" |
| 2087 | /* bytes: in, out */ |
| 2088 | "<td>%s</td><td>%s</td>" |
| 2089 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2090 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2091 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2092 | U2H(l->counters->cum_conn), U2H(l->counters->bytes_in), U2H(l->counters->bytes_out)); |
Willy Tarreau | 56a560a | 2009-09-22 19:27:35 +0200 | [diff] [blame] | 2093 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2094 | chunk_appendf(&trash, |
| 2095 | /* denied: req, resp */ |
| 2096 | "<td>%s</td><td>%s</td>" |
| 2097 | /* errors: request, connect, response */ |
| 2098 | "<td>%s</td><td></td><td></td>" |
| 2099 | /* warnings: retries, redispatches */ |
| 2100 | "<td></td><td></td>" |
| 2101 | /* server status: reflect listener status */ |
| 2102 | "<td class=ac>%s</td>" |
| 2103 | /* rest of server: nothing */ |
| 2104 | "<td class=ac colspan=8></td></tr>" |
| 2105 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2106 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2107 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2108 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2109 | } |
| 2110 | else { /* CSV mode */ |
| 2111 | chunk_appendf(&trash, |
| 2112 | /* pxid, name, queue cur, queue max, */ |
| 2113 | "%s,%s,,," |
| 2114 | /* sessions: current, max, limit, total */ |
| 2115 | "%d,%d,%d,%lld," |
| 2116 | /* bytes: in, out */ |
| 2117 | "%lld,%lld," |
| 2118 | /* denied: req, resp */ |
| 2119 | "%lld,%lld," |
| 2120 | /* errors: request, connect, response */ |
| 2121 | "%lld,,," |
| 2122 | /* warnings: retries, redispatches */ |
| 2123 | ",," |
| 2124 | /* server status: reflect listener status */ |
| 2125 | "%s," |
| 2126 | /* rest of server: nothing */ |
| 2127 | ",,,,,,,," |
| 2128 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2129 | "%d,%d,%d,,,,%d," |
| 2130 | /* rate, rate_lim, rate_max */ |
| 2131 | ",,," |
| 2132 | /* check_status, check_code, check_duration */ |
| 2133 | ",,," |
| 2134 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2135 | ",,,,,," |
| 2136 | /* failed health analyses */ |
| 2137 | "," |
| 2138 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2139 | ",,," |
| 2140 | /* errors: cli_aborts, srv_aborts */ |
| 2141 | ",," |
| 2142 | /* compression: in, out, bypassed, comp_rsp */ |
| 2143 | ",,,," |
| 2144 | "\n", |
| 2145 | px->id, l->name, |
| 2146 | l->nbconn, l->counters->conn_max, |
| 2147 | l->maxconn, l->counters->cum_conn, |
| 2148 | l->counters->bytes_in, l->counters->bytes_out, |
| 2149 | l->counters->denied_req, l->counters->denied_resp, |
| 2150 | l->counters->failed_req, |
| 2151 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2152 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2153 | } |
| 2154 | return 1; |
| 2155 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2156 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2157 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2158 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2159 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2160 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2161 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2162 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2163 | */ |
| 2164 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2165 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2166 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2167 | struct server *ref = sv->track ? sv->track : sv; |
| 2168 | char str[INET6_ADDRSTRLEN]; |
| 2169 | struct chunk src; |
| 2170 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2171 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2172 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2173 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2174 | "DOWN", |
| 2175 | "DN %d/%d ↑", |
| 2176 | "UP %d/%d ↓", |
| 2177 | "UP", |
| 2178 | "NOLB %d/%d ↓", |
| 2179 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2180 | "DRAIN %d/%d ↓", |
| 2181 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2182 | "<i>no check</i>" |
| 2183 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2184 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2185 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2186 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2187 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2188 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2189 | "<tr class=\"%s%d\">", |
| 2190 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2191 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2192 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2193 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2194 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2195 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2196 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2197 | chunk_appendf(&trash, |
| 2198 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2199 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2200 | "", |
| 2201 | px->id, sv->id, |
| 2202 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2203 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2204 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2205 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2206 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2207 | |
| 2208 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2209 | case AF_INET: |
| 2210 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2211 | break; |
| 2212 | case AF_INET6: |
| 2213 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2214 | break; |
| 2215 | case AF_UNIX: |
| 2216 | chunk_appendf(&trash, "unix, "); |
| 2217 | break; |
| 2218 | case -1: |
| 2219 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2220 | break; |
| 2221 | default: /* address family not supported */ |
| 2222 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2223 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2224 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2225 | /* id */ |
| 2226 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2227 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2228 | /* cookie */ |
| 2229 | if (sv->cookie) { |
| 2230 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2231 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2232 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2233 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2234 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2235 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2236 | } |
| 2237 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2238 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2239 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2240 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2241 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2242 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2243 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2244 | /* sessions rate : current, max, limit */ |
| 2245 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2246 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2247 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2248 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2249 | U2H(read_freq_ctr(&sv->sess_per_sec)), U2H(sv->counters.sps_max)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2250 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2251 | |
| 2252 | chunk_appendf(&trash, |
| 2253 | /* sessions: current, max, limit, total */ |
| 2254 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2255 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2256 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2257 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2258 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2259 | U2H(sv->counters.cum_sess), |
| 2260 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2261 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2262 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2263 | if (px->mode == PR_MODE_HTTP) { |
| 2264 | unsigned long long tot; |
| 2265 | for (tot = i = 0; i < 6; i++) |
| 2266 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2267 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2268 | chunk_appendf(&trash, |
| 2269 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2270 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2271 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2272 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2273 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2274 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2275 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2276 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2277 | U2H(tot), |
| 2278 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2279 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2280 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2281 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2282 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2283 | U2H(sv->counters.p.http.rsp[0]), tot ? (int)(100*sv->counters.p.http.rsp[0] / tot) : 0); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2284 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2285 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2286 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2287 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2288 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2289 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2290 | U2H(sv->counters.cum_lbconn)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2291 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2292 | chunk_appendf(&trash, |
| 2293 | /* bytes : in, out */ |
| 2294 | "<td>%s</td><td>%s</td>" |
| 2295 | /* denied: req, resp */ |
| 2296 | "<td></td><td>%s</td>" |
| 2297 | /* errors : request, connect */ |
| 2298 | "<td></td><td>%s</td>" |
| 2299 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2300 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2301 | /* warnings: retries, redispatches */ |
| 2302 | "<td>%lld</td><td>%lld</td>" |
| 2303 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2304 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2305 | U2H(sv->counters.failed_secu), |
| 2306 | U2H(sv->counters.failed_conns), |
| 2307 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2308 | sv->counters.cli_aborts, |
| 2309 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2310 | sv->counters.retries, sv->counters.redispatches); |
| 2311 | |
| 2312 | /* status, lest check */ |
| 2313 | chunk_appendf(&trash, "<td class=ac>"); |
| 2314 | |
| 2315 | if (sv->state & SRV_MAINTAIN) { |
| 2316 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2317 | chunk_appendf(&trash, "MAINT"); |
| 2318 | } |
| 2319 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2320 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2321 | chunk_appendf(&trash, "MAINT(via)"); |
| 2322 | } |
| 2323 | else if (ref->state & SRV_CHECKED) { |
| 2324 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2325 | chunk_appendf(&trash, |
| 2326 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2327 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2328 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2329 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2330 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2331 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2332 | chunk_appendf(&trash, |
| 2333 | "</td><td class=ac><u> %s%s", |
Simon Horman | cd5d7b6 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 2334 | (sv->check.state & CHK_STATE_RUNNING) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2335 | get_check_status_info(sv->check.status)); |
| 2336 | |
| 2337 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2338 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2339 | |
| 2340 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2341 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2342 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2343 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2344 | get_check_status_description(sv->check.status)); |
| 2345 | if (*sv->check.desc) { |
| 2346 | chunk_appendf(&trash, ": "); |
| 2347 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2348 | chunk_htmlencode(&trash, &src); |
| 2349 | } |
| 2350 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2351 | } |
| 2352 | else |
| 2353 | chunk_appendf(&trash, "</td><td>"); |
| 2354 | |
| 2355 | chunk_appendf(&trash, |
| 2356 | /* weight */ |
| 2357 | "</td><td class=ac>%d</td>" |
| 2358 | /* act, bck */ |
| 2359 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2360 | "", |
| 2361 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2362 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2363 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2364 | |
| 2365 | /* check failures: unique, fatal, down time */ |
| 2366 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2367 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2368 | |
| 2369 | if (ref->observe) |
| 2370 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2371 | |
| 2372 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2373 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2374 | "<td>%lld</td><td>%s</td>" |
| 2375 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2376 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2377 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2378 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2379 | else if (sv != ref) { |
| 2380 | if (sv->state & SRV_MAINTAIN) |
| 2381 | chunk_appendf(&trash, |
| 2382 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2383 | ref->proxy->id, ref->id); |
| 2384 | else |
| 2385 | chunk_appendf(&trash, |
| 2386 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2387 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2388 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2389 | else |
| 2390 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2391 | |
| 2392 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2393 | if (sv->state & SRV_WARMINGUP) |
| 2394 | chunk_appendf(&trash, "<td class=ac>%d %%</td></tr>\n", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2395 | else |
| 2396 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2397 | } |
| 2398 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2399 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2400 | "DOWN,", |
| 2401 | "DOWN %d/%d,", |
| 2402 | "UP %d/%d,", |
| 2403 | "UP,", |
| 2404 | "NOLB %d/%d,", |
| 2405 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2406 | "DRAIN %d/%d,", |
| 2407 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2408 | "no check," |
| 2409 | }; |
| 2410 | |
| 2411 | chunk_appendf(&trash, |
| 2412 | /* pxid, name */ |
| 2413 | "%s,%s," |
| 2414 | /* queue : current, max */ |
| 2415 | "%d,%d," |
| 2416 | /* sessions : current, max, limit, total */ |
| 2417 | "%d,%d,%s,%lld," |
| 2418 | /* bytes : in, out */ |
| 2419 | "%lld,%lld," |
| 2420 | /* denied: req, resp */ |
| 2421 | ",%lld," |
| 2422 | /* errors : request, connect, response */ |
| 2423 | ",%lld,%lld," |
| 2424 | /* warnings: retries, redispatches */ |
| 2425 | "%lld,%lld," |
| 2426 | "", |
| 2427 | px->id, sv->id, |
| 2428 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2429 | sv->cur_sess, sv->counters.cur_sess_max, LIM2A(sv->maxconn, ""), sv->counters.cum_sess, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2430 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2431 | sv->counters.failed_secu, |
| 2432 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2433 | sv->counters.retries, sv->counters.redispatches); |
| 2434 | |
| 2435 | /* status */ |
| 2436 | if (sv->state & SRV_MAINTAIN) |
| 2437 | chunk_appendf(&trash, "MAINT,"); |
| 2438 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2439 | chunk_appendf(&trash, "MAINT(via),"); |
| 2440 | else |
| 2441 | chunk_appendf(&trash, |
| 2442 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2443 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2444 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2445 | |
| 2446 | chunk_appendf(&trash, |
| 2447 | /* weight, active, backup */ |
| 2448 | "%d,%d,%d," |
| 2449 | "", |
| 2450 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2451 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2452 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2453 | |
| 2454 | /* check failures: unique, fatal; last change, total downtime */ |
| 2455 | if (sv->state & SRV_CHECKED) |
| 2456 | chunk_appendf(&trash, |
| 2457 | "%lld,%lld,%d,%d,", |
| 2458 | sv->counters.failed_checks, sv->counters.down_trans, |
| 2459 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 2460 | else |
| 2461 | chunk_appendf(&trash, ",,,,"); |
| 2462 | |
| 2463 | /* queue limit, pid, iid, sid, */ |
| 2464 | chunk_appendf(&trash, |
| 2465 | "%s," |
| 2466 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2467 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2468 | relative_pid, px->uuid, sv->puid); |
| 2469 | |
| 2470 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2471 | if (sv->state & SRV_WARMINGUP) |
| 2472 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2473 | |
| 2474 | /* sessions: lbtot */ |
| 2475 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 2476 | |
| 2477 | /* tracked */ |
| 2478 | if (sv->track) |
| 2479 | chunk_appendf(&trash, "%s/%s,", |
| 2480 | sv->track->proxy->id, sv->track->id); |
| 2481 | else |
| 2482 | chunk_appendf(&trash, ","); |
| 2483 | |
| 2484 | /* type */ |
| 2485 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 2486 | |
| 2487 | /* rate */ |
| 2488 | chunk_appendf(&trash, "%u,,%u,", |
| 2489 | read_freq_ctr(&sv->sess_per_sec), |
| 2490 | sv->counters.sps_max); |
| 2491 | |
| 2492 | if (sv->state & SRV_CHECKED) { |
| 2493 | /* check_status */ |
| 2494 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 2495 | |
| 2496 | /* check_code */ |
| 2497 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2498 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 2499 | else |
| 2500 | chunk_appendf(&trash, ","); |
| 2501 | |
| 2502 | /* check_duration */ |
| 2503 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 2504 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 2505 | else |
| 2506 | chunk_appendf(&trash, ","); |
| 2507 | |
| 2508 | } |
| 2509 | else |
| 2510 | chunk_appendf(&trash, ",,,"); |
| 2511 | |
| 2512 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2513 | if (px->mode == PR_MODE_HTTP) { |
| 2514 | for (i=1; i<6; i++) |
| 2515 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 2516 | |
| 2517 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 2518 | } |
| 2519 | else |
| 2520 | chunk_appendf(&trash, ",,,,,,"); |
| 2521 | |
| 2522 | /* failed health analyses */ |
| 2523 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 2524 | |
| 2525 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2526 | chunk_appendf(&trash, ",,,"); |
| 2527 | |
| 2528 | /* errors: cli_aborts, srv_aborts */ |
| 2529 | chunk_appendf(&trash, "%lld,%lld,", |
| 2530 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 2531 | |
| 2532 | /* compression: in, out, bypassed, comp_rsp */ |
| 2533 | chunk_appendf(&trash, ",,,,"); |
| 2534 | |
| 2535 | /* finish with EOL */ |
| 2536 | chunk_appendf(&trash, "\n"); |
| 2537 | } |
| 2538 | return 1; |
| 2539 | } |
| 2540 | |
| 2541 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 2542 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 2543 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 2544 | */ |
| 2545 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 2546 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2547 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2548 | struct chunk src; |
| 2549 | int i; |
| 2550 | |
| 2551 | if (!(px->cap & PR_CAP_BE)) |
| 2552 | return 0; |
| 2553 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2554 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE))) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2555 | return 0; |
| 2556 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2557 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2558 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2559 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2560 | /* Column sub-heading for Enable or Disable server */ |
| 2561 | chunk_appendf(&trash, "<td></td>"); |
| 2562 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2563 | chunk_appendf(&trash, |
| 2564 | "<td class=ac>" |
| 2565 | /* name */ |
| 2566 | "%s<a name=\"%s/Backend\"></a>" |
| 2567 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 2568 | "", |
| 2569 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2570 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2571 | |
| 2572 | if (flags & ST_SHLGNDS) { |
| 2573 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2574 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2575 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 2576 | |
| 2577 | /* cookie */ |
| 2578 | if (px->cookie_name) { |
| 2579 | chunk_appendf(&trash, ", cookie: '"); |
| 2580 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 2581 | chunk_htmlencode(&trash, &src); |
| 2582 | chunk_appendf(&trash, "'"); |
| 2583 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2584 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2588 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2589 | /* queue : current, max */ |
| 2590 | "<td>%s</td><td>%s</td><td></td>" |
| 2591 | /* sessions rate : current, max, limit */ |
| 2592 | "<td>%s</td><td>%s</td><td></td>" |
| 2593 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2594 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2595 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 2596 | U2H(read_freq_ctr(&px->be_sess_per_sec)), U2H(px->be_counters.sps_max)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2597 | |
| 2598 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2599 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2600 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2601 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2602 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2603 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2604 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 2605 | U2H(px->be_counters.cum_conn), |
| 2606 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2607 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2608 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2609 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2610 | chunk_appendf(&trash, |
| 2611 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2612 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2613 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2614 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2615 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2616 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2617 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2618 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2619 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2620 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2621 | U2H(px->be_counters.p.http.cum_req), |
| 2622 | U2H(px->be_counters.p.http.rsp[1]), |
| 2623 | U2H(px->be_counters.p.http.rsp[2]), |
| 2624 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2625 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2626 | (int)(100*px->be_counters.p.http.comp_rsp/px->be_counters.p.http.rsp[2]) : 0, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2627 | U2H(px->be_counters.p.http.rsp[3]), |
| 2628 | U2H(px->be_counters.p.http.rsp[4]), |
| 2629 | U2H(px->be_counters.p.http.rsp[5]), |
| 2630 | U2H(px->be_counters.p.http.rsp[0]), |
| 2631 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2635 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2636 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2637 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2638 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2639 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2640 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2641 | U2H(px->be_counters.cum_lbconn), |
| 2642 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2643 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2644 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2645 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2646 | "<td>%s%s<div class=tips>compression: in=%lld out=%lld bypassed=%lld savings=%d%%</div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2647 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2648 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2649 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 2650 | px->be_counters.comp_in ? |
| 2651 | (int)((px->be_counters.comp_in - px->be_counters.comp_out)*100/px->be_counters.comp_in) : 0, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2652 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 2653 | |
| 2654 | chunk_appendf(&trash, |
| 2655 | /* denied: req, resp */ |
| 2656 | "<td>%s</td><td>%s</td>" |
| 2657 | /* errors : request, connect */ |
| 2658 | "<td></td><td>%s</td>" |
| 2659 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2660 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2661 | /* warnings: retries, redispatches */ |
| 2662 | "<td>%lld</td><td>%lld</td>" |
| 2663 | /* backend status: reflect backend status (up/down): we display UP |
| 2664 | * if the backend has known working servers or if it has no server at |
| 2665 | * all (eg: for stats). Then we display the total weight, number of |
| 2666 | * active and backups. */ |
| 2667 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 2668 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 2669 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2670 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 2671 | U2H(px->be_counters.failed_conns), |
| 2672 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2673 | px->be_counters.cli_aborts, |
| 2674 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2675 | px->be_counters.retries, px->be_counters.redispatches, |
| 2676 | human_time(now.tv_sec - px->last_change, 1), |
| 2677 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 2678 | "<font color=\"red\"><b>DOWN</b></font>", |
| 2679 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2680 | px->srv_act, px->srv_bck); |
| 2681 | |
| 2682 | chunk_appendf(&trash, |
| 2683 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 2684 | "<td class=ac> </td><td>%d</td>" |
| 2685 | "<td>%s</td>" |
| 2686 | "<td></td>" |
| 2687 | "</tr>", |
| 2688 | px->down_trans, |
| 2689 | px->srv?human_time(be_downtime(px), 1):" "); |
| 2690 | } |
| 2691 | else { /* CSV mode */ |
| 2692 | chunk_appendf(&trash, |
| 2693 | /* pxid, name */ |
| 2694 | "%s,BACKEND," |
| 2695 | /* queue : current, max */ |
| 2696 | "%d,%d," |
| 2697 | /* sessions : current, max, limit, total */ |
| 2698 | "%d,%d,%d,%lld," |
| 2699 | /* bytes : in, out */ |
| 2700 | "%lld,%lld," |
| 2701 | /* denied: req, resp */ |
| 2702 | "%lld,%lld," |
| 2703 | /* errors : request, connect, response */ |
| 2704 | ",%lld,%lld," |
| 2705 | /* warnings: retries, redispatches */ |
| 2706 | "%lld,%lld," |
| 2707 | /* backend status: reflect backend status (up/down): we display UP |
| 2708 | * if the backend has known working servers or if it has no server at |
| 2709 | * all (eg: for stats). Then we display the total weight, number of |
| 2710 | * active and backups. */ |
| 2711 | "%s," |
| 2712 | "%d,%d,%d," |
| 2713 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 2714 | ",%d,%d,%d,," |
| 2715 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2716 | "%d,%d,0,,%lld,,%d," |
| 2717 | /* rate, rate_lim, rate_max, */ |
| 2718 | "%u,,%u," |
| 2719 | /* check_status, check_code, check_duration */ |
| 2720 | ",,,", |
| 2721 | px->id, |
| 2722 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 2723 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 2724 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 2725 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 2726 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 2727 | px->be_counters.retries, px->be_counters.redispatches, |
| 2728 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 2729 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2730 | px->srv_act, px->srv_bck, |
| 2731 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 2732 | px->srv?be_downtime(px):0, |
| 2733 | relative_pid, px->uuid, |
| 2734 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 2735 | read_freq_ctr(&px->be_sess_per_sec), |
| 2736 | px->be_counters.sps_max); |
| 2737 | |
| 2738 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2739 | if (px->mode == PR_MODE_HTTP) { |
| 2740 | for (i=1; i<6; i++) |
| 2741 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 2742 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 2743 | } |
| 2744 | else |
| 2745 | chunk_appendf(&trash, ",,,,,,"); |
| 2746 | |
| 2747 | /* failed health analyses */ |
| 2748 | chunk_appendf(&trash, ","); |
| 2749 | |
| 2750 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2751 | chunk_appendf(&trash, ",,,"); |
| 2752 | |
| 2753 | /* errors: cli_aborts, srv_aborts */ |
| 2754 | chunk_appendf(&trash, "%lld,%lld,", |
| 2755 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 2756 | |
| 2757 | /* compression: in, out, bypassed */ |
| 2758 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2759 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 2760 | |
| 2761 | /* compression: comp_rsp */ |
| 2762 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 2763 | |
| 2764 | /* finish with EOL */ |
| 2765 | chunk_appendf(&trash, "\n"); |
| 2766 | } |
| 2767 | return 1; |
| 2768 | } |
| 2769 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2770 | /* Dumps the HTML table header for proxy <px> to the trash for and uses the state from |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2771 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2772 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2773 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2774 | static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px, struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2775 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2776 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2777 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 2778 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2779 | if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2780 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2781 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2782 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2783 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2784 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2785 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2786 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 2787 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2788 | } |
| 2789 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2790 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2791 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 2792 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2793 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2794 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2795 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | /* print a new table */ |
| 2799 | chunk_appendf(&trash, |
| 2800 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2801 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2802 | "<th class=\"pxname\" width=\"10%%\">"); |
| 2803 | |
| 2804 | chunk_appendf(&trash, |
| 2805 | "<a name=\"%s\"></a>%s" |
| 2806 | "<a class=px href=\"#%s\">%s</a>", |
| 2807 | px->id, |
| 2808 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 2809 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2810 | |
| 2811 | if (uri->flags & ST_SHLGNDS) { |
| 2812 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2813 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2814 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 2815 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2816 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2820 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2821 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 2822 | "</tr>\n" |
| 2823 | "</table>\n" |
| 2824 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2825 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2826 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 2827 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 2828 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2829 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2830 | /* Column heading for Enable or Disable server */ |
| 2831 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2832 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2833 | |
| 2834 | chunk_appendf(&trash, |
| 2835 | "<th rowspan=2></th>" |
| 2836 | "<th colspan=3>Queue</th>" |
| 2837 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
| 2838 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 2839 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 2840 | "<th colspan=9>Server</th>" |
| 2841 | "</tr>\n" |
| 2842 | "<tr class=\"titre\">" |
| 2843 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 2844 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 2845 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>" |
| 2846 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 2847 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 2848 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 2849 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 2850 | "<th>Thrtle</th>\n" |
| 2851 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2852 | } |
| 2853 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2854 | /* Dumps the HTML table trailer for proxy <px> to the trash for and uses the state from |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2855 | * stream interface <si>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2856 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2857 | static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2858 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2859 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2860 | chunk_appendf(&trash, "</table>"); |
| 2861 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2862 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2863 | /* close the form used to enable/disable this proxy servers */ |
| 2864 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2865 | "Choose the action to perform on the checked servers : " |
| 2866 | "<select name=action>" |
| 2867 | "<option value=\"\"></option>" |
| 2868 | "<option value=\"disable\">Disable</option>" |
| 2869 | "<option value=\"enable\">Enable</option>" |
| 2870 | "<option value=\"stop\">Soft Stop</option>" |
| 2871 | "<option value=\"start\">Soft Start</option>" |
| 2872 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 2873 | "</select>" |
| 2874 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 2875 | " <input type=\"submit\" value=\"Apply\">" |
| 2876 | "</form>", |
| 2877 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2878 | } |
| 2879 | |
| 2880 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2881 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2882 | |
| 2883 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2884 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 2885 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 2886 | * buffer space, or non-zero if everything completed. This function is used |
| 2887 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 2888 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2889 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2890 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2891 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2892 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 2893 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2894 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2895 | 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] | 2896 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2897 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2898 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2899 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2900 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2901 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2902 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2903 | if (uri && uri->scope) { |
| 2904 | /* we have a limited scope, we have to check the proxy name */ |
| 2905 | struct stat_scope *scope; |
| 2906 | int len; |
| 2907 | |
| 2908 | len = strlen(px->id); |
| 2909 | scope = uri->scope; |
| 2910 | |
| 2911 | while (scope) { |
| 2912 | /* match exact proxy name */ |
| 2913 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 2914 | break; |
| 2915 | |
| 2916 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 2917 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2918 | break; |
| 2919 | scope = scope->next; |
| 2920 | } |
| 2921 | |
| 2922 | /* proxy name not found : don't dump anything */ |
| 2923 | if (scope == NULL) |
| 2924 | return 1; |
| 2925 | } |
| 2926 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2927 | /* if the user has requested a limited output and the proxy |
| 2928 | * name does not match, skip it. |
| 2929 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2930 | if (appctx->ctx.stats.scope_len && |
| 2931 | strnistr(px->id, strlen(px->id), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len) == NULL) |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2932 | return 1; |
| 2933 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2934 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 2935 | (appctx->ctx.stats.iid != -1) && |
| 2936 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2937 | return 1; |
| 2938 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2939 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2940 | /* fall through */ |
| 2941 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2942 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2943 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2944 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2945 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2946 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2947 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2948 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2949 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2950 | /* fall through */ |
| 2951 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2952 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2953 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2954 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2955 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2956 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2957 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2958 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 2959 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2960 | /* fall through */ |
| 2961 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2962 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2963 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2964 | for (; appctx->ctx.stats.l != &px->conf.listeners; appctx->ctx.stats.l = l->by_fe.n) { |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2965 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2966 | return 0; |
| 2967 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2968 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2969 | if (!l->counters) |
| 2970 | continue; |
| 2971 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2972 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 2973 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2974 | break; |
| 2975 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2976 | if (appctx->ctx.stats.sid != -1 && l->luid != appctx->ctx.stats.sid) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2977 | continue; |
| 2978 | } |
| 2979 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2980 | /* print the frontend */ |
| 2981 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 2982 | if (bi_putchk(rep, &trash) == -1) |
| 2983 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2984 | } |
| 2985 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2986 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 2987 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2988 | /* fall through */ |
| 2989 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2990 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2991 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2992 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2993 | 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] | 2994 | |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2995 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2996 | return 0; |
| 2997 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2998 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2999 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3000 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3001 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3002 | break; |
| 3003 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3004 | if (appctx->ctx.stats.sid != -1 && sv->puid != appctx->ctx.stats.sid) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3005 | continue; |
| 3006 | } |
| 3007 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3008 | if (sv->track) |
| 3009 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3010 | else |
| 3011 | svs = sv; |
| 3012 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3013 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3014 | if (!(svs->state & SRV_CHECKED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3015 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3016 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 3017 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3018 | sv_state = 3; /* UP */ |
| 3019 | else |
| 3020 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3021 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3022 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3023 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3024 | else if (svs->state & SRV_GOINGDOWN) |
| 3025 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3026 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3027 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 3028 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3029 | sv_state = 1; /* going up */ |
| 3030 | else |
| 3031 | sv_state = 0; /* DOWN */ |
| 3032 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3033 | if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (appctx->ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3034 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3035 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3036 | continue; |
| 3037 | } |
| 3038 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3039 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3040 | if (bi_putchk(rep, &trash) == -1) |
| 3041 | return 0; |
| 3042 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3043 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3044 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3045 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3046 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3047 | case STAT_PX_ST_BE: |
| 3048 | /* print the backend */ |
| 3049 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3050 | if (bi_putchk(rep, &trash) == -1) |
| 3051 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3052 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3053 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3054 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3055 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3056 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3057 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3058 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3059 | if (bi_putchk(rep, &trash) == -1) |
| 3060 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3061 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3062 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3063 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3064 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3065 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3066 | case STAT_PX_ST_FIN: |
| 3067 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3068 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3069 | default: |
| 3070 | /* unknown state, we should put an abort() here ! */ |
| 3071 | return 1; |
| 3072 | } |
| 3073 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3074 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3075 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3076 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3077 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3078 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3079 | { |
| 3080 | /* WARNING! This must fit in the first buffer !!! */ |
| 3081 | chunk_appendf(&trash, |
| 3082 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3083 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3084 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3085 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3086 | "<style type=\"text/css\"><!--\n" |
| 3087 | "body {" |
| 3088 | " font-family: arial, helvetica, sans-serif;" |
| 3089 | " font-size: 12px;" |
| 3090 | " font-weight: normal;" |
| 3091 | " color: black;" |
| 3092 | " background: white;" |
| 3093 | "}\n" |
| 3094 | "th,td {" |
| 3095 | " font-size: 10px;" |
| 3096 | "}\n" |
| 3097 | "h1 {" |
| 3098 | " font-size: x-large;" |
| 3099 | " margin-bottom: 0.5em;" |
| 3100 | "}\n" |
| 3101 | "h2 {" |
| 3102 | " font-family: helvetica, arial;" |
| 3103 | " font-size: x-large;" |
| 3104 | " font-weight: bold;" |
| 3105 | " font-style: italic;" |
| 3106 | " color: #6020a0;" |
| 3107 | " margin-top: 0em;" |
| 3108 | " margin-bottom: 0em;" |
| 3109 | "}\n" |
| 3110 | "h3 {" |
| 3111 | " font-family: helvetica, arial;" |
| 3112 | " font-size: 16px;" |
| 3113 | " font-weight: bold;" |
| 3114 | " color: #b00040;" |
| 3115 | " background: #e8e8d0;" |
| 3116 | " margin-top: 0em;" |
| 3117 | " margin-bottom: 0em;" |
| 3118 | "}\n" |
| 3119 | "li {" |
| 3120 | " margin-top: 0.25em;" |
| 3121 | " margin-right: 2em;" |
| 3122 | "}\n" |
| 3123 | ".hr {margin-top: 0.25em;" |
| 3124 | " border-color: black;" |
| 3125 | " border-bottom-style: solid;" |
| 3126 | "}\n" |
| 3127 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3128 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3129 | ".frontend {background: #e8e8d0;}\n" |
| 3130 | ".socket {background: #d0d0d0;}\n" |
| 3131 | ".backend {background: #e8e8d0;}\n" |
| 3132 | ".active0 {background: #ff9090;}\n" |
| 3133 | ".active1 {background: #ffd020;}\n" |
| 3134 | ".active2 {background: #ffffa0;}\n" |
| 3135 | ".active3 {background: #c0ffc0;}\n" |
| 3136 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3137 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3138 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3139 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3140 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3141 | ".backup0 {background: #ff9090;}\n" |
| 3142 | ".backup1 {background: #ff80ff;}\n" |
| 3143 | ".backup2 {background: #c060ff;}\n" |
| 3144 | ".backup3 {background: #b0d0ff;}\n" |
| 3145 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3146 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3147 | ".backup6 {background: #c060ff;}\n" |
| 3148 | ".backup7 {background: #cc9900;}\n" |
| 3149 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3150 | ".maintain {background: #c07820;}\n" |
| 3151 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3152 | "\n" |
| 3153 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3154 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3155 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3156 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3157 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3158 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3159 | "\n" |
| 3160 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3161 | "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" |
| 3162 | "table.tbl td.ac { text-align: center;}\n" |
| 3163 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3164 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3165 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3166 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3167 | "\n" |
| 3168 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3169 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3170 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3171 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3172 | "table.det th { text-align: left; border-width: 0px; padding: 0px 1px 0px 0px; font-style:normal;font-size:11px;font-weight:bold;font-family: sans-serif;}\n" |
| 3173 | "table.det td { text-align: right; border-width: 0px; padding: 0px 0px 0px 4px; white-space: nowrap; font-style:normal;font-size:11px;font-weight:normal;font-family: monospace;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3174 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3175 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3176 | " display:block;\n" |
| 3177 | " visibility:hidden;\n" |
| 3178 | " z-index:2147483647;\n" |
| 3179 | " position:absolute;\n" |
| 3180 | " padding:2px 4px 3px;\n" |
| 3181 | " background:#f0f060; color:#000000;\n" |
| 3182 | " border:1px solid #7040c0;\n" |
| 3183 | " white-space:nowrap;\n" |
| 3184 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3185 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3186 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3187 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3188 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3189 | "-->\n" |
| 3190 | "</style></head>\n", |
| 3191 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3192 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3193 | ); |
| 3194 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3195 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3196 | /* Dumps the HTML stats information block to the trash for and uses the state from |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3197 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3198 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3199 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3200 | static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3201 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3202 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3203 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3204 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3205 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3206 | /* WARNING! this has to fit the first packet too. |
| 3207 | * We are around 3.5 kB, add adding entries will |
| 3208 | * become tricky if we want to support 4kB buffers ! |
| 3209 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3210 | chunk_appendf(&trash, |
| 3211 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3212 | PRODUCT_NAME "%s</a></h1>\n" |
| 3213 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3214 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3215 | "<h3>> General process information</h3>\n" |
| 3216 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3217 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3218 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3219 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3220 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3221 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3222 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3223 | "</td><td align=\"center\" nowrap>\n" |
| 3224 | "<table class=\"lgd\"><tr>\n" |
| 3225 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3226 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3227 | "</tr><tr>\n" |
| 3228 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3229 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3230 | "</tr><tr>\n" |
| 3231 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3232 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3233 | "</tr><tr>\n" |
| 3234 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3235 | "</tr><tr>\n" |
| 3236 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3237 | "</tr><tr>\n" |
| 3238 | "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) </td>" |
Geoff Bucar | cc8bb92 | 2013-04-18 13:53:16 -0700 | [diff] [blame] | 3239 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3240 | "<td class=\"active7\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3241 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3242 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3243 | "</td>" |
| 3244 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3245 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3246 | "", |
| 3247 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3248 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3249 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3250 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3251 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3252 | pid, relative_pid, global.nbproc, |
| 3253 | up / 86400, (up % 86400) / 3600, |
| 3254 | (up % 3600) / 60, (up % 60), |
| 3255 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3256 | global.rlimit_memmax ? " MB" : "", |
| 3257 | global.rlimit_nofile, |
| 3258 | global.maxsock, global.maxconn, global.maxpipes, |
| 3259 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3260 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3261 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3262 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3263 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3264 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3265 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3266 | |
| 3267 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3268 | "<li><form method=\"GET\" action=\"%s%s%s\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3269 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3270 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3271 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3272 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3273 | STAT_SCOPE_TXT_MAXLEN); |
| 3274 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3275 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3276 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3277 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3278 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3279 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3280 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3281 | } |
| 3282 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3283 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3284 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3285 | "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3286 | uri->uri_prefix, |
| 3287 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3288 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3289 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3290 | else |
| 3291 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3292 | "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3293 | uri->uri_prefix, |
| 3294 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3295 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3296 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3297 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3298 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3299 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3300 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3301 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3302 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3303 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3304 | "", |
| 3305 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3306 | else |
| 3307 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3308 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3309 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3310 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3311 | ";norefresh", |
| 3312 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3313 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3314 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3315 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3316 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3317 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3318 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3319 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3320 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3321 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3322 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3323 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3324 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3325 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3326 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3327 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3328 | chunk_appendf(&trash, |
| 3329 | "</ul></td>" |
| 3330 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3331 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3332 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3333 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3334 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3335 | "</ul>" |
| 3336 | "</td>" |
| 3337 | "</tr></table>\n" |
| 3338 | "" |
| 3339 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3340 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3341 | if (appctx->ctx.stats.st_code) { |
| 3342 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3343 | case STAT_STATUS_DONE: |
| 3344 | chunk_appendf(&trash, |
| 3345 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3346 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3347 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3348 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3349 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3350 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3351 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3352 | break; |
| 3353 | case STAT_STATUS_NONE: |
| 3354 | chunk_appendf(&trash, |
| 3355 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3356 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3357 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3358 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3359 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3360 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3361 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3362 | break; |
| 3363 | case STAT_STATUS_PART: |
| 3364 | chunk_appendf(&trash, |
| 3365 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3366 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3367 | "Action partially processed.<br>" |
| 3368 | "Some server names are probably unknown or ambiguous (duplicated names in the backend)." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3369 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3370 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3371 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3372 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3373 | break; |
| 3374 | case STAT_STATUS_ERRP: |
| 3375 | chunk_appendf(&trash, |
| 3376 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3377 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3378 | "Action not processed because of invalid parameters." |
| 3379 | "<ul>" |
| 3380 | "<li>The action is maybe unknown.</li>" |
| 3381 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3382 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3383 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3384 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3385 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3386 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3387 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3388 | break; |
| 3389 | case STAT_STATUS_EXCD: |
| 3390 | chunk_appendf(&trash, |
| 3391 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3392 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3393 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3394 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3395 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3396 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3397 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3398 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3399 | break; |
| 3400 | case STAT_STATUS_DENY: |
| 3401 | chunk_appendf(&trash, |
| 3402 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3403 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3404 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3405 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3406 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3407 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3408 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3409 | break; |
| 3410 | default: |
| 3411 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3412 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3413 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3414 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3415 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3416 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3417 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3418 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3419 | } |
| 3420 | chunk_appendf(&trash, "<p>\n"); |
| 3421 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3422 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3423 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3424 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3425 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3426 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3427 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3428 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3429 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3430 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3431 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3432 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3433 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3434 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3435 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3436 | * and the session must be closed, or -1 in case of any error. This function is |
| 3437 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3438 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3439 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3440 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3441 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3442 | struct channel *rep = si->ib; |
| 3443 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3444 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3445 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3446 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3447 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3448 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3449 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3450 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3451 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3452 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3453 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3454 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3455 | else |
| 3456 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3457 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3458 | if (bi_putchk(rep, &trash) == -1) |
| 3459 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3460 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3461 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3462 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3463 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3464 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3465 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3466 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3467 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3468 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3469 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3470 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3471 | appctx->ctx.stats.px = proxy; |
| 3472 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3473 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3474 | /* fall through */ |
| 3475 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3476 | case STAT_ST_LIST: |
| 3477 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3478 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3479 | if (buffer_almost_full(rep->buf)) |
| 3480 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3481 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3482 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3483 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 3484 | if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE))) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3485 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3486 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3487 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3488 | appctx->ctx.stats.px = px->next; |
| 3489 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3490 | } |
| 3491 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3492 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3493 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3494 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3495 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3496 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3497 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3498 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3499 | if (bi_putchk(rep, &trash) == -1) |
| 3500 | return 0; |
| 3501 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3502 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3503 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3504 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 3505 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3506 | case STAT_ST_FIN: |
| 3507 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3508 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3509 | default: |
| 3510 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3511 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3512 | return -1; |
| 3513 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3514 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3515 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3516 | /* We reached the stats page through a POST request. The appctx is |
| 3517 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3518 | * Parse the posted data and enable/disable servers if necessary. |
| 3519 | * Returns 1 if request was parsed or zero if it needs more data. |
| 3520 | */ |
| 3521 | static int stats_process_http_post(struct stream_interface *si) |
| 3522 | { |
| 3523 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3524 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3525 | |
| 3526 | struct proxy *px = NULL; |
| 3527 | struct server *sv = NULL; |
| 3528 | |
| 3529 | char key[LINESIZE]; |
| 3530 | int action = ST_ADM_ACTION_NONE; |
| 3531 | int reprocess = 0; |
| 3532 | |
| 3533 | int total_servers = 0; |
| 3534 | int altered_servers = 0; |
| 3535 | |
| 3536 | char *first_param, *cur_param, *next_param, *end_params; |
| 3537 | char *st_cur_param = NULL; |
| 3538 | char *st_next_param = NULL; |
| 3539 | |
| 3540 | struct chunk *temp; |
| 3541 | int reql; |
| 3542 | |
| 3543 | temp = get_trash_chunk(); |
| 3544 | if (temp->size < s->txn.req.body_len) { |
| 3545 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3546 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3547 | goto out; |
| 3548 | } |
| 3549 | |
| 3550 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 3551 | if (reql <= 0) { |
| 3552 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3553 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3554 | return 0; |
| 3555 | } |
| 3556 | |
| 3557 | first_param = temp->str; |
| 3558 | end_params = temp->str + reql; |
| 3559 | cur_param = next_param = end_params; |
| 3560 | *end_params = '\0'; |
| 3561 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3562 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3563 | |
| 3564 | /* |
| 3565 | * Parse the parameters in reverse order to only store the last value. |
| 3566 | * From the html form, the backend and the action are at the end. |
| 3567 | */ |
| 3568 | while (cur_param > first_param) { |
| 3569 | char *value; |
| 3570 | int poffset, plen; |
| 3571 | |
| 3572 | cur_param--; |
| 3573 | |
| 3574 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 3575 | reprocess_servers: |
| 3576 | /* Parse the key */ |
| 3577 | poffset = (cur_param != first_param ? 1 : 0); |
| 3578 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 3579 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 3580 | strncpy(key, cur_param + poffset, plen); |
| 3581 | key[plen - 1] = '\0'; |
| 3582 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3583 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3584 | goto out; |
| 3585 | } |
| 3586 | |
| 3587 | /* Parse the value */ |
| 3588 | value = key; |
| 3589 | while (*value != '\0' && *value != '=') { |
| 3590 | value++; |
| 3591 | } |
| 3592 | if (*value == '=') { |
| 3593 | /* Ok, a value is found, we can mark the end of the key */ |
| 3594 | *value++ = '\0'; |
| 3595 | } |
| 3596 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 3597 | break; |
| 3598 | |
| 3599 | /* Now we can check the key to see what to do */ |
| 3600 | if (!px && (strcmp(key, "b") == 0)) { |
| 3601 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 3602 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3603 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3604 | goto out; |
| 3605 | } |
| 3606 | } |
| 3607 | else if (!action && (strcmp(key, "action") == 0)) { |
| 3608 | if (strcmp(value, "disable") == 0) { |
| 3609 | action = ST_ADM_ACTION_DISABLE; |
| 3610 | } |
| 3611 | else if (strcmp(value, "enable") == 0) { |
| 3612 | action = ST_ADM_ACTION_ENABLE; |
| 3613 | } |
| 3614 | else if (strcmp(value, "stop") == 0) { |
| 3615 | action = ST_ADM_ACTION_STOP; |
| 3616 | } |
| 3617 | else if (strcmp(value, "start") == 0) { |
| 3618 | action = ST_ADM_ACTION_START; |
| 3619 | } |
| 3620 | else if (strcmp(value, "shutdown") == 0) { |
| 3621 | action = ST_ADM_ACTION_SHUTDOWN; |
| 3622 | } |
| 3623 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3624 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3625 | goto out; |
| 3626 | } |
| 3627 | } |
| 3628 | else if (strcmp(key, "s") == 0) { |
| 3629 | if (!(px && action)) { |
| 3630 | /* |
| 3631 | * Indicates that we'll need to reprocess the parameters |
| 3632 | * as soon as backend and action are known |
| 3633 | */ |
| 3634 | if (!reprocess) { |
| 3635 | st_cur_param = cur_param; |
| 3636 | st_next_param = next_param; |
| 3637 | } |
| 3638 | reprocess = 1; |
| 3639 | } |
| 3640 | else if ((sv = findserver(px, value)) != NULL) { |
| 3641 | switch (action) { |
| 3642 | case ST_ADM_ACTION_DISABLE: |
| 3643 | if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) { |
| 3644 | /* Not already in maintenance, we can change the server state */ |
| 3645 | sv->state |= SRV_MAINTAIN; |
| 3646 | set_server_down(&sv->check); |
| 3647 | altered_servers++; |
| 3648 | total_servers++; |
| 3649 | } |
| 3650 | break; |
| 3651 | case ST_ADM_ACTION_ENABLE: |
| 3652 | if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) { |
| 3653 | /* Already in maintenance, we can change the server state */ |
| 3654 | set_server_up(&sv->check); |
| 3655 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 3656 | altered_servers++; |
| 3657 | total_servers++; |
| 3658 | } |
| 3659 | break; |
| 3660 | case ST_ADM_ACTION_STOP: |
| 3661 | case ST_ADM_ACTION_START: |
| 3662 | if (action == ST_ADM_ACTION_START) |
| 3663 | sv->uweight = sv->iweight; |
| 3664 | else |
| 3665 | sv->uweight = 0; |
| 3666 | |
| 3667 | server_recalc_eweight(sv); |
| 3668 | set_server_drain_state(sv); |
| 3669 | |
| 3670 | altered_servers++; |
| 3671 | total_servers++; |
| 3672 | break; |
| 3673 | case ST_ADM_ACTION_SHUTDOWN: |
| 3674 | if (px->state != PR_STSTOPPED) { |
| 3675 | struct session *sess, *sess_bck; |
| 3676 | |
| 3677 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 3678 | if (sess->srv_conn == sv) |
| 3679 | session_shutdown(sess, SN_ERR_KILLED); |
| 3680 | |
| 3681 | altered_servers++; |
| 3682 | total_servers++; |
| 3683 | } |
| 3684 | break; |
| 3685 | } |
| 3686 | } else { |
| 3687 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 3688 | total_servers++; |
| 3689 | } |
| 3690 | } |
| 3691 | if (reprocess && px && action) { |
| 3692 | /* Now, we know the backend and the action chosen by the user. |
| 3693 | * We can safely restart from the first server parameter |
| 3694 | * to reprocess them |
| 3695 | */ |
| 3696 | cur_param = st_cur_param; |
| 3697 | next_param = st_next_param; |
| 3698 | reprocess = 0; |
| 3699 | goto reprocess_servers; |
| 3700 | } |
| 3701 | |
| 3702 | next_param = cur_param; |
| 3703 | } |
| 3704 | } |
| 3705 | |
| 3706 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3707 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3708 | } |
| 3709 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3710 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3711 | } |
| 3712 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3713 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3714 | } |
| 3715 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3716 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3717 | } |
| 3718 | out: |
| 3719 | return 1; |
| 3720 | } |
| 3721 | |
| 3722 | |
| 3723 | static int stats_send_http_headers(struct stream_interface *si) |
| 3724 | { |
| 3725 | struct session *s = session_from_task(si->owner); |
| 3726 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3727 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3728 | |
| 3729 | chunk_printf(&trash, |
| 3730 | "HTTP/1.0 200 OK\r\n" |
| 3731 | "Cache-Control: no-cache\r\n" |
| 3732 | "Connection: close\r\n" |
| 3733 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3734 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3735 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3736 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3737 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 3738 | uri->refresh); |
| 3739 | |
| 3740 | chunk_appendf(&trash, "\r\n"); |
| 3741 | |
| 3742 | s->txn.status = 200; |
| 3743 | s->logs.tv_request = now; |
| 3744 | |
| 3745 | if (bi_putchk(si->ib, &trash) == -1) |
| 3746 | return 0; |
| 3747 | |
| 3748 | return 1; |
| 3749 | } |
| 3750 | |
| 3751 | static int stats_send_http_redirect(struct stream_interface *si) |
| 3752 | { |
| 3753 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3754 | struct session *s = session_from_task(si->owner); |
| 3755 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3756 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3757 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3758 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3759 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3760 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3761 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3762 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3763 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | /* We don't want to land on the posted stats page because a refresh will |
| 3767 | * repost the data. We don't want this to happen on accident so we redirect |
| 3768 | * the browse to the stats page with a GET. |
| 3769 | */ |
| 3770 | chunk_printf(&trash, |
| 3771 | "HTTP/1.1 303 See Other\r\n" |
| 3772 | "Cache-Control: no-cache\r\n" |
| 3773 | "Content-Type: text/plain\r\n" |
| 3774 | "Connection: close\r\n" |
| 3775 | "Location: %s;st=%s%s%s%s\r\n" |
| 3776 | "\r\n", |
| 3777 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3778 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 3779 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 3780 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 3781 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3782 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3783 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3784 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3785 | scope_txt); |
| 3786 | |
| 3787 | s->txn.status = 303; |
| 3788 | s->logs.tv_request = now; |
| 3789 | |
| 3790 | if (bi_putchk(si->ib, &trash) == -1) |
| 3791 | return 0; |
| 3792 | |
| 3793 | return 1; |
| 3794 | } |
| 3795 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3796 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 3797 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3798 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3799 | * automatically unregisters itself once transfer is complete. |
| 3800 | */ |
| 3801 | static void http_stats_io_handler(struct stream_interface *si) |
| 3802 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3803 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3804 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3805 | struct channel *req = si->ob; |
| 3806 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3807 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3808 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 3809 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3810 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3811 | /* check that the output is not closed */ |
| 3812 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3813 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3814 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3815 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3816 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3817 | if (stats_send_http_headers(si)) { |
| 3818 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3819 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3820 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3821 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3822 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3823 | } |
| 3824 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3825 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3826 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3827 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3828 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3829 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3830 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3831 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3832 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3833 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3834 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3835 | } |
| 3836 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3837 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3838 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3839 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3840 | } |
| 3841 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3842 | if (appctx->st0 == STAT_HTTP_DONE) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3843 | si_shutw(si); |
| 3844 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3845 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 3846 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3847 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3848 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 3849 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 3850 | si_shutr(si); |
| 3851 | res->flags |= CF_READ_NULL; |
| 3852 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3853 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3854 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3855 | /* update all other flags and resync with the other side */ |
| 3856 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3857 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3858 | /* we don't want to expire timeouts while we're processing requests */ |
| 3859 | si->ib->rex = TICK_ETERNITY; |
| 3860 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3861 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3862 | out: |
| 3863 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 3864 | /* check that we have released everything then unregister */ |
| 3865 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3866 | } |
| 3867 | } |
| 3868 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3869 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3870 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 3871 | { |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 3872 | if (!(conn->flags & CO_FL_CTRL_READY) || !conn->ctrl) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3873 | return "NONE"; |
| 3874 | return conn->ctrl->name; |
| 3875 | } |
| 3876 | |
| 3877 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 3878 | { |
| 3879 | static char ptr[17]; |
| 3880 | |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 3881 | if (!(conn->flags & CO_FL_XPRT_READY) || !conn->xprt) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3882 | return "NONE"; |
| 3883 | |
| 3884 | if (conn->xprt == &raw_sock) |
| 3885 | return "RAW"; |
| 3886 | |
| 3887 | #ifdef USE_OPENSSL |
| 3888 | if (conn->xprt == &ssl_sock) |
| 3889 | return "SSL"; |
| 3890 | #endif |
| 3891 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 3892 | return ptr; |
| 3893 | } |
| 3894 | |
| 3895 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 3896 | { |
| 3897 | static char ptr[17]; |
| 3898 | |
| 3899 | if (!conn->data) |
| 3900 | return "NONE"; |
| 3901 | |
| 3902 | if (conn->data == &sess_conn_cb) |
| 3903 | return "SESS"; |
| 3904 | |
| 3905 | if (conn->data == &si_conn_cb) |
| 3906 | return "STRM"; |
| 3907 | |
| 3908 | if (conn->data == &check_conn_cb) |
| 3909 | return "CHCK"; |
| 3910 | |
| 3911 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 3912 | return ptr; |
| 3913 | } |
| 3914 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 3915 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3916 | * read buffer. The session has to be set in sess->target. It returns |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3917 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 3918 | * 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] | 3919 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3920 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3921 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3922 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3923 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3924 | extern const char *monthname[12]; |
| 3925 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3926 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 3927 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3928 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3929 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3930 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3931 | if (appctx->ctx.sess.section > 0 && appctx->ctx.sess.uid != sess->uniq_id) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3932 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3933 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 3934 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3935 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3936 | appctx->ctx.sess.uid = 0; |
| 3937 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3938 | return 1; |
| 3939 | } |
| 3940 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3941 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3942 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3943 | appctx->ctx.sess.uid = sess->uniq_id; |
| 3944 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3945 | /* fall through */ |
| 3946 | |
| 3947 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3948 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3949 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3950 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3951 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3952 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 3953 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3954 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 3955 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3956 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3957 | conn = objt_conn(sess->si[0].end); |
| 3958 | switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3959 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3960 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3961 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3962 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3963 | break; |
| 3964 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3965 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3966 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3967 | default: |
| 3968 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3969 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3970 | break; |
| 3971 | } |
| 3972 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3973 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3974 | " 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] | 3975 | 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] | 3976 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3977 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3978 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3979 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 3980 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 3981 | sess->listener ? sess->listener->luid : 0); |
| 3982 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3983 | if (conn) |
| 3984 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 3985 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3986 | switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3987 | case AF_INET: |
| 3988 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3989 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3990 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3991 | break; |
| 3992 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3993 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3994 | break; |
| 3995 | default: |
| 3996 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3997 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3998 | break; |
| 3999 | } |
| 4000 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4001 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4002 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4003 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4004 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4005 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 4006 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4007 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4008 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4009 | conn = objt_conn(sess->si[1].end); |
| 4010 | if (conn) |
| 4011 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4012 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4013 | switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4014 | case AF_INET: |
| 4015 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4016 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4017 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4018 | break; |
| 4019 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4020 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4021 | break; |
| 4022 | default: |
| 4023 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4024 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4025 | break; |
| 4026 | } |
| 4027 | |
| 4028 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4029 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4030 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4031 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 4032 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4033 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4034 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4035 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4036 | if (conn) |
| 4037 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4038 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4039 | switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4040 | case AF_INET: |
| 4041 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4042 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4043 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4044 | break; |
| 4045 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4046 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4047 | break; |
| 4048 | default: |
| 4049 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4050 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4051 | break; |
| 4052 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4053 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4054 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4055 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4056 | sess->task, |
| 4057 | sess->task->state, |
| 4058 | sess->task->nice, sess->task->calls, |
| 4059 | sess->task->expire ? |
| 4060 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4061 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4062 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4063 | task_in_rq(sess->task) ? ", running" : ""); |
| 4064 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4065 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4066 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4067 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4068 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4069 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4070 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4071 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4072 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4073 | |
| 4074 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4075 | " si[0]=%p (state=%s flags=0x%02x endp0=%s:%p exp=%s, et=0x%03x)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4076 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4077 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4078 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4079 | obj_type_name(sess->si[0].end), |
| 4080 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4081 | sess->si[0].exp ? |
| 4082 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4083 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4084 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4085 | sess->si[0].err_type); |
| 4086 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4087 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4088 | " si[1]=%p (state=%s flags=0x%02x endp1=%s:%p exp=%s, et=0x%03x)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4089 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4090 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4091 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4092 | obj_type_name(sess->si[1].end), |
| 4093 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4094 | sess->si[1].exp ? |
| 4095 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4096 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4097 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4098 | sess->si[1].err_type); |
| 4099 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4100 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4101 | chunk_appendf(&trash, |
| 4102 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4103 | conn, |
| 4104 | get_conn_ctrl_name(conn), |
| 4105 | get_conn_xprt_name(conn), |
| 4106 | get_conn_data_name(conn), |
| 4107 | obj_type_name(conn->target), |
| 4108 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4109 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4110 | chunk_appendf(&trash, |
| 4111 | " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4112 | conn->flags, |
| 4113 | conn->t.sock.fd, |
| 4114 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_e : 0, |
| 4115 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_p : 0, |
| 4116 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4117 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4118 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 4119 | chunk_appendf(&trash, |
| 4120 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4121 | tmpctx, |
| 4122 | tmpctx->st0, |
| 4123 | tmpctx->st1, |
| 4124 | tmpctx->st2, |
| 4125 | tmpctx->applet->name); |
| 4126 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4127 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4128 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4129 | chunk_appendf(&trash, |
| 4130 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4131 | conn, |
| 4132 | get_conn_ctrl_name(conn), |
| 4133 | get_conn_xprt_name(conn), |
| 4134 | get_conn_data_name(conn), |
| 4135 | obj_type_name(conn->target), |
| 4136 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4137 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4138 | chunk_appendf(&trash, |
| 4139 | " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4140 | conn->flags, |
| 4141 | conn->t.sock.fd, |
| 4142 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_e : 0, |
| 4143 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_p : 0, |
| 4144 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4145 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4146 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 4147 | chunk_appendf(&trash, |
| 4148 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4149 | tmpctx, |
| 4150 | tmpctx->st0, |
| 4151 | tmpctx->st1, |
| 4152 | tmpctx->st2, |
| 4153 | tmpctx->applet->name); |
| 4154 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4155 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4156 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4157 | " req=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4158 | " an_exp=%s", |
| 4159 | sess->req, |
| 4160 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4161 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4162 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4163 | sess->req->analyse_exp ? |
| 4164 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 4165 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4166 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4167 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4168 | " rex=%s", |
| 4169 | sess->req->rex ? |
| 4170 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4171 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4172 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4173 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4174 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4175 | " buf=%p data=%p o=%d p=%d req.next=%d i=%d size=%d\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4176 | sess->req->wex ? |
| 4177 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4178 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4179 | sess->req->buf, |
| 4180 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4181 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4182 | sess->txn.req.next, sess->req->buf->i, |
| 4183 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4184 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4185 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4186 | " res=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4187 | " an_exp=%s", |
| 4188 | sess->rep, |
| 4189 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4190 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4191 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4192 | sess->rep->analyse_exp ? |
| 4193 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 4194 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4195 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4196 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4197 | " rex=%s", |
| 4198 | sess->rep->rex ? |
| 4199 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4200 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4201 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4202 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4203 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4204 | " buf=%p data=%p o=%d p=%d rsp.next=%d i=%d size=%d\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4205 | sess->rep->wex ? |
| 4206 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4207 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4208 | sess->rep->buf, |
| 4209 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4210 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4211 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4212 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4213 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4214 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4215 | return 0; |
| 4216 | |
| 4217 | /* use other states to dump the contents */ |
| 4218 | } |
| 4219 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4220 | appctx->ctx.sess.uid = 0; |
| 4221 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4222 | return 1; |
| 4223 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4224 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4225 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4226 | * read buffer. It returns 0 if the output buffer is full and it needs |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 4227 | * to be called again, otherwise non-zero. It is designed to be called |
| 4228 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4229 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4230 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4231 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4232 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4233 | struct connection *conn; |
| 4234 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4235 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4236 | /* If we're forced to shut down, we might have to remove our |
| 4237 | * reference to the last session being dumped. |
| 4238 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4239 | if (appctx->st2 == STAT_ST_LIST) { |
| 4240 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 4241 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 4242 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4243 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4244 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4245 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4246 | } |
| 4247 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4248 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4249 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4250 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4251 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4252 | /* the function had not been called yet, let's prepare the |
| 4253 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4254 | * pointer to the first in the global list. When a target |
| 4255 | * session is being destroyed, it is responsible for updating |
| 4256 | * this pointer. We know we have reached the end when this |
| 4257 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4258 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4259 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 4260 | appctx->ctx.sess.bref.ref = sessions.n; |
| 4261 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4262 | /* fall through */ |
| 4263 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4264 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4265 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4266 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 4267 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 4268 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4272 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 4273 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4274 | struct session *curr_sess; |
| 4275 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4276 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4277 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4278 | if (appctx->ctx.sess.target) { |
| 4279 | if (appctx->ctx.sess.target != (void *)-1 && appctx->ctx.sess.target != curr_sess) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4280 | goto next_sess; |
| 4281 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4282 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4283 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4284 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4285 | return 0; |
| 4286 | |
| 4287 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4288 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 4289 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 4290 | if (appctx->ctx.sess.target != (void *)-1) { |
| 4291 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4292 | break; |
| 4293 | } |
| 4294 | else |
| 4295 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4296 | } |
| 4297 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4298 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4299 | "%p: proto=%s", |
| 4300 | curr_sess, |
| 4301 | curr_sess->listener->proto->name); |
| 4302 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4303 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4304 | conn = objt_conn(curr_sess->si[0].end); |
| 4305 | switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 4306 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4307 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4308 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4309 | " src=%s:%d fe=%s be=%s srv=%s", |
| 4310 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4311 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4312 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4313 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4314 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4315 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4316 | break; |
| 4317 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4318 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4319 | " src=unix:%d fe=%s be=%s srv=%s", |
| 4320 | curr_sess->listener->luid, |
| 4321 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4322 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4323 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4324 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4325 | break; |
| 4326 | } |
| 4327 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4328 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 4329 | " ts=%02x age=%s calls=%d", |
| 4330 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 4331 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 4332 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4333 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4334 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 4335 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4336 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4337 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4338 | curr_sess->req->analysers, |
| 4339 | curr_sess->req->rex ? |
| 4340 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 4341 | TICKS_TO_MS(1000)) : ""); |
| 4342 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4343 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4344 | ",wx=%s", |
| 4345 | curr_sess->req->wex ? |
| 4346 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 4347 | TICKS_TO_MS(1000)) : ""); |
| 4348 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4349 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4350 | ",ax=%s]", |
| 4351 | curr_sess->req->analyse_exp ? |
| 4352 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 4353 | TICKS_TO_MS(1000)) : ""); |
| 4354 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4355 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 4356 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4357 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4358 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4359 | curr_sess->rep->analysers, |
| 4360 | curr_sess->rep->rex ? |
| 4361 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 4362 | TICKS_TO_MS(1000)) : ""); |
| 4363 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4364 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4365 | ",wx=%s", |
| 4366 | curr_sess->rep->wex ? |
| 4367 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 4368 | TICKS_TO_MS(1000)) : ""); |
| 4369 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4370 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4371 | ",ax=%s]", |
| 4372 | curr_sess->rep->analyse_exp ? |
| 4373 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 4374 | TICKS_TO_MS(1000)) : ""); |
| 4375 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4376 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4377 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4378 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 4379 | curr_sess->si[0].state, |
| 4380 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4381 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4382 | curr_sess->si[0].exp ? |
| 4383 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 4384 | TICKS_TO_MS(1000)) : ""); |
| 4385 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4386 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4387 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4388 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 4389 | curr_sess->si[1].state, |
| 4390 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4391 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4392 | curr_sess->si[1].exp ? |
| 4393 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 4394 | TICKS_TO_MS(1000)) : ""); |
| 4395 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4396 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4397 | " exp=%s", |
| 4398 | curr_sess->task->expire ? |
| 4399 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 4400 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 4401 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4402 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4403 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4404 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4405 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4406 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4407 | /* let's try again later from this session. We add ourselves into |
| 4408 | * this session's users so that it can remove us upon termination. |
| 4409 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4410 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4411 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4412 | } |
| 4413 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4414 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4415 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4416 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4417 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4418 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4419 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4420 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4421 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4422 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4423 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4424 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4425 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4426 | return 0; |
| 4427 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4428 | appctx->ctx.sess.target = NULL; |
| 4429 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4430 | return 1; |
| 4431 | } |
| 4432 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4433 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4434 | /* fall through */ |
| 4435 | |
| 4436 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4437 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4438 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4439 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 4440 | } |
| 4441 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4442 | /* This is called when the stream interface is closed. For instance, upon an |
| 4443 | * external abort, we won't call the i/o handler anymore so we may need to |
| 4444 | * remove back references to the session currently being dumped. |
| 4445 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 4446 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4447 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4448 | struct appctx *appctx = __objt_appctx(si->end); |
| 4449 | |
| 4450 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 4451 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 4452 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4453 | } |
| 4454 | } |
| 4455 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4456 | /* This function is used to either dump tables states (when action is set |
| 4457 | * to STAT_CLI_O_TAB) or clear tables (when action is STAT_CLI_O_CLR). |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4458 | * It returns 0 if the output buffer is full and it needs to be called |
| 4459 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4460 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4461 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4462 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4463 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4464 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4465 | struct ebmb_node *eb; |
| 4466 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4467 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4468 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4469 | |
| 4470 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4471 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4472 | * - STAT_ST_INIT : the first call |
| 4473 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4474 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4475 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4476 | * and the entry pointer points to the next entry to be dumped, |
| 4477 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4478 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4479 | * data though. |
| 4480 | */ |
| 4481 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4482 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4483 | /* in case of abort, remove any refcount we might have set on an entry */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4484 | if (appctx->st2 == STAT_ST_LIST) { |
| 4485 | appctx->ctx.table.entry->ref_cnt--; |
| 4486 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 4487 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4488 | return 1; |
| 4489 | } |
| 4490 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4491 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4492 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4493 | while (appctx->st2 != STAT_ST_FIN) { |
| 4494 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4495 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4496 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 4497 | if (!appctx->ctx.table.proxy) |
| 4498 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4499 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4500 | appctx->ctx.table.entry = NULL; |
| 4501 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4502 | break; |
| 4503 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4504 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4505 | if (!appctx->ctx.table.proxy || |
| 4506 | (appctx->ctx.table.target && |
| 4507 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 4508 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4509 | break; |
| 4510 | } |
| 4511 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4512 | if (appctx->ctx.table.proxy->table.size) { |
| 4513 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 4514 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4515 | return 0; |
| 4516 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4517 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 4518 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4519 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4520 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4521 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4522 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 4523 | appctx->ctx.table.entry->ref_cnt++; |
| 4524 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4525 | break; |
| 4526 | } |
| 4527 | } |
| 4528 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4529 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4530 | break; |
| 4531 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4532 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4533 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4534 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4535 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4536 | /* we're filtering on some data contents */ |
| 4537 | void *ptr; |
| 4538 | long long data; |
| 4539 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4540 | dt = appctx->ctx.table.data_type; |
| 4541 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 4542 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4543 | dt); |
| 4544 | |
| 4545 | data = 0; |
| 4546 | switch (stktable_data_types[dt].std_type) { |
| 4547 | case STD_T_SINT: |
| 4548 | data = stktable_data_cast(ptr, std_t_sint); |
| 4549 | break; |
| 4550 | case STD_T_UINT: |
| 4551 | data = stktable_data_cast(ptr, std_t_uint); |
| 4552 | break; |
| 4553 | case STD_T_ULL: |
| 4554 | data = stktable_data_cast(ptr, std_t_ull); |
| 4555 | break; |
| 4556 | case STD_T_FRQP: |
| 4557 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4558 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4559 | break; |
| 4560 | } |
| 4561 | |
| 4562 | /* skip the entry if the data does not match the test and the value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4563 | if ((data < appctx->ctx.table.value && |
| 4564 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 4565 | appctx->ctx.table.data_op == STD_OP_GT || |
| 4566 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 4567 | (data == appctx->ctx.table.value && |
| 4568 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 4569 | appctx->ctx.table.data_op == STD_OP_GT || |
| 4570 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 4571 | (data > appctx->ctx.table.value && |
| 4572 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 4573 | appctx->ctx.table.data_op == STD_OP_LT || |
| 4574 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4575 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4576 | } |
| 4577 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4578 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4579 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 4580 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 4581 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4582 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4583 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4584 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4585 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4586 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4587 | struct stksess *old = appctx->ctx.table.entry; |
| 4588 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 4589 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4590 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 4591 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 4592 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 4593 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4594 | break; |
| 4595 | } |
| 4596 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4597 | |
| 4598 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4599 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 4600 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 4601 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4602 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4603 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 4604 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4605 | break; |
| 4606 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4607 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4608 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4609 | break; |
| 4610 | } |
| 4611 | } |
| 4612 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4613 | } |
| 4614 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4615 | /* 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] | 4616 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 4617 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 4618 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 4619 | * lines are respected within the limit of 70 output chars. Lines that are |
| 4620 | * continuation of a previous truncated line begin with "+" instead of " " |
| 4621 | * after the offset. The new pointer is returned. |
| 4622 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4623 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 4624 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4625 | { |
| 4626 | int end; |
| 4627 | unsigned char c; |
| 4628 | |
| 4629 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4630 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4631 | return ptr; |
| 4632 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 4633 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4634 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4635 | while (ptr < len && ptr < bsize) { |
| 4636 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4637 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4638 | if (out->len > end - 2) |
| 4639 | break; |
| 4640 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4641 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4642 | if (out->len > end - 3) |
| 4643 | break; |
| 4644 | out->str[out->len++] = '\\'; |
| 4645 | switch (c) { |
| 4646 | case '\t': c = 't'; break; |
| 4647 | case '\n': c = 'n'; break; |
| 4648 | case '\r': c = 'r'; break; |
| 4649 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4650 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4651 | } |
| 4652 | out->str[out->len++] = c; |
| 4653 | } else { |
| 4654 | if (out->len > end - 5) |
| 4655 | break; |
| 4656 | out->str[out->len++] = '\\'; |
| 4657 | out->str[out->len++] = 'x'; |
| 4658 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 4659 | out->str[out->len++] = hextab[c & 0xF]; |
| 4660 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4661 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4662 | /* we had a line break, let's return now */ |
| 4663 | out->str[out->len++] = '\n'; |
| 4664 | *line = ptr; |
| 4665 | return ptr; |
| 4666 | } |
| 4667 | } |
| 4668 | /* we have an incomplete line, we return it as-is */ |
| 4669 | out->str[out->len++] = '\n'; |
| 4670 | return ptr; |
| 4671 | } |
| 4672 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4673 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4674 | * read buffer. It returns 0 if the output buffer is full and it needs |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 4675 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4676 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4677 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4678 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4679 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4680 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4681 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4682 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4683 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4684 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4685 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4686 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4687 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4688 | /* the function had not been called yet, let's prepare the |
| 4689 | * buffer for a response. |
| 4690 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4691 | struct tm tm; |
| 4692 | |
| 4693 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4694 | chunk_appendf(&trash, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n", |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4695 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4696 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 4697 | error_snapshot_id); |
| 4698 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4699 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4700 | /* Socket buffer full. Let's try again later from the same point */ |
| 4701 | return 0; |
| 4702 | } |
| 4703 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4704 | appctx->ctx.errors.px = proxy; |
| 4705 | appctx->ctx.errors.buf = 0; |
| 4706 | appctx->ctx.errors.bol = 0; |
| 4707 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | /* we have two inner loops here, one for the proxy, the other one for |
| 4711 | * the buffer. |
| 4712 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4713 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4714 | struct error_snapshot *es; |
| 4715 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4716 | if (appctx->ctx.errors.buf == 0) |
| 4717 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4718 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4719 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4720 | |
| 4721 | if (!es->when.tv_sec) |
| 4722 | goto next; |
| 4723 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4724 | if (appctx->ctx.errors.iid >= 0 && |
| 4725 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 4726 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4727 | goto next; |
| 4728 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4729 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4730 | /* just print headers now */ |
| 4731 | |
| 4732 | char pn[INET6_ADDRSTRLEN]; |
| 4733 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4734 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4735 | |
| 4736 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4737 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4738 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4739 | 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] | 4740 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4741 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 4742 | case AF_INET: |
| 4743 | case AF_INET6: |
| 4744 | port = get_host_port(&es->src); |
| 4745 | break; |
| 4746 | default: |
| 4747 | port = 0; |
| 4748 | } |
| 4749 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4750 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4751 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4752 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4753 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4754 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4755 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4756 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 4757 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4758 | break; |
| 4759 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4760 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4761 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4762 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4763 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4764 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4765 | break; |
| 4766 | } |
| 4767 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4768 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4769 | ", server %s (#%d), event #%u\n" |
| 4770 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 4771 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 4772 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 4773 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 4774 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 4775 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 4776 | es->ev_id, |
| 4777 | pn, port, es->sid, es->s_flags, |
| 4778 | es->state, es->m_flags, es->t_flags, |
| 4779 | es->m_clen, es->m_blen, |
| 4780 | es->b_flags, es->b_out, es->b_tot, |
| 4781 | es->len, es->b_wrap, es->pos); |
| 4782 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4783 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4784 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4785 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4786 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4787 | appctx->ctx.errors.ptr = 0; |
| 4788 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4789 | } |
| 4790 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4791 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4792 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4793 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4794 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4795 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4796 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4797 | goto next; |
| 4798 | } |
| 4799 | |
| 4800 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4801 | while (appctx->ctx.errors.ptr < es->len && appctx->ctx.errors.ptr < sizeof(es->buf)) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4802 | int newptr; |
| 4803 | int newline; |
| 4804 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4805 | newline = appctx->ctx.errors.bol; |
| 4806 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 4807 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4808 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4809 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4810 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4811 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4812 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4813 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4814 | appctx->ctx.errors.ptr = newptr; |
| 4815 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4816 | }; |
| 4817 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4818 | appctx->ctx.errors.bol = 0; |
| 4819 | appctx->ctx.errors.ptr = -1; |
| 4820 | appctx->ctx.errors.buf++; |
| 4821 | if (appctx->ctx.errors.buf > 1) { |
| 4822 | appctx->ctx.errors.buf = 0; |
| 4823 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4824 | } |
| 4825 | } |
| 4826 | |
| 4827 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4828 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4829 | } |
| 4830 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4831 | /* parse the "level" argument on the bind lines */ |
| 4832 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 4833 | { |
| 4834 | if (!*args[cur_arg + 1]) { |
| 4835 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 4836 | return ERR_ALERT | ERR_FATAL; |
| 4837 | } |
| 4838 | |
| 4839 | if (!strcmp(args[cur_arg+1], "user")) |
| 4840 | conf->level = ACCESS_LVL_USER; |
| 4841 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 4842 | conf->level = ACCESS_LVL_OPER; |
| 4843 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 4844 | conf->level = ACCESS_LVL_ADMIN; |
| 4845 | else { |
| 4846 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 4847 | args[cur_arg], args[cur_arg+1]); |
| 4848 | return ERR_ALERT | ERR_FATAL; |
| 4849 | } |
| 4850 | |
| 4851 | return 0; |
| 4852 | } |
| 4853 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4854 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4855 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4856 | .name = "<STATS>", /* used for logging */ |
| 4857 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 4858 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4859 | }; |
| 4860 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4861 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4862 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4863 | .name = "<CLI>", /* used for logging */ |
| 4864 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4865 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4866 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4867 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 4868 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4869 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 4870 | { 0, NULL, NULL }, |
| 4871 | }}; |
| 4872 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4873 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 4874 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 4875 | { NULL, NULL, 0 }, |
| 4876 | }}; |
| 4877 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4878 | __attribute__((constructor)) |
| 4879 | static void __dumpstats_module_init(void) |
| 4880 | { |
| 4881 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4882 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4883 | } |
| 4884 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4885 | /* |
| 4886 | * Local variables: |
| 4887 | * c-indent-level: 8 |
| 4888 | * c-basic-offset: 8 |
| 4889 | * End: |
| 4890 | */ |