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; |
| 929 | |
| 930 | while (isspace((unsigned char)*line)) |
| 931 | line++; |
| 932 | |
| 933 | arg = 0; |
| 934 | args[arg] = line; |
| 935 | |
| 936 | while (*line && arg < MAX_STATS_ARGS) { |
| 937 | if (isspace((unsigned char)*line)) { |
| 938 | *line++ = '\0'; |
| 939 | |
| 940 | while (isspace((unsigned char)*line)) |
| 941 | line++; |
| 942 | |
| 943 | args[++arg] = line; |
| 944 | continue; |
| 945 | } |
| 946 | |
| 947 | line++; |
| 948 | } |
| 949 | |
| 950 | while (++arg <= MAX_STATS_ARGS) |
| 951 | args[arg] = line; |
| 952 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 953 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 954 | if (strcmp(args[0], "show") == 0) { |
| 955 | if (strcmp(args[1], "stat") == 0) { |
| 956 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 957 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 958 | appctx->ctx.stats.iid = atoi(args[2]); |
| 959 | appctx->ctx.stats.type = atoi(args[3]); |
| 960 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 961 | } |
| 962 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 963 | appctx->st2 = STAT_ST_INIT; |
| 964 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 965 | } |
| 966 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 967 | appctx->st2 = STAT_ST_INIT; |
| 968 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 969 | } |
| 970 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 971 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 972 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 973 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 974 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 975 | return 1; |
| 976 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 977 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 978 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 979 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 980 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 981 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 982 | appctx->ctx.sess.target = NULL; |
| 983 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 984 | appctx->ctx.sess.pos = 0; |
| 985 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 986 | } |
| 987 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 988 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 989 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 990 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 991 | return 1; |
| 992 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 993 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 994 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 995 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 996 | appctx->ctx.errors.iid = -1; |
| 997 | appctx->ctx.errors.px = NULL; |
| 998 | appctx->st2 = STAT_ST_INIT; |
| 999 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1000 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1001 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1002 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1003 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1004 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1005 | return 0; |
| 1006 | } |
| 1007 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1008 | else if (strcmp(args[0], "clear") == 0) { |
| 1009 | if (strcmp(args[1], "counters") == 0) { |
| 1010 | struct proxy *px; |
| 1011 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1012 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1013 | int clrall = 0; |
| 1014 | |
| 1015 | if (strcmp(args[2], "all") == 0) |
| 1016 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1017 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1018 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1019 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1020 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1021 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1022 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1023 | return 1; |
| 1024 | } |
| 1025 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1026 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1027 | if (clrall) { |
| 1028 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1029 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1030 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1031 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1032 | px->be_counters.conn_max = 0; |
| 1033 | px->be_counters.p.http.rps_max = 0; |
| 1034 | px->be_counters.sps_max = 0; |
| 1035 | px->be_counters.cps_max = 0; |
| 1036 | px->be_counters.nbpend_max = 0; |
| 1037 | |
| 1038 | px->fe_counters.conn_max = 0; |
| 1039 | px->fe_counters.p.http.rps_max = 0; |
| 1040 | px->fe_counters.sps_max = 0; |
| 1041 | px->fe_counters.cps_max = 0; |
| 1042 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1043 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1044 | |
| 1045 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1046 | if (clrall) |
| 1047 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1048 | else { |
| 1049 | sv->counters.cur_sess_max = 0; |
| 1050 | sv->counters.nbpend_max = 0; |
| 1051 | sv->counters.sps_max = 0; |
| 1052 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1053 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1054 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1055 | if (li->counters) { |
| 1056 | if (clrall) |
| 1057 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1058 | else |
| 1059 | li->counters->conn_max = 0; |
| 1060 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1061 | } |
| 1062 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1063 | global.cps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1064 | return 1; |
| 1065 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1066 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1067 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1068 | /* end of processing */ |
| 1069 | return 1; |
| 1070 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1071 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1072 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1073 | return 0; |
| 1074 | } |
| 1075 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1076 | else if (strcmp(args[0], "get") == 0) { |
| 1077 | if (strcmp(args[1], "weight") == 0) { |
| 1078 | struct proxy *px; |
| 1079 | struct server *sv; |
| 1080 | |
| 1081 | /* split "backend/server" and make <line> point to server */ |
| 1082 | for (line = args[2]; *line; line++) |
| 1083 | if (*line == '/') { |
| 1084 | *line++ = '\0'; |
| 1085 | break; |
| 1086 | } |
| 1087 | |
| 1088 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1089 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1090 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1091 | return 1; |
| 1092 | } |
| 1093 | |
| 1094 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1095 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1096 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1097 | return 1; |
| 1098 | } |
| 1099 | |
| 1100 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1101 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1102 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1103 | return 1; |
| 1104 | } |
| 1105 | else { /* not "get weight" */ |
| 1106 | return 0; |
| 1107 | } |
| 1108 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1109 | else if (strcmp(args[0], "set") == 0) { |
| 1110 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1111 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1112 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1113 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1114 | sv = expect_server_admin(s, si, args[2]); |
| 1115 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1116 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1117 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1118 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1119 | /* |
| 1120 | * The user-weight may now be zero and thus |
| 1121 | * the server considered to be draining. |
| 1122 | * Update the server's drain state as necessary. |
| 1123 | */ |
| 1124 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1125 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1126 | appctx->ctx.cli.msg = warning; |
| 1127 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1128 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1129 | return 1; |
| 1130 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1131 | else if (strcmp(args[1], "timeout") == 0) { |
| 1132 | if (strcmp(args[2], "cli") == 0) { |
| 1133 | unsigned timeout; |
| 1134 | const char *res; |
| 1135 | |
| 1136 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1137 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1138 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1139 | return 1; |
| 1140 | } |
| 1141 | |
| 1142 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1143 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1144 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1145 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1146 | return 1; |
| 1147 | } |
| 1148 | |
| 1149 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1150 | return 1; |
| 1151 | } |
| 1152 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1153 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1154 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1155 | return 1; |
| 1156 | } |
| 1157 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1158 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1159 | if (strcmp(args[2], "frontend") == 0) { |
| 1160 | struct proxy *px; |
| 1161 | struct listener *l; |
| 1162 | int v; |
| 1163 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1164 | px = expect_frontend_admin(s, si, args[3]); |
| 1165 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1166 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1167 | |
| 1168 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1169 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1170 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1171 | return 1; |
| 1172 | } |
| 1173 | |
| 1174 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1175 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1176 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1177 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1178 | return 1; |
| 1179 | } |
| 1180 | |
| 1181 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1182 | * its listeners. The blocked ones will be dequeued. |
| 1183 | */ |
| 1184 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1185 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1186 | l->maxconn = v; |
| 1187 | if (l->state == LI_FULL) |
| 1188 | resume_listener(l); |
| 1189 | } |
| 1190 | |
| 1191 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1192 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1193 | |
| 1194 | return 1; |
| 1195 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1196 | else if (strcmp(args[2], "global") == 0) { |
| 1197 | int v; |
| 1198 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1199 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1200 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1201 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1202 | return 1; |
| 1203 | } |
| 1204 | |
| 1205 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1206 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1207 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1208 | return 1; |
| 1209 | } |
| 1210 | |
| 1211 | v = atoi(args[3]); |
| 1212 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1213 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1214 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1215 | return 1; |
| 1216 | } |
| 1217 | |
| 1218 | /* check for unlimited values */ |
| 1219 | if (v <= 0) |
| 1220 | v = global.hardmaxconn; |
| 1221 | |
| 1222 | global.maxconn = v; |
| 1223 | |
| 1224 | /* Dequeues all of the listeners waiting for a resource */ |
| 1225 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1226 | dequeue_all_listeners(&global_listener_queue); |
| 1227 | |
| 1228 | return 1; |
| 1229 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1230 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1231 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1232 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1233 | return 1; |
| 1234 | } |
| 1235 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1236 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1237 | if (strcmp(args[2], "connections") == 0) { |
| 1238 | if (strcmp(args[3], "global") == 0) { |
| 1239 | int v; |
| 1240 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1241 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1242 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1243 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1244 | return 1; |
| 1245 | } |
| 1246 | |
| 1247 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1248 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1249 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1250 | return 1; |
| 1251 | } |
| 1252 | |
| 1253 | v = atoi(args[4]); |
| 1254 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1255 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1256 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1257 | return 1; |
| 1258 | } |
| 1259 | |
| 1260 | global.cps_lim = v; |
| 1261 | |
| 1262 | /* Dequeues all of the listeners waiting for a resource */ |
| 1263 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1264 | dequeue_all_listeners(&global_listener_queue); |
| 1265 | |
| 1266 | return 1; |
| 1267 | } |
| 1268 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1269 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1270 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1271 | return 1; |
| 1272 | } |
| 1273 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1274 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1275 | if (strcmp(args[3], "global") == 0) { |
| 1276 | int v; |
| 1277 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1278 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1279 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1280 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1281 | return 1; |
| 1282 | } |
| 1283 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1284 | v = atoi(args[4]); |
| 1285 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1286 | } |
| 1287 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1288 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1289 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1290 | return 1; |
| 1291 | } |
| 1292 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1293 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1294 | appctx->ctx.cli.msg = "'set rate-limit' supports 'connections' and 'http-compression'.\n"; |
| 1295 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1296 | return 1; |
| 1297 | } |
| 1298 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1299 | else if (strcmp(args[1], "table") == 0) { |
| 1300 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1301 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1302 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1303 | return 0; |
| 1304 | } |
| 1305 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1306 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1307 | if (strcmp(args[1], "agent") == 0) { |
| 1308 | struct server *sv; |
| 1309 | |
| 1310 | sv = expect_server_admin(s, si, args[2]); |
| 1311 | if (!sv) |
| 1312 | return 1; |
| 1313 | |
| 1314 | sv->agent.state &= ~CHK_STATE_DISABLED; |
| 1315 | |
| 1316 | return 1; |
| 1317 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1318 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1319 | struct server *sv; |
| 1320 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1321 | sv = expect_server_admin(s, si, args[2]); |
| 1322 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1323 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1324 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1325 | if (sv->state & SRV_MAINTAIN) { |
| 1326 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1327 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1328 | /* If this server tracks the status of another one, |
| 1329 | * we must restore the good status. |
| 1330 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1331 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1332 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1333 | 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] | 1334 | } else { |
| 1335 | sv->state &= ~SRV_MAINTAIN; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1336 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1337 | } |
| 1338 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1339 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1340 | 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] | 1341 | } |
| 1342 | } |
| 1343 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1344 | return 1; |
| 1345 | } |
| 1346 | else if (strcmp(args[1], "frontend") == 0) { |
| 1347 | struct proxy *px; |
| 1348 | |
| 1349 | px = expect_frontend_admin(s, si, args[2]); |
| 1350 | if (!px) |
| 1351 | return 1; |
| 1352 | |
| 1353 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1354 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1355 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1356 | return 1; |
| 1357 | } |
| 1358 | |
| 1359 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1360 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1361 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1362 | return 1; |
| 1363 | } |
| 1364 | |
| 1365 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1366 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1367 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1368 | return 1; |
| 1369 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1370 | return 1; |
| 1371 | } |
| 1372 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1373 | appctx->ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1374 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1375 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1379 | if (strcmp(args[1], "agent") == 0) { |
| 1380 | struct server *sv; |
| 1381 | |
| 1382 | sv = expect_server_admin(s, si, args[2]); |
| 1383 | if (!sv) |
| 1384 | return 1; |
| 1385 | |
| 1386 | sv->agent.state |= CHK_STATE_DISABLED; |
| 1387 | |
| 1388 | return 1; |
| 1389 | } |
| 1390 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1391 | struct server *sv; |
| 1392 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1393 | sv = expect_server_admin(s, si, args[2]); |
| 1394 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1395 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1396 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1397 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1398 | /* Not already in maintenance, we can change the server state */ |
| 1399 | sv->state |= SRV_MAINTAIN; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1400 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1401 | } |
| 1402 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1403 | return 1; |
| 1404 | } |
| 1405 | else if (strcmp(args[1], "frontend") == 0) { |
| 1406 | struct proxy *px; |
| 1407 | |
| 1408 | px = expect_frontend_admin(s, si, args[2]); |
| 1409 | if (!px) |
| 1410 | return 1; |
| 1411 | |
| 1412 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1413 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1414 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1415 | return 1; |
| 1416 | } |
| 1417 | |
| 1418 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1419 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1420 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1421 | return 1; |
| 1422 | } |
| 1423 | |
| 1424 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1425 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1426 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1427 | return 1; |
| 1428 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1429 | return 1; |
| 1430 | } |
| 1431 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1432 | appctx->ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1433 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1434 | return 1; |
| 1435 | } |
| 1436 | } |
| 1437 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1438 | if (strcmp(args[1], "frontend") == 0) { |
| 1439 | struct proxy *px; |
| 1440 | |
| 1441 | px = expect_frontend_admin(s, si, args[2]); |
| 1442 | if (!px) |
| 1443 | return 1; |
| 1444 | |
| 1445 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1446 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1447 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1448 | return 1; |
| 1449 | } |
| 1450 | |
| 1451 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1452 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1453 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1454 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1455 | stop_proxy(px); |
| 1456 | return 1; |
| 1457 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1458 | else if (strcmp(args[1], "session") == 0) { |
| 1459 | struct session *sess, *ptr; |
| 1460 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1461 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1462 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1463 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1464 | return 1; |
| 1465 | } |
| 1466 | |
| 1467 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1468 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1469 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1470 | return 1; |
| 1471 | } |
| 1472 | |
| 1473 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1474 | |
| 1475 | /* first, look for the requested session in the session table */ |
| 1476 | list_for_each_entry(sess, &sessions, list) { |
| 1477 | if (sess == ptr) |
| 1478 | break; |
| 1479 | } |
| 1480 | |
| 1481 | /* do we have the session ? */ |
| 1482 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1483 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1484 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1485 | return 1; |
| 1486 | } |
| 1487 | |
| 1488 | session_shutdown(sess, SN_ERR_KILLED); |
| 1489 | return 1; |
| 1490 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1491 | else if (strcmp(args[1], "sessions") == 0) { |
| 1492 | if (strcmp(args[2], "server") == 0) { |
| 1493 | struct server *sv; |
| 1494 | struct session *sess, *sess_bck; |
| 1495 | |
| 1496 | sv = expect_server_admin(s, si, args[3]); |
| 1497 | if (!sv) |
| 1498 | return 1; |
| 1499 | |
| 1500 | /* kill all the session that are on this server */ |
| 1501 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1502 | if (sess->srv_conn == sv) |
| 1503 | session_shutdown(sess, SN_ERR_KILLED); |
| 1504 | |
| 1505 | return 1; |
| 1506 | } |
| 1507 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1508 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1509 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1510 | return 1; |
| 1511 | } |
| 1512 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1513 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1514 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1515 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1516 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | 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] | 1520 | return 0; |
| 1521 | } |
| 1522 | return 1; |
| 1523 | } |
| 1524 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1525 | /* 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] | 1526 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 1527 | * state machine handling requests and various responses. We read a request, |
| 1528 | * 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] | 1529 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 1530 | * 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] | 1531 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1532 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 1533 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1534 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1535 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1536 | struct channel *req = si->ob; |
| 1537 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1538 | int reql; |
| 1539 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1540 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1541 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 1542 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1543 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1544 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1545 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1546 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1547 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 1548 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1549 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1550 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1551 | /* Let's close for real now. We just close the request |
| 1552 | * side, the conditions below will complete if needed. |
| 1553 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1554 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1555 | break; |
| 1556 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1557 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1558 | /* ensure we have some output room left in the event we |
| 1559 | * would want to return some info right after parsing. |
| 1560 | */ |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1561 | if (buffer_almost_full(si->ib->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1562 | break; |
| 1563 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1564 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1565 | if (reql <= 0) { /* closed or EOL not found */ |
| 1566 | if (reql == 0) |
| 1567 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1568 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1569 | continue; |
| 1570 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1571 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1572 | /* seek for a possible semi-colon. If we find one, we |
| 1573 | * replace it with an LF and skip only this part. |
| 1574 | */ |
| 1575 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1576 | if (trash.str[len] == ';') { |
| 1577 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1578 | reql = len + 1; |
| 1579 | break; |
| 1580 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1581 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1582 | /* now it is time to check that we have a full line, |
| 1583 | * remove the trailing \n and possibly \r, then cut the |
| 1584 | * line. |
| 1585 | */ |
| 1586 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1587 | if (trash.str[len] != '\n') { |
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; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1590 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1591 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1592 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1593 | len--; |
| 1594 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1595 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1596 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1597 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1598 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1599 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1600 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1601 | continue; |
| 1602 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1603 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1604 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1605 | else if (strcmp(trash.str, "help") == 0 || |
| 1606 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1607 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 1608 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1609 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1610 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1611 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1612 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1613 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1614 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1615 | /* if prompt is disabled, print help on empty lines, |
| 1616 | * so that the user at least knows how to enable |
| 1617 | * prompt and find help. |
| 1618 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1619 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 1620 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1624 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1625 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1626 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1627 | 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] | 1628 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1629 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1630 | continue; |
| 1631 | } |
| 1632 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1633 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1634 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1635 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 1636 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1637 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1638 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1639 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1640 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1641 | break; |
| 1642 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1643 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1644 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1645 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1646 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1647 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1648 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1649 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1650 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1651 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1652 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1653 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1654 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1655 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1656 | if (stats_table_request(si, appctx->st0)) |
| 1657 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1658 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1659 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1660 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1661 | break; |
| 1662 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1663 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1664 | /* 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] | 1665 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 1666 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 1667 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1668 | } |
| 1669 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1670 | /* 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] | 1671 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1672 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1673 | |
| 1674 | /* Now we close the output if one of the writers did so, |
| 1675 | * or if we're not in interactive mode and the request |
| 1676 | * buffer is empty. This still allows pipelined requests |
| 1677 | * to be sent in non-interactive mode. |
| 1678 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1679 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 1680 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1681 | continue; |
| 1682 | } |
| 1683 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1684 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1685 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1686 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1687 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1688 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1689 | 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] | 1690 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 1691 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1692 | /* 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] | 1693 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 1694 | * we forward the close to the request side so that it flows upstream to |
| 1695 | * the client. |
| 1696 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1697 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1698 | } |
| 1699 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1700 | 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] | 1701 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 1702 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 1703 | /* We have no more processing to do, and nothing more to send, and |
| 1704 | * the client side has closed. So we'll forward this state downstream |
| 1705 | * on the response buffer. |
| 1706 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1707 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1708 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1712 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1713 | |
| 1714 | /* we don't want to expire timeouts while we're processing requests */ |
| 1715 | si->ib->rex = TICK_ETERNITY; |
| 1716 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1717 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1718 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1719 | 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] | 1720 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1721 | 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] | 1722 | |
| 1723 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 1724 | /* check that we have released everything then unregister */ |
| 1725 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1726 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1727 | } |
| 1728 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1729 | /* This function dumps information onto the stream interface's read buffer. |
| 1730 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 1731 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1732 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1733 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1734 | { |
| 1735 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 1736 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1737 | chunk_printf(&trash, |
| 1738 | "Name: " PRODUCT_NAME "\n" |
| 1739 | "Version: " HAPROXY_VERSION "\n" |
| 1740 | "Release_date: " HAPROXY_DATE "\n" |
| 1741 | "Nbproc: %d\n" |
| 1742 | "Process_num: %d\n" |
| 1743 | "Pid: %d\n" |
| 1744 | "Uptime: %dd %dh%02dm%02ds\n" |
| 1745 | "Uptime_sec: %d\n" |
| 1746 | "Memmax_MB: %d\n" |
| 1747 | "Ulimit-n: %d\n" |
| 1748 | "Maxsock: %d\n" |
| 1749 | "Maxconn: %d\n" |
| 1750 | "Hard_maxconn: %d\n" |
| 1751 | "Maxpipes: %d\n" |
| 1752 | "CurrConns: %d\n" |
| 1753 | "PipesUsed: %d\n" |
| 1754 | "PipesFree: %d\n" |
| 1755 | "ConnRate: %d\n" |
| 1756 | "ConnRateLimit: %d\n" |
| 1757 | "MaxConnRate: %d\n" |
| 1758 | "CompressBpsIn: %u\n" |
| 1759 | "CompressBpsOut: %u\n" |
| 1760 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1761 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1762 | "ZlibMemUsage: %ld\n" |
| 1763 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1764 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1765 | "Tasks: %d\n" |
| 1766 | "Run_queue: %d\n" |
| 1767 | "Idle_pct: %d\n" |
| 1768 | "node: %s\n" |
| 1769 | "description: %s\n" |
| 1770 | "", |
| 1771 | global.nbproc, |
| 1772 | relative_pid, |
| 1773 | pid, |
| 1774 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 1775 | up, |
| 1776 | global.rlimit_memmax, |
| 1777 | global.rlimit_nofile, |
| 1778 | global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes, |
| 1779 | actconn, pipes_used, pipes_free, |
| 1780 | read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max, |
| 1781 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 1782 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1783 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1784 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1785 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1786 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 1787 | global.node, global.desc ? global.desc : "" |
| 1788 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1789 | |
| 1790 | if (bi_putchk(si->ib, &trash) == -1) |
| 1791 | return 0; |
| 1792 | |
| 1793 | return 1; |
| 1794 | } |
| 1795 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1796 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 1797 | * the state from stream interface <si>. The caller is responsible for clearing |
| 1798 | * 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] | 1799 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1800 | 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] | 1801 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1802 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1803 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1804 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1805 | if (!(px->cap & PR_CAP_FE)) |
| 1806 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1807 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1808 | 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] | 1809 | return 0; |
| 1810 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1811 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1812 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1813 | /* name, queue */ |
| 1814 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1815 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1816 | 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] | 1817 | /* Column sub-heading for Enable or Disable server */ |
| 1818 | chunk_appendf(&trash, "<td></td>"); |
| 1819 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1820 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1821 | chunk_appendf(&trash, |
| 1822 | "<td class=ac>" |
| 1823 | "<a name=\"%s/Frontend\"></a>" |
| 1824 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 1825 | "<td colspan=3></td>" |
| 1826 | "", |
| 1827 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1828 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1829 | chunk_appendf(&trash, |
| 1830 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1831 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1832 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 1833 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 1834 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1835 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 1836 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 1837 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1838 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1839 | if (px->mode == PR_MODE_HTTP) |
| 1840 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1841 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1842 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1843 | |
| 1844 | chunk_appendf(&trash, |
| 1845 | "</table></div></u></td>" |
| 1846 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1847 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1848 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 1849 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 1850 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1851 | U2H(px->fe_counters.sps_max), |
| 1852 | U2H(px->fe_counters.cps_max), |
| 1853 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1854 | |
| 1855 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1856 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1857 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1858 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1859 | |
| 1860 | chunk_appendf(&trash, |
| 1861 | "</table></div></u></td>" |
| 1862 | /* sessions rate : limit */ |
| 1863 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1864 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1865 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1866 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1867 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1868 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1869 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1870 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 1871 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1872 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1873 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 1874 | U2H(px->fe_counters.cum_sess), |
| 1875 | U2H(px->fe_counters.cum_conn), |
| 1876 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1877 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1878 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1879 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1880 | chunk_appendf(&trash, |
| 1881 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 1882 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 1883 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 1884 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1885 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 1886 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 1887 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 1888 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 1889 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 1890 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1891 | U2H(px->fe_counters.p.http.cum_req), |
| 1892 | U2H(px->fe_counters.p.http.rsp[1]), |
| 1893 | U2H(px->fe_counters.p.http.rsp[2]), |
| 1894 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1895 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1896 | (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] | 1897 | U2H(px->fe_counters.p.http.rsp[3]), |
| 1898 | U2H(px->fe_counters.p.http.rsp[4]), |
| 1899 | U2H(px->fe_counters.p.http.rsp[5]), |
| 1900 | U2H(px->fe_counters.p.http.rsp[0]), |
| 1901 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1902 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1903 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1904 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1905 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1906 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1907 | "<td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1908 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1909 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1910 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1911 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1912 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1913 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1914 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1915 | "<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] | 1916 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1917 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1918 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 1919 | px->fe_counters.comp_in ? |
| 1920 | (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] | 1921 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1922 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1923 | chunk_appendf(&trash, |
| 1924 | /* denied: req, resp */ |
| 1925 | "<td>%s</td><td>%s</td>" |
| 1926 | /* errors : request, connect, response */ |
| 1927 | "<td>%s</td><td></td><td></td>" |
| 1928 | /* warnings: retries, redispatches */ |
| 1929 | "<td></td><td></td>" |
| 1930 | /* server status : reflect frontend status */ |
| 1931 | "<td class=ac>%s</td>" |
| 1932 | /* rest of server: nothing */ |
| 1933 | "<td class=ac colspan=8></td></tr>" |
| 1934 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1935 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 1936 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1937 | px->state == PR_STREADY ? "OPEN" : |
| 1938 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1939 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1940 | else { /* CSV mode */ |
| 1941 | chunk_appendf(&trash, |
| 1942 | /* pxid, name, queue cur, queue max, */ |
| 1943 | "%s,FRONTEND,,," |
| 1944 | /* sessions : current, max, limit, total */ |
| 1945 | "%d,%d,%d,%lld," |
| 1946 | /* bytes : in, out */ |
| 1947 | "%lld,%lld," |
| 1948 | /* denied: req, resp */ |
| 1949 | "%lld,%lld," |
| 1950 | /* errors : request, connect, response */ |
| 1951 | "%lld,,," |
| 1952 | /* warnings: retries, redispatches */ |
| 1953 | ",," |
| 1954 | /* server status : reflect frontend status */ |
| 1955 | "%s," |
| 1956 | /* rest of server: nothing */ |
| 1957 | ",,,,,,,," |
| 1958 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 1959 | "%d,%d,0,,,,%d," |
| 1960 | /* rate, rate_lim, rate_max */ |
| 1961 | "%u,%u,%u," |
| 1962 | /* check_status, check_code, check_duration */ |
| 1963 | ",,,", |
| 1964 | px->id, |
| 1965 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 1966 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 1967 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 1968 | px->fe_counters.failed_req, |
| 1969 | px->state == PR_STREADY ? "OPEN" : |
| 1970 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 1971 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 1972 | read_freq_ctr(&px->fe_sess_per_sec), |
| 1973 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1974 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1975 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1976 | if (px->mode == PR_MODE_HTTP) { |
| 1977 | for (i=1; i<6; i++) |
| 1978 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 1979 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 1980 | } |
| 1981 | else |
| 1982 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1983 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1984 | /* failed health analyses */ |
| 1985 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1986 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1987 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 1988 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 1989 | read_freq_ctr(&px->fe_req_per_sec), |
| 1990 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 1991 | |
| 1992 | /* errors: cli_aborts, srv_aborts */ |
| 1993 | chunk_appendf(&trash, ",,"); |
| 1994 | |
| 1995 | /* compression: in, out, bypassed */ |
| 1996 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 1997 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 1998 | |
| 1999 | /* compression: comp_rsp */ |
| 2000 | chunk_appendf(&trash, "%lld,", |
| 2001 | px->fe_counters.p.http.comp_rsp); |
| 2002 | |
| 2003 | /* finish with EOL */ |
| 2004 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2005 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2006 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2007 | } |
| 2008 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2009 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2010 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2011 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2012 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2013 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2014 | 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] | 2015 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2016 | struct appctx *appctx = __objt_appctx(si->end); |
| 2017 | |
| 2018 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2019 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2020 | 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] | 2021 | /* Column sub-heading for Enable or Disable server */ |
| 2022 | chunk_appendf(&trash, "<td></td>"); |
| 2023 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2024 | chunk_appendf(&trash, |
| 2025 | /* frontend name, listener name */ |
| 2026 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2027 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2028 | "", |
| 2029 | px->id, l->name, |
| 2030 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2031 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2032 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2033 | if (flags & ST_SHLGNDS) { |
| 2034 | char str[INET6_ADDRSTRLEN]; |
| 2035 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2036 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2037 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2038 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2039 | port = get_host_port(&l->addr); |
| 2040 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2041 | case AF_INET: |
| 2042 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2043 | break; |
| 2044 | case AF_INET6: |
| 2045 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2046 | break; |
| 2047 | case AF_UNIX: |
| 2048 | chunk_appendf(&trash, "unix, "); |
| 2049 | break; |
| 2050 | case -1: |
| 2051 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2052 | break; |
| 2053 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2054 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2055 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2056 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2057 | } |
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 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2060 | /* queue */ |
| 2061 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2062 | /* sessions rate: current, max, limit */ |
| 2063 | "<td colspan=3> </td>" |
| 2064 | /* sessions: current, max, limit, total, lbtot */ |
| 2065 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2066 | "<td>%s</td><td> </td>" |
| 2067 | /* bytes: in, out */ |
| 2068 | "<td>%s</td><td>%s</td>" |
| 2069 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2070 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2071 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2072 | 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] | 2073 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2074 | chunk_appendf(&trash, |
| 2075 | /* denied: req, resp */ |
| 2076 | "<td>%s</td><td>%s</td>" |
| 2077 | /* errors: request, connect, response */ |
| 2078 | "<td>%s</td><td></td><td></td>" |
| 2079 | /* warnings: retries, redispatches */ |
| 2080 | "<td></td><td></td>" |
| 2081 | /* server status: reflect listener status */ |
| 2082 | "<td class=ac>%s</td>" |
| 2083 | /* rest of server: nothing */ |
| 2084 | "<td class=ac colspan=8></td></tr>" |
| 2085 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2086 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2087 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2088 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2089 | } |
| 2090 | else { /* CSV mode */ |
| 2091 | chunk_appendf(&trash, |
| 2092 | /* pxid, name, queue cur, queue max, */ |
| 2093 | "%s,%s,,," |
| 2094 | /* sessions: current, max, limit, total */ |
| 2095 | "%d,%d,%d,%lld," |
| 2096 | /* bytes: in, out */ |
| 2097 | "%lld,%lld," |
| 2098 | /* denied: req, resp */ |
| 2099 | "%lld,%lld," |
| 2100 | /* errors: request, connect, response */ |
| 2101 | "%lld,,," |
| 2102 | /* warnings: retries, redispatches */ |
| 2103 | ",," |
| 2104 | /* server status: reflect listener status */ |
| 2105 | "%s," |
| 2106 | /* rest of server: nothing */ |
| 2107 | ",,,,,,,," |
| 2108 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2109 | "%d,%d,%d,,,,%d," |
| 2110 | /* rate, rate_lim, rate_max */ |
| 2111 | ",,," |
| 2112 | /* check_status, check_code, check_duration */ |
| 2113 | ",,," |
| 2114 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2115 | ",,,,,," |
| 2116 | /* failed health analyses */ |
| 2117 | "," |
| 2118 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2119 | ",,," |
| 2120 | /* errors: cli_aborts, srv_aborts */ |
| 2121 | ",," |
| 2122 | /* compression: in, out, bypassed, comp_rsp */ |
| 2123 | ",,,," |
| 2124 | "\n", |
| 2125 | px->id, l->name, |
| 2126 | l->nbconn, l->counters->conn_max, |
| 2127 | l->maxconn, l->counters->cum_conn, |
| 2128 | l->counters->bytes_in, l->counters->bytes_out, |
| 2129 | l->counters->denied_req, l->counters->denied_resp, |
| 2130 | l->counters->failed_req, |
| 2131 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2132 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2133 | } |
| 2134 | return 1; |
| 2135 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2136 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2137 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2138 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2139 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2140 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2141 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2142 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2143 | */ |
| 2144 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2145 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2146 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2147 | struct server *ref = sv->track ? sv->track : sv; |
| 2148 | char str[INET6_ADDRSTRLEN]; |
| 2149 | struct chunk src; |
| 2150 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2151 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2152 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2153 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2154 | "DOWN", |
| 2155 | "DN %d/%d ↑", |
| 2156 | "UP %d/%d ↓", |
| 2157 | "UP", |
| 2158 | "NOLB %d/%d ↓", |
| 2159 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2160 | "DRAIN %d/%d ↓", |
| 2161 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2162 | "<i>no check</i>" |
| 2163 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2164 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2165 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2166 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2167 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2168 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2169 | "<tr class=\"%s%d\">", |
| 2170 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
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 ((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] | 2173 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2174 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2175 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2176 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2177 | chunk_appendf(&trash, |
| 2178 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2179 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2180 | "", |
| 2181 | px->id, sv->id, |
| 2182 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2183 | px->id, sv->id, sv->id); |
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 (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2186 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2187 | |
| 2188 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2189 | case AF_INET: |
| 2190 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2191 | break; |
| 2192 | case AF_INET6: |
| 2193 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2194 | break; |
| 2195 | case AF_UNIX: |
| 2196 | chunk_appendf(&trash, "unix, "); |
| 2197 | break; |
| 2198 | case -1: |
| 2199 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2200 | break; |
| 2201 | default: /* address family not supported */ |
| 2202 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2203 | } |
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 | /* id */ |
| 2206 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2207 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2208 | /* cookie */ |
| 2209 | if (sv->cookie) { |
| 2210 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2211 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2212 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2213 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2214 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2215 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2216 | } |
| 2217 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2218 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2219 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2220 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2221 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2222 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2223 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2224 | /* sessions rate : current, max, limit */ |
| 2225 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2226 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2227 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2228 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2229 | 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] | 2230 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2231 | |
| 2232 | chunk_appendf(&trash, |
| 2233 | /* sessions: current, max, limit, total */ |
| 2234 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2235 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2236 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2237 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2238 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2239 | U2H(sv->counters.cum_sess), |
| 2240 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2241 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2242 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2243 | if (px->mode == PR_MODE_HTTP) { |
| 2244 | unsigned long long tot; |
| 2245 | for (tot = i = 0; i < 6; i++) |
| 2246 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2247 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2248 | chunk_appendf(&trash, |
| 2249 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2250 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2251 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2252 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2253 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2254 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2255 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2256 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2257 | U2H(tot), |
| 2258 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2259 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2260 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2261 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2262 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2263 | 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] | 2264 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2265 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2266 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2267 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2268 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2269 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2270 | U2H(sv->counters.cum_lbconn)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2271 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2272 | chunk_appendf(&trash, |
| 2273 | /* bytes : in, out */ |
| 2274 | "<td>%s</td><td>%s</td>" |
| 2275 | /* denied: req, resp */ |
| 2276 | "<td></td><td>%s</td>" |
| 2277 | /* errors : request, connect */ |
| 2278 | "<td></td><td>%s</td>" |
| 2279 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2280 | "<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] | 2281 | /* warnings: retries, redispatches */ |
| 2282 | "<td>%lld</td><td>%lld</td>" |
| 2283 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2284 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2285 | U2H(sv->counters.failed_secu), |
| 2286 | U2H(sv->counters.failed_conns), |
| 2287 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2288 | sv->counters.cli_aborts, |
| 2289 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2290 | sv->counters.retries, sv->counters.redispatches); |
| 2291 | |
| 2292 | /* status, lest check */ |
| 2293 | chunk_appendf(&trash, "<td class=ac>"); |
| 2294 | |
| 2295 | if (sv->state & SRV_MAINTAIN) { |
| 2296 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2297 | chunk_appendf(&trash, "MAINT"); |
| 2298 | } |
| 2299 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2300 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2301 | chunk_appendf(&trash, "MAINT(via)"); |
| 2302 | } |
| 2303 | else if (ref->state & SRV_CHECKED) { |
| 2304 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2305 | chunk_appendf(&trash, |
| 2306 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2307 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2308 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2309 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2310 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2311 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2312 | chunk_appendf(&trash, |
| 2313 | "</td><td class=ac><u> %s%s", |
Simon Horman | cd5d7b6 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 2314 | (sv->check.state & CHK_STATE_RUNNING) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2315 | get_check_status_info(sv->check.status)); |
| 2316 | |
| 2317 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2318 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2319 | |
| 2320 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2321 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2322 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2323 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2324 | get_check_status_description(sv->check.status)); |
| 2325 | if (*sv->check.desc) { |
| 2326 | chunk_appendf(&trash, ": "); |
| 2327 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2328 | chunk_htmlencode(&trash, &src); |
| 2329 | } |
| 2330 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2331 | } |
| 2332 | else |
| 2333 | chunk_appendf(&trash, "</td><td>"); |
| 2334 | |
| 2335 | chunk_appendf(&trash, |
| 2336 | /* weight */ |
| 2337 | "</td><td class=ac>%d</td>" |
| 2338 | /* act, bck */ |
| 2339 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2340 | "", |
| 2341 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2342 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2343 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2344 | |
| 2345 | /* check failures: unique, fatal, down time */ |
| 2346 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2347 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2348 | |
| 2349 | if (ref->observe) |
| 2350 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2351 | |
| 2352 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2353 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2354 | "<td>%lld</td><td>%s</td>" |
| 2355 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2356 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2357 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2358 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2359 | else if (sv != ref) { |
| 2360 | if (sv->state & SRV_MAINTAIN) |
| 2361 | chunk_appendf(&trash, |
| 2362 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2363 | ref->proxy->id, ref->id); |
| 2364 | else |
| 2365 | chunk_appendf(&trash, |
| 2366 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2367 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2368 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2369 | else |
| 2370 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2371 | |
| 2372 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2373 | if (sv->state & SRV_WARMINGUP) |
| 2374 | 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] | 2375 | else |
| 2376 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2377 | } |
| 2378 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2379 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2380 | "DOWN,", |
| 2381 | "DOWN %d/%d,", |
| 2382 | "UP %d/%d,", |
| 2383 | "UP,", |
| 2384 | "NOLB %d/%d,", |
| 2385 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2386 | "DRAIN %d/%d,", |
| 2387 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2388 | "no check," |
| 2389 | }; |
| 2390 | |
| 2391 | chunk_appendf(&trash, |
| 2392 | /* pxid, name */ |
| 2393 | "%s,%s," |
| 2394 | /* queue : current, max */ |
| 2395 | "%d,%d," |
| 2396 | /* sessions : current, max, limit, total */ |
| 2397 | "%d,%d,%s,%lld," |
| 2398 | /* bytes : in, out */ |
| 2399 | "%lld,%lld," |
| 2400 | /* denied: req, resp */ |
| 2401 | ",%lld," |
| 2402 | /* errors : request, connect, response */ |
| 2403 | ",%lld,%lld," |
| 2404 | /* warnings: retries, redispatches */ |
| 2405 | "%lld,%lld," |
| 2406 | "", |
| 2407 | px->id, sv->id, |
| 2408 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2409 | 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] | 2410 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2411 | sv->counters.failed_secu, |
| 2412 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2413 | sv->counters.retries, sv->counters.redispatches); |
| 2414 | |
| 2415 | /* status */ |
| 2416 | if (sv->state & SRV_MAINTAIN) |
| 2417 | chunk_appendf(&trash, "MAINT,"); |
| 2418 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2419 | chunk_appendf(&trash, "MAINT(via),"); |
| 2420 | else |
| 2421 | chunk_appendf(&trash, |
| 2422 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2423 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2424 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2425 | |
| 2426 | chunk_appendf(&trash, |
| 2427 | /* weight, active, backup */ |
| 2428 | "%d,%d,%d," |
| 2429 | "", |
| 2430 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2431 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2432 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2433 | |
| 2434 | /* check failures: unique, fatal; last change, total downtime */ |
| 2435 | if (sv->state & SRV_CHECKED) |
| 2436 | chunk_appendf(&trash, |
| 2437 | "%lld,%lld,%d,%d,", |
| 2438 | sv->counters.failed_checks, sv->counters.down_trans, |
| 2439 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 2440 | else |
| 2441 | chunk_appendf(&trash, ",,,,"); |
| 2442 | |
| 2443 | /* queue limit, pid, iid, sid, */ |
| 2444 | chunk_appendf(&trash, |
| 2445 | "%s," |
| 2446 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2447 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2448 | relative_pid, px->uuid, sv->puid); |
| 2449 | |
| 2450 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2451 | if (sv->state & SRV_WARMINGUP) |
| 2452 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2453 | |
| 2454 | /* sessions: lbtot */ |
| 2455 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 2456 | |
| 2457 | /* tracked */ |
| 2458 | if (sv->track) |
| 2459 | chunk_appendf(&trash, "%s/%s,", |
| 2460 | sv->track->proxy->id, sv->track->id); |
| 2461 | else |
| 2462 | chunk_appendf(&trash, ","); |
| 2463 | |
| 2464 | /* type */ |
| 2465 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 2466 | |
| 2467 | /* rate */ |
| 2468 | chunk_appendf(&trash, "%u,,%u,", |
| 2469 | read_freq_ctr(&sv->sess_per_sec), |
| 2470 | sv->counters.sps_max); |
| 2471 | |
| 2472 | if (sv->state & SRV_CHECKED) { |
| 2473 | /* check_status */ |
| 2474 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 2475 | |
| 2476 | /* check_code */ |
| 2477 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2478 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 2479 | else |
| 2480 | chunk_appendf(&trash, ","); |
| 2481 | |
| 2482 | /* check_duration */ |
| 2483 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 2484 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 2485 | else |
| 2486 | chunk_appendf(&trash, ","); |
| 2487 | |
| 2488 | } |
| 2489 | else |
| 2490 | chunk_appendf(&trash, ",,,"); |
| 2491 | |
| 2492 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2493 | if (px->mode == PR_MODE_HTTP) { |
| 2494 | for (i=1; i<6; i++) |
| 2495 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 2496 | |
| 2497 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 2498 | } |
| 2499 | else |
| 2500 | chunk_appendf(&trash, ",,,,,,"); |
| 2501 | |
| 2502 | /* failed health analyses */ |
| 2503 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 2504 | |
| 2505 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2506 | chunk_appendf(&trash, ",,,"); |
| 2507 | |
| 2508 | /* errors: cli_aborts, srv_aborts */ |
| 2509 | chunk_appendf(&trash, "%lld,%lld,", |
| 2510 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 2511 | |
| 2512 | /* compression: in, out, bypassed, comp_rsp */ |
| 2513 | chunk_appendf(&trash, ",,,,"); |
| 2514 | |
| 2515 | /* finish with EOL */ |
| 2516 | chunk_appendf(&trash, "\n"); |
| 2517 | } |
| 2518 | return 1; |
| 2519 | } |
| 2520 | |
| 2521 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 2522 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 2523 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 2524 | */ |
| 2525 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 2526 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2527 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2528 | struct chunk src; |
| 2529 | int i; |
| 2530 | |
| 2531 | if (!(px->cap & PR_CAP_BE)) |
| 2532 | return 0; |
| 2533 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2534 | 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] | 2535 | return 0; |
| 2536 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2537 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2538 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2539 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2540 | /* Column sub-heading for Enable or Disable server */ |
| 2541 | chunk_appendf(&trash, "<td></td>"); |
| 2542 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2543 | chunk_appendf(&trash, |
| 2544 | "<td class=ac>" |
| 2545 | /* name */ |
| 2546 | "%s<a name=\"%s/Backend\"></a>" |
| 2547 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 2548 | "", |
| 2549 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2550 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2551 | |
| 2552 | if (flags & ST_SHLGNDS) { |
| 2553 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2554 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2555 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 2556 | |
| 2557 | /* cookie */ |
| 2558 | if (px->cookie_name) { |
| 2559 | chunk_appendf(&trash, ", cookie: '"); |
| 2560 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 2561 | chunk_htmlencode(&trash, &src); |
| 2562 | chunk_appendf(&trash, "'"); |
| 2563 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2564 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2568 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2569 | /* queue : current, max */ |
| 2570 | "<td>%s</td><td>%s</td><td></td>" |
| 2571 | /* sessions rate : current, max, limit */ |
| 2572 | "<td>%s</td><td>%s</td><td></td>" |
| 2573 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2574 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2575 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 2576 | 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] | 2577 | |
| 2578 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2579 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2580 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2581 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2582 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2583 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2584 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 2585 | U2H(px->be_counters.cum_conn), |
| 2586 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2587 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2588 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2589 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2590 | chunk_appendf(&trash, |
| 2591 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2592 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2593 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2594 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2595 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2596 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2597 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2598 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2599 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2600 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2601 | U2H(px->be_counters.p.http.cum_req), |
| 2602 | U2H(px->be_counters.p.http.rsp[1]), |
| 2603 | U2H(px->be_counters.p.http.rsp[2]), |
| 2604 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2605 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2606 | (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] | 2607 | U2H(px->be_counters.p.http.rsp[3]), |
| 2608 | U2H(px->be_counters.p.http.rsp[4]), |
| 2609 | U2H(px->be_counters.p.http.rsp[5]), |
| 2610 | U2H(px->be_counters.p.http.rsp[0]), |
| 2611 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2615 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2616 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2617 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2618 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2619 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2620 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2621 | U2H(px->be_counters.cum_lbconn), |
| 2622 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2623 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2624 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2625 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2626 | "<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] | 2627 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2628 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2629 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 2630 | px->be_counters.comp_in ? |
| 2631 | (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] | 2632 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 2633 | |
| 2634 | chunk_appendf(&trash, |
| 2635 | /* denied: req, resp */ |
| 2636 | "<td>%s</td><td>%s</td>" |
| 2637 | /* errors : request, connect */ |
| 2638 | "<td></td><td>%s</td>" |
| 2639 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2640 | "<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] | 2641 | /* warnings: retries, redispatches */ |
| 2642 | "<td>%lld</td><td>%lld</td>" |
| 2643 | /* backend status: reflect backend status (up/down): we display UP |
| 2644 | * if the backend has known working servers or if it has no server at |
| 2645 | * all (eg: for stats). Then we display the total weight, number of |
| 2646 | * active and backups. */ |
| 2647 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 2648 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 2649 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2650 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 2651 | U2H(px->be_counters.failed_conns), |
| 2652 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2653 | px->be_counters.cli_aborts, |
| 2654 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2655 | px->be_counters.retries, px->be_counters.redispatches, |
| 2656 | human_time(now.tv_sec - px->last_change, 1), |
| 2657 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 2658 | "<font color=\"red\"><b>DOWN</b></font>", |
| 2659 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2660 | px->srv_act, px->srv_bck); |
| 2661 | |
| 2662 | chunk_appendf(&trash, |
| 2663 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 2664 | "<td class=ac> </td><td>%d</td>" |
| 2665 | "<td>%s</td>" |
| 2666 | "<td></td>" |
| 2667 | "</tr>", |
| 2668 | px->down_trans, |
| 2669 | px->srv?human_time(be_downtime(px), 1):" "); |
| 2670 | } |
| 2671 | else { /* CSV mode */ |
| 2672 | chunk_appendf(&trash, |
| 2673 | /* pxid, name */ |
| 2674 | "%s,BACKEND," |
| 2675 | /* queue : current, max */ |
| 2676 | "%d,%d," |
| 2677 | /* sessions : current, max, limit, total */ |
| 2678 | "%d,%d,%d,%lld," |
| 2679 | /* bytes : in, out */ |
| 2680 | "%lld,%lld," |
| 2681 | /* denied: req, resp */ |
| 2682 | "%lld,%lld," |
| 2683 | /* errors : request, connect, response */ |
| 2684 | ",%lld,%lld," |
| 2685 | /* warnings: retries, redispatches */ |
| 2686 | "%lld,%lld," |
| 2687 | /* backend status: reflect backend status (up/down): we display UP |
| 2688 | * if the backend has known working servers or if it has no server at |
| 2689 | * all (eg: for stats). Then we display the total weight, number of |
| 2690 | * active and backups. */ |
| 2691 | "%s," |
| 2692 | "%d,%d,%d," |
| 2693 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 2694 | ",%d,%d,%d,," |
| 2695 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2696 | "%d,%d,0,,%lld,,%d," |
| 2697 | /* rate, rate_lim, rate_max, */ |
| 2698 | "%u,,%u," |
| 2699 | /* check_status, check_code, check_duration */ |
| 2700 | ",,,", |
| 2701 | px->id, |
| 2702 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 2703 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 2704 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 2705 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 2706 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 2707 | px->be_counters.retries, px->be_counters.redispatches, |
| 2708 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 2709 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2710 | px->srv_act, px->srv_bck, |
| 2711 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 2712 | px->srv?be_downtime(px):0, |
| 2713 | relative_pid, px->uuid, |
| 2714 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 2715 | read_freq_ctr(&px->be_sess_per_sec), |
| 2716 | px->be_counters.sps_max); |
| 2717 | |
| 2718 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2719 | if (px->mode == PR_MODE_HTTP) { |
| 2720 | for (i=1; i<6; i++) |
| 2721 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 2722 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 2723 | } |
| 2724 | else |
| 2725 | chunk_appendf(&trash, ",,,,,,"); |
| 2726 | |
| 2727 | /* failed health analyses */ |
| 2728 | chunk_appendf(&trash, ","); |
| 2729 | |
| 2730 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2731 | chunk_appendf(&trash, ",,,"); |
| 2732 | |
| 2733 | /* errors: cli_aborts, srv_aborts */ |
| 2734 | chunk_appendf(&trash, "%lld,%lld,", |
| 2735 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 2736 | |
| 2737 | /* compression: in, out, bypassed */ |
| 2738 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2739 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 2740 | |
| 2741 | /* compression: comp_rsp */ |
| 2742 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 2743 | |
| 2744 | /* finish with EOL */ |
| 2745 | chunk_appendf(&trash, "\n"); |
| 2746 | } |
| 2747 | return 1; |
| 2748 | } |
| 2749 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2750 | /* 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] | 2751 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2752 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2753 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2754 | 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] | 2755 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2756 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2757 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 2758 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2759 | 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] | 2760 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2761 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2762 | /* 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] | 2763 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2764 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2765 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2766 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 2767 | 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] | 2768 | } |
| 2769 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2770 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2771 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 2772 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2773 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2774 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2775 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | /* print a new table */ |
| 2779 | chunk_appendf(&trash, |
| 2780 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2781 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2782 | "<th class=\"pxname\" width=\"10%%\">"); |
| 2783 | |
| 2784 | chunk_appendf(&trash, |
| 2785 | "<a name=\"%s\"></a>%s" |
| 2786 | "<a class=px href=\"#%s\">%s</a>", |
| 2787 | px->id, |
| 2788 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 2789 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2790 | |
| 2791 | if (uri->flags & ST_SHLGNDS) { |
| 2792 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2793 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2794 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 2795 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2796 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2800 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2801 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 2802 | "</tr>\n" |
| 2803 | "</table>\n" |
| 2804 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2805 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2806 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 2807 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 2808 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2809 | 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] | 2810 | /* Column heading for Enable or Disable server */ |
| 2811 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2812 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2813 | |
| 2814 | chunk_appendf(&trash, |
| 2815 | "<th rowspan=2></th>" |
| 2816 | "<th colspan=3>Queue</th>" |
| 2817 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
| 2818 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 2819 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 2820 | "<th colspan=9>Server</th>" |
| 2821 | "</tr>\n" |
| 2822 | "<tr class=\"titre\">" |
| 2823 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 2824 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 2825 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>" |
| 2826 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 2827 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 2828 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 2829 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 2830 | "<th>Thrtle</th>\n" |
| 2831 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2832 | } |
| 2833 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2834 | /* 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] | 2835 | * 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] | 2836 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2837 | 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] | 2838 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2839 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2840 | chunk_appendf(&trash, "</table>"); |
| 2841 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2842 | 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] | 2843 | /* close the form used to enable/disable this proxy servers */ |
| 2844 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2845 | "Choose the action to perform on the checked servers : " |
| 2846 | "<select name=action>" |
| 2847 | "<option value=\"\"></option>" |
| 2848 | "<option value=\"disable\">Disable</option>" |
| 2849 | "<option value=\"enable\">Enable</option>" |
| 2850 | "<option value=\"stop\">Soft Stop</option>" |
| 2851 | "<option value=\"start\">Soft Start</option>" |
| 2852 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 2853 | "</select>" |
| 2854 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 2855 | " <input type=\"submit\" value=\"Apply\">" |
| 2856 | "</form>", |
| 2857 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2861 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2862 | |
| 2863 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2864 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 2865 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 2866 | * buffer space, or non-zero if everything completed. This function is used |
| 2867 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 2868 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2869 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2870 | 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] | 2871 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2872 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 2873 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2874 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2875 | 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] | 2876 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2877 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2878 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2879 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2880 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2881 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2882 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2883 | if (uri && uri->scope) { |
| 2884 | /* we have a limited scope, we have to check the proxy name */ |
| 2885 | struct stat_scope *scope; |
| 2886 | int len; |
| 2887 | |
| 2888 | len = strlen(px->id); |
| 2889 | scope = uri->scope; |
| 2890 | |
| 2891 | while (scope) { |
| 2892 | /* match exact proxy name */ |
| 2893 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 2894 | break; |
| 2895 | |
| 2896 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 2897 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2898 | break; |
| 2899 | scope = scope->next; |
| 2900 | } |
| 2901 | |
| 2902 | /* proxy name not found : don't dump anything */ |
| 2903 | if (scope == NULL) |
| 2904 | return 1; |
| 2905 | } |
| 2906 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2907 | /* if the user has requested a limited output and the proxy |
| 2908 | * name does not match, skip it. |
| 2909 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2910 | if (appctx->ctx.stats.scope_len && |
| 2911 | 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] | 2912 | return 1; |
| 2913 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2914 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 2915 | (appctx->ctx.stats.iid != -1) && |
| 2916 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2917 | return 1; |
| 2918 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2919 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2920 | /* fall through */ |
| 2921 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2922 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2923 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2924 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2925 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2926 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2927 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2928 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2929 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2930 | /* fall through */ |
| 2931 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2932 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2933 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2934 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2935 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2936 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2937 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2938 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 2939 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2940 | /* fall through */ |
| 2941 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2942 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2943 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2944 | 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] | 2945 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2946 | return 0; |
| 2947 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2948 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2949 | if (!l->counters) |
| 2950 | continue; |
| 2951 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2952 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 2953 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2954 | break; |
| 2955 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2956 | 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] | 2957 | continue; |
| 2958 | } |
| 2959 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2960 | /* print the frontend */ |
| 2961 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 2962 | if (bi_putchk(rep, &trash) == -1) |
| 2963 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2964 | } |
| 2965 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2966 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 2967 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2968 | /* fall through */ |
| 2969 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2970 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2971 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2972 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2973 | 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] | 2974 | |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2975 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2976 | return 0; |
| 2977 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2978 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2979 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2980 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 2981 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2982 | break; |
| 2983 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2984 | 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] | 2985 | continue; |
| 2986 | } |
| 2987 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2988 | if (sv->track) |
| 2989 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2990 | else |
| 2991 | svs = sv; |
| 2992 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2993 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2994 | if (!(svs->state & SRV_CHECKED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2995 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2996 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2997 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2998 | sv_state = 3; /* UP */ |
| 2999 | else |
| 3000 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3001 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3002 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3003 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3004 | else if (svs->state & SRV_GOINGDOWN) |
| 3005 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3006 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3007 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 3008 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3009 | sv_state = 1; /* going up */ |
| 3010 | else |
| 3011 | sv_state = 0; /* DOWN */ |
| 3012 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3013 | 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] | 3014 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3015 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3016 | continue; |
| 3017 | } |
| 3018 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3019 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3020 | if (bi_putchk(rep, &trash) == -1) |
| 3021 | return 0; |
| 3022 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3023 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3024 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3025 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3026 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3027 | case STAT_PX_ST_BE: |
| 3028 | /* print the backend */ |
| 3029 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3030 | if (bi_putchk(rep, &trash) == -1) |
| 3031 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3032 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3033 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3034 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3035 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3036 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3037 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3038 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3039 | if (bi_putchk(rep, &trash) == -1) |
| 3040 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3041 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3042 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3043 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3044 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3045 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3046 | case STAT_PX_ST_FIN: |
| 3047 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3048 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3049 | default: |
| 3050 | /* unknown state, we should put an abort() here ! */ |
| 3051 | return 1; |
| 3052 | } |
| 3053 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3054 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3055 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3056 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3057 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3058 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3059 | { |
| 3060 | /* WARNING! This must fit in the first buffer !!! */ |
| 3061 | chunk_appendf(&trash, |
| 3062 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3063 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3064 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3065 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3066 | "<style type=\"text/css\"><!--\n" |
| 3067 | "body {" |
| 3068 | " font-family: arial, helvetica, sans-serif;" |
| 3069 | " font-size: 12px;" |
| 3070 | " font-weight: normal;" |
| 3071 | " color: black;" |
| 3072 | " background: white;" |
| 3073 | "}\n" |
| 3074 | "th,td {" |
| 3075 | " font-size: 10px;" |
| 3076 | "}\n" |
| 3077 | "h1 {" |
| 3078 | " font-size: x-large;" |
| 3079 | " margin-bottom: 0.5em;" |
| 3080 | "}\n" |
| 3081 | "h2 {" |
| 3082 | " font-family: helvetica, arial;" |
| 3083 | " font-size: x-large;" |
| 3084 | " font-weight: bold;" |
| 3085 | " font-style: italic;" |
| 3086 | " color: #6020a0;" |
| 3087 | " margin-top: 0em;" |
| 3088 | " margin-bottom: 0em;" |
| 3089 | "}\n" |
| 3090 | "h3 {" |
| 3091 | " font-family: helvetica, arial;" |
| 3092 | " font-size: 16px;" |
| 3093 | " font-weight: bold;" |
| 3094 | " color: #b00040;" |
| 3095 | " background: #e8e8d0;" |
| 3096 | " margin-top: 0em;" |
| 3097 | " margin-bottom: 0em;" |
| 3098 | "}\n" |
| 3099 | "li {" |
| 3100 | " margin-top: 0.25em;" |
| 3101 | " margin-right: 2em;" |
| 3102 | "}\n" |
| 3103 | ".hr {margin-top: 0.25em;" |
| 3104 | " border-color: black;" |
| 3105 | " border-bottom-style: solid;" |
| 3106 | "}\n" |
| 3107 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3108 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3109 | ".frontend {background: #e8e8d0;}\n" |
| 3110 | ".socket {background: #d0d0d0;}\n" |
| 3111 | ".backend {background: #e8e8d0;}\n" |
| 3112 | ".active0 {background: #ff9090;}\n" |
| 3113 | ".active1 {background: #ffd020;}\n" |
| 3114 | ".active2 {background: #ffffa0;}\n" |
| 3115 | ".active3 {background: #c0ffc0;}\n" |
| 3116 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3117 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3118 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3119 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3120 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3121 | ".backup0 {background: #ff9090;}\n" |
| 3122 | ".backup1 {background: #ff80ff;}\n" |
| 3123 | ".backup2 {background: #c060ff;}\n" |
| 3124 | ".backup3 {background: #b0d0ff;}\n" |
| 3125 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3126 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3127 | ".backup6 {background: #c060ff;}\n" |
| 3128 | ".backup7 {background: #cc9900;}\n" |
| 3129 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3130 | ".maintain {background: #c07820;}\n" |
| 3131 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3132 | "\n" |
| 3133 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3134 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3135 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3136 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3137 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3138 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3139 | "\n" |
| 3140 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3141 | "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" |
| 3142 | "table.tbl td.ac { text-align: center;}\n" |
| 3143 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3144 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3145 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3146 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3147 | "\n" |
| 3148 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3149 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3150 | "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] | 3151 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3152 | "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" |
| 3153 | "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] | 3154 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3155 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3156 | " display:block;\n" |
| 3157 | " visibility:hidden;\n" |
| 3158 | " z-index:2147483647;\n" |
| 3159 | " position:absolute;\n" |
| 3160 | " padding:2px 4px 3px;\n" |
| 3161 | " background:#f0f060; color:#000000;\n" |
| 3162 | " border:1px solid #7040c0;\n" |
| 3163 | " white-space:nowrap;\n" |
| 3164 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3165 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3166 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3167 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3168 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3169 | "-->\n" |
| 3170 | "</style></head>\n", |
| 3171 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3172 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3173 | ); |
| 3174 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3175 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3176 | /* 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] | 3177 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3178 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3179 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3180 | 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] | 3181 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3182 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3183 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3184 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3185 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3186 | /* WARNING! this has to fit the first packet too. |
| 3187 | * We are around 3.5 kB, add adding entries will |
| 3188 | * become tricky if we want to support 4kB buffers ! |
| 3189 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3190 | chunk_appendf(&trash, |
| 3191 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3192 | PRODUCT_NAME "%s</a></h1>\n" |
| 3193 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3194 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3195 | "<h3>> General process information</h3>\n" |
| 3196 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3197 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3198 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3199 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3200 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3201 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3202 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3203 | "</td><td align=\"center\" nowrap>\n" |
| 3204 | "<table class=\"lgd\"><tr>\n" |
| 3205 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3206 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3207 | "</tr><tr>\n" |
| 3208 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3209 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3210 | "</tr><tr>\n" |
| 3211 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3212 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3213 | "</tr><tr>\n" |
| 3214 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3215 | "</tr><tr>\n" |
| 3216 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3217 | "</tr><tr>\n" |
| 3218 | "<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] | 3219 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3220 | "<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] | 3221 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3222 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3223 | "</td>" |
| 3224 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3225 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3226 | "", |
| 3227 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3228 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3229 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3230 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3231 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3232 | pid, relative_pid, global.nbproc, |
| 3233 | up / 86400, (up % 86400) / 3600, |
| 3234 | (up % 3600) / 60, (up % 60), |
| 3235 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3236 | global.rlimit_memmax ? " MB" : "", |
| 3237 | global.rlimit_nofile, |
| 3238 | global.maxsock, global.maxconn, global.maxpipes, |
| 3239 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3240 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3241 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3242 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3243 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3244 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3245 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3246 | |
| 3247 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3248 | "<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] | 3249 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3250 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3251 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3252 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3253 | STAT_SCOPE_TXT_MAXLEN); |
| 3254 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3255 | /* 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] | 3256 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3257 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3258 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3259 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3260 | 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] | 3261 | } |
| 3262 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3263 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3264 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3265 | "<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] | 3266 | uri->uri_prefix, |
| 3267 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3268 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3269 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3270 | else |
| 3271 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3272 | "<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] | 3273 | uri->uri_prefix, |
| 3274 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3275 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3276 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3277 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3278 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3279 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3280 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3281 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3282 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3283 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3284 | "", |
| 3285 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3286 | else |
| 3287 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3288 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3289 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3290 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3291 | ";norefresh", |
| 3292 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3293 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3294 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3295 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3296 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3297 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3298 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3299 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3300 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3301 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3302 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3303 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3304 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3305 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3306 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3307 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3308 | chunk_appendf(&trash, |
| 3309 | "</ul></td>" |
| 3310 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3311 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3312 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3313 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3314 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3315 | "</ul>" |
| 3316 | "</td>" |
| 3317 | "</tr></table>\n" |
| 3318 | "" |
| 3319 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3320 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3321 | if (appctx->ctx.stats.st_code) { |
| 3322 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3323 | case STAT_STATUS_DONE: |
| 3324 | chunk_appendf(&trash, |
| 3325 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3326 | "<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] | 3327 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3328 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3329 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3330 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3331 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3332 | break; |
| 3333 | case STAT_STATUS_NONE: |
| 3334 | chunk_appendf(&trash, |
| 3335 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3336 | "<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] | 3337 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3338 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3339 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3340 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3341 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3342 | break; |
| 3343 | case STAT_STATUS_PART: |
| 3344 | chunk_appendf(&trash, |
| 3345 | "<p><div class=active2>" |
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 partially processed.<br>" |
| 3348 | "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] | 3349 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3350 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3351 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3352 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3353 | break; |
| 3354 | case STAT_STATUS_ERRP: |
| 3355 | chunk_appendf(&trash, |
| 3356 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3357 | "<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] | 3358 | "Action not processed because of invalid parameters." |
| 3359 | "<ul>" |
| 3360 | "<li>The action is maybe unknown.</li>" |
| 3361 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3362 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3363 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3364 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3365 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3366 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3367 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3368 | break; |
| 3369 | case STAT_STATUS_EXCD: |
| 3370 | chunk_appendf(&trash, |
| 3371 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3372 | "<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] | 3373 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3374 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3375 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3376 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3377 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3378 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3379 | break; |
| 3380 | case STAT_STATUS_DENY: |
| 3381 | chunk_appendf(&trash, |
| 3382 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3383 | "<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] | 3384 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3385 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3386 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3387 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3388 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3389 | break; |
| 3390 | default: |
| 3391 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3392 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3393 | "<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] | 3394 | "Unexpected result." |
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 | } |
| 3400 | chunk_appendf(&trash, "<p>\n"); |
| 3401 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3402 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3403 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3404 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3405 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3406 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3407 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3408 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3409 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3410 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3411 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3412 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3413 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3414 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3415 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3416 | * and the session must be closed, or -1 in case of any error. This function is |
| 3417 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3418 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3419 | 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] | 3420 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3421 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3422 | struct channel *rep = si->ib; |
| 3423 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3424 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3425 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3426 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3427 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3428 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3429 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3430 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3431 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3432 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3433 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3434 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3435 | else |
| 3436 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3437 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3438 | if (bi_putchk(rep, &trash) == -1) |
| 3439 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3440 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3441 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3442 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3443 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3444 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3445 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3446 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3447 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3448 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3449 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3450 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3451 | appctx->ctx.stats.px = proxy; |
| 3452 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3453 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3454 | /* fall through */ |
| 3455 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3456 | case STAT_ST_LIST: |
| 3457 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3458 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3459 | if (buffer_almost_full(rep->buf)) |
| 3460 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3461 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3462 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3463 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 3464 | 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] | 3465 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3466 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3467 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3468 | appctx->ctx.stats.px = px->next; |
| 3469 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3470 | } |
| 3471 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3472 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3473 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3474 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3475 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3476 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3477 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3478 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3479 | if (bi_putchk(rep, &trash) == -1) |
| 3480 | return 0; |
| 3481 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3482 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3483 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3484 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 3485 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3486 | case STAT_ST_FIN: |
| 3487 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3488 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3489 | default: |
| 3490 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3491 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3492 | return -1; |
| 3493 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3494 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3495 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3496 | /* We reached the stats page through a POST request. The appctx is |
| 3497 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3498 | * Parse the posted data and enable/disable servers if necessary. |
| 3499 | * Returns 1 if request was parsed or zero if it needs more data. |
| 3500 | */ |
| 3501 | static int stats_process_http_post(struct stream_interface *si) |
| 3502 | { |
| 3503 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3504 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3505 | |
| 3506 | struct proxy *px = NULL; |
| 3507 | struct server *sv = NULL; |
| 3508 | |
| 3509 | char key[LINESIZE]; |
| 3510 | int action = ST_ADM_ACTION_NONE; |
| 3511 | int reprocess = 0; |
| 3512 | |
| 3513 | int total_servers = 0; |
| 3514 | int altered_servers = 0; |
| 3515 | |
| 3516 | char *first_param, *cur_param, *next_param, *end_params; |
| 3517 | char *st_cur_param = NULL; |
| 3518 | char *st_next_param = NULL; |
| 3519 | |
| 3520 | struct chunk *temp; |
| 3521 | int reql; |
| 3522 | |
| 3523 | temp = get_trash_chunk(); |
| 3524 | if (temp->size < s->txn.req.body_len) { |
| 3525 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3526 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3527 | goto out; |
| 3528 | } |
| 3529 | |
| 3530 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 3531 | if (reql <= 0) { |
| 3532 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3533 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3534 | return 0; |
| 3535 | } |
| 3536 | |
| 3537 | first_param = temp->str; |
| 3538 | end_params = temp->str + reql; |
| 3539 | cur_param = next_param = end_params; |
| 3540 | *end_params = '\0'; |
| 3541 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3542 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3543 | |
| 3544 | /* |
| 3545 | * Parse the parameters in reverse order to only store the last value. |
| 3546 | * From the html form, the backend and the action are at the end. |
| 3547 | */ |
| 3548 | while (cur_param > first_param) { |
| 3549 | char *value; |
| 3550 | int poffset, plen; |
| 3551 | |
| 3552 | cur_param--; |
| 3553 | |
| 3554 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 3555 | reprocess_servers: |
| 3556 | /* Parse the key */ |
| 3557 | poffset = (cur_param != first_param ? 1 : 0); |
| 3558 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 3559 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 3560 | strncpy(key, cur_param + poffset, plen); |
| 3561 | key[plen - 1] = '\0'; |
| 3562 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3563 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3564 | goto out; |
| 3565 | } |
| 3566 | |
| 3567 | /* Parse the value */ |
| 3568 | value = key; |
| 3569 | while (*value != '\0' && *value != '=') { |
| 3570 | value++; |
| 3571 | } |
| 3572 | if (*value == '=') { |
| 3573 | /* Ok, a value is found, we can mark the end of the key */ |
| 3574 | *value++ = '\0'; |
| 3575 | } |
| 3576 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 3577 | break; |
| 3578 | |
| 3579 | /* Now we can check the key to see what to do */ |
| 3580 | if (!px && (strcmp(key, "b") == 0)) { |
| 3581 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 3582 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3583 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3584 | goto out; |
| 3585 | } |
| 3586 | } |
| 3587 | else if (!action && (strcmp(key, "action") == 0)) { |
| 3588 | if (strcmp(value, "disable") == 0) { |
| 3589 | action = ST_ADM_ACTION_DISABLE; |
| 3590 | } |
| 3591 | else if (strcmp(value, "enable") == 0) { |
| 3592 | action = ST_ADM_ACTION_ENABLE; |
| 3593 | } |
| 3594 | else if (strcmp(value, "stop") == 0) { |
| 3595 | action = ST_ADM_ACTION_STOP; |
| 3596 | } |
| 3597 | else if (strcmp(value, "start") == 0) { |
| 3598 | action = ST_ADM_ACTION_START; |
| 3599 | } |
| 3600 | else if (strcmp(value, "shutdown") == 0) { |
| 3601 | action = ST_ADM_ACTION_SHUTDOWN; |
| 3602 | } |
| 3603 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3604 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3605 | goto out; |
| 3606 | } |
| 3607 | } |
| 3608 | else if (strcmp(key, "s") == 0) { |
| 3609 | if (!(px && action)) { |
| 3610 | /* |
| 3611 | * Indicates that we'll need to reprocess the parameters |
| 3612 | * as soon as backend and action are known |
| 3613 | */ |
| 3614 | if (!reprocess) { |
| 3615 | st_cur_param = cur_param; |
| 3616 | st_next_param = next_param; |
| 3617 | } |
| 3618 | reprocess = 1; |
| 3619 | } |
| 3620 | else if ((sv = findserver(px, value)) != NULL) { |
| 3621 | switch (action) { |
| 3622 | case ST_ADM_ACTION_DISABLE: |
| 3623 | if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) { |
| 3624 | /* Not already in maintenance, we can change the server state */ |
| 3625 | sv->state |= SRV_MAINTAIN; |
| 3626 | set_server_down(&sv->check); |
| 3627 | altered_servers++; |
| 3628 | total_servers++; |
| 3629 | } |
| 3630 | break; |
| 3631 | case ST_ADM_ACTION_ENABLE: |
| 3632 | if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) { |
| 3633 | /* Already in maintenance, we can change the server state */ |
| 3634 | set_server_up(&sv->check); |
| 3635 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 3636 | altered_servers++; |
| 3637 | total_servers++; |
| 3638 | } |
| 3639 | break; |
| 3640 | case ST_ADM_ACTION_STOP: |
| 3641 | case ST_ADM_ACTION_START: |
| 3642 | if (action == ST_ADM_ACTION_START) |
| 3643 | sv->uweight = sv->iweight; |
| 3644 | else |
| 3645 | sv->uweight = 0; |
| 3646 | |
| 3647 | server_recalc_eweight(sv); |
| 3648 | set_server_drain_state(sv); |
| 3649 | |
| 3650 | altered_servers++; |
| 3651 | total_servers++; |
| 3652 | break; |
| 3653 | case ST_ADM_ACTION_SHUTDOWN: |
| 3654 | if (px->state != PR_STSTOPPED) { |
| 3655 | struct session *sess, *sess_bck; |
| 3656 | |
| 3657 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 3658 | if (sess->srv_conn == sv) |
| 3659 | session_shutdown(sess, SN_ERR_KILLED); |
| 3660 | |
| 3661 | altered_servers++; |
| 3662 | total_servers++; |
| 3663 | } |
| 3664 | break; |
| 3665 | } |
| 3666 | } else { |
| 3667 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 3668 | total_servers++; |
| 3669 | } |
| 3670 | } |
| 3671 | if (reprocess && px && action) { |
| 3672 | /* Now, we know the backend and the action chosen by the user. |
| 3673 | * We can safely restart from the first server parameter |
| 3674 | * to reprocess them |
| 3675 | */ |
| 3676 | cur_param = st_cur_param; |
| 3677 | next_param = st_next_param; |
| 3678 | reprocess = 0; |
| 3679 | goto reprocess_servers; |
| 3680 | } |
| 3681 | |
| 3682 | next_param = cur_param; |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3687 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3688 | } |
| 3689 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3690 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3691 | } |
| 3692 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3693 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3694 | } |
| 3695 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3696 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3697 | } |
| 3698 | out: |
| 3699 | return 1; |
| 3700 | } |
| 3701 | |
| 3702 | |
| 3703 | static int stats_send_http_headers(struct stream_interface *si) |
| 3704 | { |
| 3705 | struct session *s = session_from_task(si->owner); |
| 3706 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3707 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3708 | |
| 3709 | chunk_printf(&trash, |
| 3710 | "HTTP/1.0 200 OK\r\n" |
| 3711 | "Cache-Control: no-cache\r\n" |
| 3712 | "Connection: close\r\n" |
| 3713 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3714 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3715 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3716 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3717 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 3718 | uri->refresh); |
| 3719 | |
| 3720 | chunk_appendf(&trash, "\r\n"); |
| 3721 | |
| 3722 | s->txn.status = 200; |
| 3723 | s->logs.tv_request = now; |
| 3724 | |
| 3725 | if (bi_putchk(si->ib, &trash) == -1) |
| 3726 | return 0; |
| 3727 | |
| 3728 | return 1; |
| 3729 | } |
| 3730 | |
| 3731 | static int stats_send_http_redirect(struct stream_interface *si) |
| 3732 | { |
| 3733 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3734 | struct session *s = session_from_task(si->owner); |
| 3735 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3736 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3737 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3738 | /* 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] | 3739 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3740 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3741 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3742 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3743 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | /* We don't want to land on the posted stats page because a refresh will |
| 3747 | * repost the data. We don't want this to happen on accident so we redirect |
| 3748 | * the browse to the stats page with a GET. |
| 3749 | */ |
| 3750 | chunk_printf(&trash, |
| 3751 | "HTTP/1.1 303 See Other\r\n" |
| 3752 | "Cache-Control: no-cache\r\n" |
| 3753 | "Content-Type: text/plain\r\n" |
| 3754 | "Connection: close\r\n" |
| 3755 | "Location: %s;st=%s%s%s%s\r\n" |
| 3756 | "\r\n", |
| 3757 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3758 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 3759 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 3760 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 3761 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3762 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3763 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3764 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3765 | scope_txt); |
| 3766 | |
| 3767 | s->txn.status = 303; |
| 3768 | s->logs.tv_request = now; |
| 3769 | |
| 3770 | if (bi_putchk(si->ib, &trash) == -1) |
| 3771 | return 0; |
| 3772 | |
| 3773 | return 1; |
| 3774 | } |
| 3775 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3776 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 3777 | * 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] | 3778 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3779 | * automatically unregisters itself once transfer is complete. |
| 3780 | */ |
| 3781 | static void http_stats_io_handler(struct stream_interface *si) |
| 3782 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3783 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3784 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3785 | struct channel *req = si->ob; |
| 3786 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3787 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3788 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 3789 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3790 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3791 | /* check that the output is not closed */ |
| 3792 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3793 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3794 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3795 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3796 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3797 | if (stats_send_http_headers(si)) { |
| 3798 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3799 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3800 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3801 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3802 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3803 | } |
| 3804 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3805 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3806 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3807 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3808 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3809 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3810 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3811 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3812 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3813 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3814 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3815 | } |
| 3816 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3817 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3818 | if (stats_send_http_redirect(si)) |
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 | } |
| 3821 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3822 | if (appctx->st0 == STAT_HTTP_DONE) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3823 | si_shutw(si); |
| 3824 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3825 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 3826 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3827 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3828 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 3829 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 3830 | si_shutr(si); |
| 3831 | res->flags |= CF_READ_NULL; |
| 3832 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3833 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3834 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3835 | /* update all other flags and resync with the other side */ |
| 3836 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3837 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3838 | /* we don't want to expire timeouts while we're processing requests */ |
| 3839 | si->ib->rex = TICK_ETERNITY; |
| 3840 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3841 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3842 | out: |
| 3843 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 3844 | /* check that we have released everything then unregister */ |
| 3845 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3846 | } |
| 3847 | } |
| 3848 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3849 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3850 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 3851 | { |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 3852 | if (!(conn->flags & CO_FL_CTRL_READY) || !conn->ctrl) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3853 | return "NONE"; |
| 3854 | return conn->ctrl->name; |
| 3855 | } |
| 3856 | |
| 3857 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 3858 | { |
| 3859 | static char ptr[17]; |
| 3860 | |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 3861 | if (!(conn->flags & CO_FL_XPRT_READY) || !conn->xprt) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3862 | return "NONE"; |
| 3863 | |
| 3864 | if (conn->xprt == &raw_sock) |
| 3865 | return "RAW"; |
| 3866 | |
| 3867 | #ifdef USE_OPENSSL |
| 3868 | if (conn->xprt == &ssl_sock) |
| 3869 | return "SSL"; |
| 3870 | #endif |
| 3871 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 3872 | return ptr; |
| 3873 | } |
| 3874 | |
| 3875 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 3876 | { |
| 3877 | static char ptr[17]; |
| 3878 | |
| 3879 | if (!conn->data) |
| 3880 | return "NONE"; |
| 3881 | |
| 3882 | if (conn->data == &sess_conn_cb) |
| 3883 | return "SESS"; |
| 3884 | |
| 3885 | if (conn->data == &si_conn_cb) |
| 3886 | return "STRM"; |
| 3887 | |
| 3888 | if (conn->data == &check_conn_cb) |
| 3889 | return "CHCK"; |
| 3890 | |
| 3891 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 3892 | return ptr; |
| 3893 | } |
| 3894 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 3895 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3896 | * 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] | 3897 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 3898 | * 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] | 3899 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3900 | 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] | 3901 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3902 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3903 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3904 | extern const char *monthname[12]; |
| 3905 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3906 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 3907 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3908 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3909 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3910 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3911 | 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] | 3912 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3913 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 3914 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3915 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3916 | appctx->ctx.sess.uid = 0; |
| 3917 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3918 | return 1; |
| 3919 | } |
| 3920 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3921 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3922 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3923 | appctx->ctx.sess.uid = sess->uniq_id; |
| 3924 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3925 | /* fall through */ |
| 3926 | |
| 3927 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3928 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3929 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3930 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3931 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3932 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 3933 | 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] | 3934 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 3935 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3936 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3937 | conn = objt_conn(sess->si[0].end); |
| 3938 | 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] | 3939 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3940 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3941 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3942 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3943 | break; |
| 3944 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3945 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3946 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3947 | default: |
| 3948 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3949 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3950 | break; |
| 3951 | } |
| 3952 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3953 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3954 | " 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] | 3955 | 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] | 3956 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3957 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3958 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3959 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 3960 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 3961 | sess->listener ? sess->listener->luid : 0); |
| 3962 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3963 | if (conn) |
| 3964 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 3965 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3966 | 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] | 3967 | case AF_INET: |
| 3968 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3969 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3970 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3971 | break; |
| 3972 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3973 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3974 | break; |
| 3975 | default: |
| 3976 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3977 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3978 | break; |
| 3979 | } |
| 3980 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3981 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3982 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3983 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3984 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3985 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 3986 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3987 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3988 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3989 | conn = objt_conn(sess->si[1].end); |
| 3990 | if (conn) |
| 3991 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 3992 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3993 | 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] | 3994 | case AF_INET: |
| 3995 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3996 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3997 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3998 | break; |
| 3999 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4000 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4001 | break; |
| 4002 | default: |
| 4003 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4004 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4005 | break; |
| 4006 | } |
| 4007 | |
| 4008 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4009 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4010 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4011 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 4012 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4013 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4014 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4015 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4016 | if (conn) |
| 4017 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4018 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4019 | 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] | 4020 | case AF_INET: |
| 4021 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4022 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4023 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4024 | break; |
| 4025 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4026 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4027 | break; |
| 4028 | default: |
| 4029 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4030 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4031 | break; |
| 4032 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4033 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4034 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4035 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4036 | sess->task, |
| 4037 | sess->task->state, |
| 4038 | sess->task->nice, sess->task->calls, |
| 4039 | sess->task->expire ? |
| 4040 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4041 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4042 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4043 | task_in_rq(sess->task) ? ", running" : ""); |
| 4044 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4045 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4046 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4047 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4048 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4049 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4050 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4051 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4052 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4053 | |
| 4054 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4055 | " 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] | 4056 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4057 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4058 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4059 | obj_type_name(sess->si[0].end), |
| 4060 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4061 | sess->si[0].exp ? |
| 4062 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4063 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4064 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4065 | sess->si[0].err_type); |
| 4066 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4067 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4068 | " 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] | 4069 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4070 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4071 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4072 | obj_type_name(sess->si[1].end), |
| 4073 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4074 | sess->si[1].exp ? |
| 4075 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4076 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4077 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4078 | sess->si[1].err_type); |
| 4079 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4080 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4081 | chunk_appendf(&trash, |
| 4082 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4083 | conn, |
| 4084 | get_conn_ctrl_name(conn), |
| 4085 | get_conn_xprt_name(conn), |
| 4086 | get_conn_data_name(conn), |
| 4087 | obj_type_name(conn->target), |
| 4088 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4089 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4090 | chunk_appendf(&trash, |
| 4091 | " 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] | 4092 | conn->flags, |
| 4093 | conn->t.sock.fd, |
| 4094 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_e : 0, |
| 4095 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_p : 0, |
| 4096 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4097 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4098 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 4099 | chunk_appendf(&trash, |
| 4100 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4101 | tmpctx, |
| 4102 | tmpctx->st0, |
| 4103 | tmpctx->st1, |
| 4104 | tmpctx->st2, |
| 4105 | tmpctx->applet->name); |
| 4106 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4107 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4108 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4109 | chunk_appendf(&trash, |
| 4110 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4111 | conn, |
| 4112 | get_conn_ctrl_name(conn), |
| 4113 | get_conn_xprt_name(conn), |
| 4114 | get_conn_data_name(conn), |
| 4115 | obj_type_name(conn->target), |
| 4116 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4117 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4118 | chunk_appendf(&trash, |
| 4119 | " 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] | 4120 | conn->flags, |
| 4121 | conn->t.sock.fd, |
| 4122 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_e : 0, |
| 4123 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_p : 0, |
| 4124 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4125 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4126 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 4127 | chunk_appendf(&trash, |
| 4128 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4129 | tmpctx, |
| 4130 | tmpctx->st0, |
| 4131 | tmpctx->st1, |
| 4132 | tmpctx->st2, |
| 4133 | tmpctx->applet->name); |
| 4134 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4135 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4136 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4137 | " 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] | 4138 | " an_exp=%s", |
| 4139 | sess->req, |
| 4140 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4141 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4142 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4143 | sess->req->analyse_exp ? |
| 4144 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 4145 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4146 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4147 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4148 | " rex=%s", |
| 4149 | sess->req->rex ? |
| 4150 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4151 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4152 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4153 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4154 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4155 | " 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] | 4156 | sess->req->wex ? |
| 4157 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4158 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4159 | sess->req->buf, |
| 4160 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4161 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4162 | sess->txn.req.next, sess->req->buf->i, |
| 4163 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4164 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4165 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4166 | " 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] | 4167 | " an_exp=%s", |
| 4168 | sess->rep, |
| 4169 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4170 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4171 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4172 | sess->rep->analyse_exp ? |
| 4173 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 4174 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4175 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4176 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4177 | " rex=%s", |
| 4178 | sess->rep->rex ? |
| 4179 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4180 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4181 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4182 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4183 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4184 | " 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] | 4185 | sess->rep->wex ? |
| 4186 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4187 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4188 | sess->rep->buf, |
| 4189 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4190 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4191 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4192 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4193 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4194 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4195 | return 0; |
| 4196 | |
| 4197 | /* use other states to dump the contents */ |
| 4198 | } |
| 4199 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4200 | appctx->ctx.sess.uid = 0; |
| 4201 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4202 | return 1; |
| 4203 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4204 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4205 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4206 | * 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] | 4207 | * to be called again, otherwise non-zero. It is designed to be called |
| 4208 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4209 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4210 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4211 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4212 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4213 | struct connection *conn; |
| 4214 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4215 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4216 | /* If we're forced to shut down, we might have to remove our |
| 4217 | * reference to the last session being dumped. |
| 4218 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4219 | if (appctx->st2 == STAT_ST_LIST) { |
| 4220 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 4221 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 4222 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4223 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4224 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4225 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4226 | } |
| 4227 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4228 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4229 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4230 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4231 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4232 | /* the function had not been called yet, let's prepare the |
| 4233 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4234 | * pointer to the first in the global list. When a target |
| 4235 | * session is being destroyed, it is responsible for updating |
| 4236 | * this pointer. We know we have reached the end when this |
| 4237 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4238 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4239 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 4240 | appctx->ctx.sess.bref.ref = sessions.n; |
| 4241 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4242 | /* fall through */ |
| 4243 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4244 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4245 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4246 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 4247 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 4248 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4249 | } |
| 4250 | |
| 4251 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4252 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 4253 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4254 | struct session *curr_sess; |
| 4255 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4256 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4257 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4258 | if (appctx->ctx.sess.target) { |
| 4259 | 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] | 4260 | goto next_sess; |
| 4261 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4262 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4263 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4264 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4265 | return 0; |
| 4266 | |
| 4267 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4268 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 4269 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 4270 | if (appctx->ctx.sess.target != (void *)-1) { |
| 4271 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4272 | break; |
| 4273 | } |
| 4274 | else |
| 4275 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4276 | } |
| 4277 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4278 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4279 | "%p: proto=%s", |
| 4280 | curr_sess, |
| 4281 | curr_sess->listener->proto->name); |
| 4282 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4283 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4284 | conn = objt_conn(curr_sess->si[0].end); |
| 4285 | 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] | 4286 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4287 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4288 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4289 | " src=%s:%d fe=%s be=%s srv=%s", |
| 4290 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4291 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4292 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4293 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4294 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4295 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4296 | break; |
| 4297 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4298 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4299 | " src=unix:%d fe=%s be=%s srv=%s", |
| 4300 | curr_sess->listener->luid, |
| 4301 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4302 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4303 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4304 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4305 | break; |
| 4306 | } |
| 4307 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4308 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 4309 | " ts=%02x age=%s calls=%d", |
| 4310 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 4311 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 4312 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4313 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4314 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 4315 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4316 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4317 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4318 | curr_sess->req->analysers, |
| 4319 | curr_sess->req->rex ? |
| 4320 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 4321 | TICKS_TO_MS(1000)) : ""); |
| 4322 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4323 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4324 | ",wx=%s", |
| 4325 | curr_sess->req->wex ? |
| 4326 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 4327 | TICKS_TO_MS(1000)) : ""); |
| 4328 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4329 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4330 | ",ax=%s]", |
| 4331 | curr_sess->req->analyse_exp ? |
| 4332 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 4333 | TICKS_TO_MS(1000)) : ""); |
| 4334 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4335 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 4336 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4337 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4338 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4339 | curr_sess->rep->analysers, |
| 4340 | curr_sess->rep->rex ? |
| 4341 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 4342 | TICKS_TO_MS(1000)) : ""); |
| 4343 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4344 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4345 | ",wx=%s", |
| 4346 | curr_sess->rep->wex ? |
| 4347 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 4348 | TICKS_TO_MS(1000)) : ""); |
| 4349 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4350 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4351 | ",ax=%s]", |
| 4352 | curr_sess->rep->analyse_exp ? |
| 4353 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 4354 | TICKS_TO_MS(1000)) : ""); |
| 4355 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4356 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4357 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4358 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 4359 | curr_sess->si[0].state, |
| 4360 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4361 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4362 | curr_sess->si[0].exp ? |
| 4363 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 4364 | TICKS_TO_MS(1000)) : ""); |
| 4365 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4366 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4367 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4368 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 4369 | curr_sess->si[1].state, |
| 4370 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4371 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4372 | curr_sess->si[1].exp ? |
| 4373 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 4374 | TICKS_TO_MS(1000)) : ""); |
| 4375 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4376 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4377 | " exp=%s", |
| 4378 | curr_sess->task->expire ? |
| 4379 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 4380 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 4381 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4382 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4383 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4384 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4385 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4386 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4387 | /* let's try again later from this session. We add ourselves into |
| 4388 | * this session's users so that it can remove us upon termination. |
| 4389 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4390 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4391 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4392 | } |
| 4393 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4394 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4395 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4396 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4397 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4398 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4399 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4400 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4401 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4402 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4403 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4404 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4405 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4406 | return 0; |
| 4407 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4408 | appctx->ctx.sess.target = NULL; |
| 4409 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4410 | return 1; |
| 4411 | } |
| 4412 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4413 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4414 | /* fall through */ |
| 4415 | |
| 4416 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4417 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4418 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4419 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 4420 | } |
| 4421 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4422 | /* This is called when the stream interface is closed. For instance, upon an |
| 4423 | * external abort, we won't call the i/o handler anymore so we may need to |
| 4424 | * remove back references to the session currently being dumped. |
| 4425 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 4426 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4427 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4428 | struct appctx *appctx = __objt_appctx(si->end); |
| 4429 | |
| 4430 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 4431 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 4432 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4433 | } |
| 4434 | } |
| 4435 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4436 | /* This function is used to either dump tables states (when action is set |
| 4437 | * 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] | 4438 | * It returns 0 if the output buffer is full and it needs to be called |
| 4439 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4440 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4441 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4442 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4443 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4444 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4445 | struct ebmb_node *eb; |
| 4446 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4447 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4448 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4449 | |
| 4450 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4451 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4452 | * - STAT_ST_INIT : the first call |
| 4453 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4454 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4455 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4456 | * and the entry pointer points to the next entry to be dumped, |
| 4457 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4458 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4459 | * data though. |
| 4460 | */ |
| 4461 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4462 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4463 | /* 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] | 4464 | if (appctx->st2 == STAT_ST_LIST) { |
| 4465 | appctx->ctx.table.entry->ref_cnt--; |
| 4466 | 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] | 4467 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4468 | return 1; |
| 4469 | } |
| 4470 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4471 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4472 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4473 | while (appctx->st2 != STAT_ST_FIN) { |
| 4474 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4475 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4476 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 4477 | if (!appctx->ctx.table.proxy) |
| 4478 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4479 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4480 | appctx->ctx.table.entry = NULL; |
| 4481 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4482 | break; |
| 4483 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4484 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4485 | if (!appctx->ctx.table.proxy || |
| 4486 | (appctx->ctx.table.target && |
| 4487 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 4488 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4489 | break; |
| 4490 | } |
| 4491 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4492 | if (appctx->ctx.table.proxy->table.size) { |
| 4493 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 4494 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4495 | return 0; |
| 4496 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4497 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 4498 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4499 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4500 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4501 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4502 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 4503 | appctx->ctx.table.entry->ref_cnt++; |
| 4504 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4505 | break; |
| 4506 | } |
| 4507 | } |
| 4508 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4509 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4510 | break; |
| 4511 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4512 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4513 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4514 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4515 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4516 | /* we're filtering on some data contents */ |
| 4517 | void *ptr; |
| 4518 | long long data; |
| 4519 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4520 | dt = appctx->ctx.table.data_type; |
| 4521 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 4522 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4523 | dt); |
| 4524 | |
| 4525 | data = 0; |
| 4526 | switch (stktable_data_types[dt].std_type) { |
| 4527 | case STD_T_SINT: |
| 4528 | data = stktable_data_cast(ptr, std_t_sint); |
| 4529 | break; |
| 4530 | case STD_T_UINT: |
| 4531 | data = stktable_data_cast(ptr, std_t_uint); |
| 4532 | break; |
| 4533 | case STD_T_ULL: |
| 4534 | data = stktable_data_cast(ptr, std_t_ull); |
| 4535 | break; |
| 4536 | case STD_T_FRQP: |
| 4537 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4538 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4539 | break; |
| 4540 | } |
| 4541 | |
| 4542 | /* 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] | 4543 | if ((data < appctx->ctx.table.value && |
| 4544 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 4545 | appctx->ctx.table.data_op == STD_OP_GT || |
| 4546 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 4547 | (data == appctx->ctx.table.value && |
| 4548 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 4549 | appctx->ctx.table.data_op == STD_OP_GT || |
| 4550 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 4551 | (data > appctx->ctx.table.value && |
| 4552 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 4553 | appctx->ctx.table.data_op == STD_OP_LT || |
| 4554 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4555 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4556 | } |
| 4557 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4558 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4559 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 4560 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 4561 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4562 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4563 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4564 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4565 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4566 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4567 | struct stksess *old = appctx->ctx.table.entry; |
| 4568 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 4569 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4570 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 4571 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 4572 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 4573 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4574 | break; |
| 4575 | } |
| 4576 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4577 | |
| 4578 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4579 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 4580 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 4581 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4582 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4583 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 4584 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4585 | break; |
| 4586 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4587 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4588 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4589 | break; |
| 4590 | } |
| 4591 | } |
| 4592 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4593 | } |
| 4594 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4595 | /* 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] | 4596 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 4597 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 4598 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 4599 | * lines are respected within the limit of 70 output chars. Lines that are |
| 4600 | * continuation of a previous truncated line begin with "+" instead of " " |
| 4601 | * after the offset. The new pointer is returned. |
| 4602 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4603 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 4604 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4605 | { |
| 4606 | int end; |
| 4607 | unsigned char c; |
| 4608 | |
| 4609 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4610 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4611 | return ptr; |
| 4612 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 4613 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4614 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4615 | while (ptr < len && ptr < bsize) { |
| 4616 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4617 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4618 | if (out->len > end - 2) |
| 4619 | break; |
| 4620 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4621 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4622 | if (out->len > end - 3) |
| 4623 | break; |
| 4624 | out->str[out->len++] = '\\'; |
| 4625 | switch (c) { |
| 4626 | case '\t': c = 't'; break; |
| 4627 | case '\n': c = 'n'; break; |
| 4628 | case '\r': c = 'r'; break; |
| 4629 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4630 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4631 | } |
| 4632 | out->str[out->len++] = c; |
| 4633 | } else { |
| 4634 | if (out->len > end - 5) |
| 4635 | break; |
| 4636 | out->str[out->len++] = '\\'; |
| 4637 | out->str[out->len++] = 'x'; |
| 4638 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 4639 | out->str[out->len++] = hextab[c & 0xF]; |
| 4640 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4641 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4642 | /* we had a line break, let's return now */ |
| 4643 | out->str[out->len++] = '\n'; |
| 4644 | *line = ptr; |
| 4645 | return ptr; |
| 4646 | } |
| 4647 | } |
| 4648 | /* we have an incomplete line, we return it as-is */ |
| 4649 | out->str[out->len++] = '\n'; |
| 4650 | return ptr; |
| 4651 | } |
| 4652 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4653 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4654 | * 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] | 4655 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4656 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4657 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4658 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4659 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4660 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4661 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4662 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4663 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4664 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4665 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4666 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4667 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4668 | /* the function had not been called yet, let's prepare the |
| 4669 | * buffer for a response. |
| 4670 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4671 | struct tm tm; |
| 4672 | |
| 4673 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4674 | 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] | 4675 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4676 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 4677 | error_snapshot_id); |
| 4678 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4679 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4680 | /* Socket buffer full. Let's try again later from the same point */ |
| 4681 | return 0; |
| 4682 | } |
| 4683 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4684 | appctx->ctx.errors.px = proxy; |
| 4685 | appctx->ctx.errors.buf = 0; |
| 4686 | appctx->ctx.errors.bol = 0; |
| 4687 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4688 | } |
| 4689 | |
| 4690 | /* we have two inner loops here, one for the proxy, the other one for |
| 4691 | * the buffer. |
| 4692 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4693 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4694 | struct error_snapshot *es; |
| 4695 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4696 | if (appctx->ctx.errors.buf == 0) |
| 4697 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4698 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4699 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4700 | |
| 4701 | if (!es->when.tv_sec) |
| 4702 | goto next; |
| 4703 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4704 | if (appctx->ctx.errors.iid >= 0 && |
| 4705 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 4706 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4707 | goto next; |
| 4708 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4709 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4710 | /* just print headers now */ |
| 4711 | |
| 4712 | char pn[INET6_ADDRSTRLEN]; |
| 4713 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4714 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4715 | |
| 4716 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4717 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4718 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4719 | 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] | 4720 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4721 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 4722 | case AF_INET: |
| 4723 | case AF_INET6: |
| 4724 | port = get_host_port(&es->src); |
| 4725 | break; |
| 4726 | default: |
| 4727 | port = 0; |
| 4728 | } |
| 4729 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4730 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4731 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4732 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4733 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4734 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4735 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4736 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 4737 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4738 | break; |
| 4739 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4740 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4741 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4742 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4743 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4744 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4745 | break; |
| 4746 | } |
| 4747 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4748 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4749 | ", server %s (#%d), event #%u\n" |
| 4750 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 4751 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 4752 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 4753 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 4754 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 4755 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 4756 | es->ev_id, |
| 4757 | pn, port, es->sid, es->s_flags, |
| 4758 | es->state, es->m_flags, es->t_flags, |
| 4759 | es->m_clen, es->m_blen, |
| 4760 | es->b_flags, es->b_out, es->b_tot, |
| 4761 | es->len, es->b_wrap, es->pos); |
| 4762 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4763 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4764 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4765 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4766 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4767 | appctx->ctx.errors.ptr = 0; |
| 4768 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4769 | } |
| 4770 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4771 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4772 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4773 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4774 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4775 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4776 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4777 | goto next; |
| 4778 | } |
| 4779 | |
| 4780 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4781 | 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] | 4782 | int newptr; |
| 4783 | int newline; |
| 4784 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4785 | newline = appctx->ctx.errors.bol; |
| 4786 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 4787 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4788 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4789 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4790 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4791 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4792 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4793 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4794 | appctx->ctx.errors.ptr = newptr; |
| 4795 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4796 | }; |
| 4797 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4798 | appctx->ctx.errors.bol = 0; |
| 4799 | appctx->ctx.errors.ptr = -1; |
| 4800 | appctx->ctx.errors.buf++; |
| 4801 | if (appctx->ctx.errors.buf > 1) { |
| 4802 | appctx->ctx.errors.buf = 0; |
| 4803 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4804 | } |
| 4805 | } |
| 4806 | |
| 4807 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4808 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4809 | } |
| 4810 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4811 | /* parse the "level" argument on the bind lines */ |
| 4812 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 4813 | { |
| 4814 | if (!*args[cur_arg + 1]) { |
| 4815 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 4816 | return ERR_ALERT | ERR_FATAL; |
| 4817 | } |
| 4818 | |
| 4819 | if (!strcmp(args[cur_arg+1], "user")) |
| 4820 | conf->level = ACCESS_LVL_USER; |
| 4821 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 4822 | conf->level = ACCESS_LVL_OPER; |
| 4823 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 4824 | conf->level = ACCESS_LVL_ADMIN; |
| 4825 | else { |
| 4826 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 4827 | args[cur_arg], args[cur_arg+1]); |
| 4828 | return ERR_ALERT | ERR_FATAL; |
| 4829 | } |
| 4830 | |
| 4831 | return 0; |
| 4832 | } |
| 4833 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4834 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4835 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4836 | .name = "<STATS>", /* used for logging */ |
| 4837 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 4838 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4839 | }; |
| 4840 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4841 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4842 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4843 | .name = "<CLI>", /* used for logging */ |
| 4844 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4845 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4846 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4847 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 4848 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4849 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 4850 | { 0, NULL, NULL }, |
| 4851 | }}; |
| 4852 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4853 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 4854 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 4855 | { NULL, NULL, 0 }, |
| 4856 | }}; |
| 4857 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4858 | __attribute__((constructor)) |
| 4859 | static void __dumpstats_module_init(void) |
| 4860 | { |
| 4861 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4862 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4863 | } |
| 4864 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4865 | /* |
| 4866 | * Local variables: |
| 4867 | * c-indent-level: 8 |
| 4868 | * c-basic-offset: 8 |
| 4869 | * End: |
| 4870 | */ |