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> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 49 | #include <proto/pattern.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 50 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 51 | #include <proto/listener.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 52 | #include <proto/map.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 53 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 54 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 55 | #include <proto/proxy.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 56 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 57 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 58 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 59 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 60 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 61 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 62 | #ifdef USE_OPENSSL |
| 63 | #include <proto/ssl_sock.h> |
| 64 | #endif |
| 65 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 66 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 67 | 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] | 68 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 69 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 70 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 71 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 72 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 73 | static int stats_maps_list(struct stream_interface *si); |
| 74 | static int stats_map_list(struct stream_interface *si); |
| 75 | static int stats_map_lookup(struct stream_interface *si); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 76 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 77 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 78 | * cli_io_handler() |
| 79 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 80 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 81 | * -> stats_dump_info_to_buffer() // "show info" |
| 82 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 83 | * -> stats_dump_csv_header() |
| 84 | * -> stats_dump_proxy_to_buffer() |
| 85 | * -> stats_dump_fe_stats() |
| 86 | * -> stats_dump_li_stats() |
| 87 | * -> stats_dump_sv_stats() |
| 88 | * -> stats_dump_be_stats() |
| 89 | * |
| 90 | * http_stats_io_handler() |
| 91 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 92 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 93 | * -> stats_dump_html_head() // emits the HTML headers |
| 94 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 95 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 96 | * -> stats_dump_html_px_hdr() |
| 97 | * -> stats_dump_fe_stats() |
| 98 | * -> stats_dump_li_stats() |
| 99 | * -> stats_dump_sv_stats() |
| 100 | * -> stats_dump_be_stats() |
| 101 | * -> stats_dump_html_px_end() |
| 102 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 103 | */ |
| 104 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 105 | static struct si_applet cli_applet; |
| 106 | |
| 107 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 108 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 109 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 110 | " clear table : remove an entry from a table\n" |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 111 | " clear map [id] : clear the content of this map\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 112 | " help : this message\n" |
| 113 | " prompt : toggle interactive mode with prompt\n" |
| 114 | " quit : disconnect\n" |
| 115 | " show info : report information about the running process\n" |
| 116 | " show stat : report counters for each proxy and server\n" |
| 117 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 118 | " 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] | 119 | " show table [id]: report table usage stats or dump this table's contents\n" |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 120 | " show map [id] : report avalaible maps or dump this map's contents\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 121 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 122 | " set weight : change a server's weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 123 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 124 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 125 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 126 | " set rate-limit : change a rate limiting value\n" |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 127 | " set map [id] [key] [value] : modify map entry\n" |
| 128 | " add map [id] [key] [value] : add map entry\n" |
| 129 | " del map [id] [key] : delete map entry\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 130 | " disable : put a server or frontend in maintenance mode\n" |
| 131 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 132 | " 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] | 133 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 134 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 135 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 136 | "Permission denied\n" |
| 137 | ""; |
| 138 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 139 | /* data transmission states for the stats responses */ |
| 140 | enum { |
| 141 | STAT_ST_INIT = 0, |
| 142 | STAT_ST_HEAD, |
| 143 | STAT_ST_INFO, |
| 144 | STAT_ST_LIST, |
| 145 | STAT_ST_END, |
| 146 | STAT_ST_FIN, |
| 147 | }; |
| 148 | |
| 149 | /* data transmission states for the stats responses inside a proxy */ |
| 150 | enum { |
| 151 | STAT_PX_ST_INIT = 0, |
| 152 | STAT_PX_ST_TH, |
| 153 | STAT_PX_ST_FE, |
| 154 | STAT_PX_ST_LI, |
| 155 | STAT_PX_ST_SV, |
| 156 | STAT_PX_ST_BE, |
| 157 | STAT_PX_ST_END, |
| 158 | STAT_PX_ST_FIN, |
| 159 | }; |
| 160 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 161 | extern const char *stat_status_codes[]; |
| 162 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 163 | /* 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] | 164 | * 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] | 165 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 166 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 167 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 168 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 169 | s->target = &cli_applet.obj_type; |
Willy Tarreau | 4171e9e | 2013-12-01 12:32:30 +0100 | [diff] [blame] | 170 | /* 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] | 171 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 172 | tv_zero(&s->logs.tv_request); |
| 173 | s->logs.t_queue = 0; |
| 174 | s->logs.t_connect = 0; |
| 175 | s->logs.t_data = 0; |
| 176 | s->logs.t_close = 0; |
| 177 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 178 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 179 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 180 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 181 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 182 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 183 | if (s->listener->timeout) { |
| 184 | s->req->rto = *s->listener->timeout; |
| 185 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 186 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 187 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 190 | /* allocate a new stats frontend named <name>, and return it |
| 191 | * (or NULL in case of lack of memory). |
| 192 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 193 | 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] | 194 | { |
| 195 | struct proxy *fe; |
| 196 | |
| 197 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 198 | if (!fe) |
| 199 | return NULL; |
| 200 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 201 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 202 | fe->next = proxy; |
| 203 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 204 | fe->last_change = now.tv_sec; |
| 205 | fe->id = strdup("GLOBAL"); |
| 206 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 207 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 208 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 209 | fe->conf.file = strdup(file); |
| 210 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 211 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 212 | |
| 213 | /* the stats frontend is the only one able to assign ID #0 */ |
| 214 | fe->conf.id.key = fe->uuid = 0; |
| 215 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 216 | return fe; |
| 217 | } |
| 218 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 219 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 220 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 221 | * error message into the <err> buffer which will be preallocated. The trailing |
| 222 | * '\n' must not be written. The function must be called with <args> pointing to |
| 223 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 224 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 225 | 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] | 226 | struct proxy *defpx, const char *file, int line, |
| 227 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 228 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 229 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 230 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 231 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 232 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 233 | int cur_arg; |
| 234 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 235 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 236 | 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] | 237 | return -1; |
| 238 | } |
| 239 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 240 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 241 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 242 | 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] | 243 | return -1; |
| 244 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 245 | } |
| 246 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 247 | 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] | 248 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 249 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 250 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 251 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 252 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 253 | return -1; |
| 254 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 255 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 256 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 257 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 258 | static int bind_dumped; |
| 259 | struct bind_kw *kw; |
| 260 | |
| 261 | kw = bind_find_kw(args[cur_arg]); |
| 262 | if (kw) { |
| 263 | if (!kw->parse) { |
| 264 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 265 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 266 | return -1; |
| 267 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 268 | |
| 269 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 270 | if (err && *err) |
| 271 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 272 | else |
| 273 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 274 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 275 | return -1; |
| 276 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 277 | |
| 278 | cur_arg += 1 + kw->skip; |
| 279 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 280 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 281 | |
| 282 | if (!bind_dumped) { |
| 283 | bind_dump_kws(err); |
| 284 | indent_msg(err, 4); |
| 285 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 286 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 287 | |
| 288 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 289 | args[0], args[1], args[cur_arg], |
| 290 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 291 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 292 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 293 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 294 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 295 | l->maxconn = global.stats_fe->maxconn; |
| 296 | l->backlog = global.stats_fe->backlog; |
| 297 | l->timeout = &global.stats_fe->timeout.client; |
| 298 | l->accept = session_accept; |
| 299 | l->handler = process_session; |
| 300 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 301 | l->nice = -64; /* we want to boost priority for local stats */ |
| 302 | global.maxsock += l->maxconn; |
| 303 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 304 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 305 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 306 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 307 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 308 | |
| 309 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 310 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 311 | return -1; |
| 312 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 313 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 314 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 315 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 316 | return -1; |
| 317 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 318 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 319 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 320 | 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] | 321 | return -1; |
| 322 | } |
| 323 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 324 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 325 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 326 | else if (!strcmp(args[1], "maxconn")) { |
| 327 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 328 | |
| 329 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 330 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 331 | return -1; |
| 332 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 333 | |
| 334 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 335 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 336 | 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] | 337 | return -1; |
| 338 | } |
| 339 | } |
| 340 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 341 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 342 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 343 | int cur_arg = 2; |
| 344 | unsigned int set = 0; |
| 345 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 346 | if (!global.stats_fe) { |
| 347 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 348 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 349 | return -1; |
| 350 | } |
| 351 | } |
| 352 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 353 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 354 | unsigned int low, high; |
| 355 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 356 | if (strcmp(args[cur_arg], "all") == 0) { |
| 357 | set = 0; |
| 358 | break; |
| 359 | } |
| 360 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 361 | set |= 0x55555555; |
| 362 | } |
| 363 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 364 | set |= 0xAAAAAAAA; |
| 365 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 366 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 367 | char *dash = strchr(args[cur_arg], '-'); |
| 368 | |
| 369 | low = high = str2uic(args[cur_arg]); |
| 370 | if (dash) |
| 371 | high = str2uic(dash + 1); |
| 372 | |
| 373 | if (high < low) { |
| 374 | unsigned int swap = low; |
| 375 | low = high; |
| 376 | high = swap; |
| 377 | } |
| 378 | |
| 379 | if (low < 1 || high > 32) { |
| 380 | memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n", |
| 381 | args[0], args[1]); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 382 | return -1; |
| 383 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 384 | |
| 385 | while (low <= high) |
| 386 | set |= 1 << (low++ - 1); |
| 387 | } |
| 388 | else { |
| 389 | memprintf(err, |
| 390 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 391 | args[0], args[1]); |
| 392 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 393 | } |
| 394 | cur_arg++; |
| 395 | } |
| 396 | global.stats_fe->bind_proc = set; |
| 397 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 398 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 399 | 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] | 400 | return -1; |
| 401 | } |
| 402 | return 0; |
| 403 | } |
| 404 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 405 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 406 | * for clearing it if needed. |
| 407 | */ |
| 408 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 409 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 410 | chunk_appendf(&trash, |
| 411 | "# pxname,svname," |
| 412 | "qcur,qmax," |
| 413 | "scur,smax,slim,stot," |
| 414 | "bin,bout," |
| 415 | "dreq,dresp," |
| 416 | "ereq,econ,eresp," |
| 417 | "wretr,wredis," |
| 418 | "status,weight,act,bck," |
| 419 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 420 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 421 | "rate,rate_lim,rate_max," |
| 422 | "check_status,check_code,check_duration," |
| 423 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 424 | "req_rate,req_rate_max,req_tot," |
| 425 | "cli_abrt,srv_abrt," |
| 426 | "comp_in,comp_out,comp_byp,comp_rsp," |
| 427 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 428 | } |
| 429 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 430 | /* print a string of text buffer to <out>. The format is : |
| 431 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 432 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 433 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 434 | */ |
| 435 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 436 | { |
| 437 | unsigned char c; |
| 438 | int ptr = 0; |
| 439 | |
| 440 | while (buf[ptr] && ptr < bsize) { |
| 441 | c = buf[ptr]; |
| 442 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 443 | if (out->len > out->size - 1) |
| 444 | break; |
| 445 | out->str[out->len++] = c; |
| 446 | } |
| 447 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 448 | if (out->len > out->size - 2) |
| 449 | break; |
| 450 | out->str[out->len++] = '\\'; |
| 451 | switch (c) { |
| 452 | case ' ': c = ' '; break; |
| 453 | case '\t': c = 't'; break; |
| 454 | case '\n': c = 'n'; break; |
| 455 | case '\r': c = 'r'; break; |
| 456 | case '\e': c = 'e'; break; |
| 457 | case '\\': c = '\\'; break; |
| 458 | } |
| 459 | out->str[out->len++] = c; |
| 460 | } |
| 461 | else { |
| 462 | if (out->len > out->size - 4) |
| 463 | break; |
| 464 | out->str[out->len++] = '\\'; |
| 465 | out->str[out->len++] = 'x'; |
| 466 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 467 | out->str[out->len++] = hextab[c & 0xF]; |
| 468 | } |
| 469 | ptr++; |
| 470 | } |
| 471 | |
| 472 | return ptr; |
| 473 | } |
| 474 | |
| 475 | /* print a buffer in hexa. |
| 476 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 477 | */ |
| 478 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 479 | { |
| 480 | unsigned char c; |
| 481 | int ptr = 0; |
| 482 | |
| 483 | while (ptr < bsize) { |
| 484 | c = buf[ptr]; |
| 485 | |
| 486 | if (out->len > out->size - 2) |
| 487 | break; |
| 488 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 489 | out->str[out->len++] = hextab[c & 0xF]; |
| 490 | |
| 491 | ptr++; |
| 492 | } |
| 493 | return ptr; |
| 494 | } |
| 495 | |
| 496 | /* Dump the status of a table to a stream interface's |
| 497 | * read buffer. It returns 0 if the output buffer is full |
| 498 | * and needs to be called again, otherwise non-zero. |
| 499 | */ |
| 500 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 501 | struct proxy *proxy, struct proxy *target) |
| 502 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 503 | struct session *s = session_from_task(si->owner); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 504 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 505 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 506 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 507 | |
| 508 | /* any other information should be dumped here */ |
| 509 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 510 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 511 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 512 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 513 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 514 | return 0; |
| 515 | |
| 516 | return 1; |
| 517 | } |
| 518 | |
| 519 | /* Dump the a table entry to a stream interface's |
| 520 | * read buffer. It returns 0 if the output buffer is full |
| 521 | * and needs to be called again, otherwise non-zero. |
| 522 | */ |
| 523 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 524 | struct proxy *proxy, struct stksess *entry) |
| 525 | { |
| 526 | int dt; |
| 527 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 528 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 529 | |
| 530 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 531 | char addr[INET_ADDRSTRLEN]; |
| 532 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 533 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 534 | } |
| 535 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 536 | char addr[INET6_ADDRSTRLEN]; |
| 537 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 538 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 539 | } |
| 540 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 541 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 542 | } |
| 543 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 544 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 545 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 546 | } |
| 547 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 548 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 549 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 550 | } |
| 551 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 552 | 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] | 553 | |
| 554 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 555 | void *ptr; |
| 556 | |
| 557 | if (proxy->table.data_ofs[dt] == 0) |
| 558 | continue; |
| 559 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 560 | 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] | 561 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 562 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 563 | |
| 564 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 565 | switch (stktable_data_types[dt].std_type) { |
| 566 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 567 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 568 | break; |
| 569 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 570 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 571 | break; |
| 572 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 573 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 574 | break; |
| 575 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 576 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 577 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 578 | proxy->table.data_arg[dt].u)); |
| 579 | break; |
| 580 | } |
| 581 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 582 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 583 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 584 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 585 | return 0; |
| 586 | |
| 587 | return 1; |
| 588 | } |
| 589 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 590 | 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] | 591 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 592 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 593 | struct appctx *appctx = __objt_appctx(si->end); |
| 594 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 595 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 596 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 597 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 598 | long long value; |
| 599 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 600 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 601 | void *ptr; |
| 602 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 603 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 604 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 605 | |
| 606 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 607 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 608 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 609 | return; |
| 610 | } |
| 611 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 612 | switch (px->table.type) { |
| 613 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 614 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 615 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 616 | break; |
| 617 | case STKTABLE_TYPE_IPV6: |
| 618 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 619 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 620 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 621 | case STKTABLE_TYPE_INTEGER: |
| 622 | { |
| 623 | char *endptr; |
| 624 | unsigned long val; |
| 625 | errno = 0; |
| 626 | val = strtoul(args[4], &endptr, 10); |
| 627 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 628 | (errno != 0 && val == 0) || endptr == args[4] || |
| 629 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 630 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 631 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 632 | return; |
| 633 | } |
| 634 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 635 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 636 | break; |
| 637 | } |
| 638 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 639 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 640 | static_table_key->key = args[4]; |
| 641 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 642 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 643 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 644 | switch (action) { |
| 645 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 646 | 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] | 647 | break; |
| 648 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 649 | 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] | 650 | break; |
| 651 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 652 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 653 | break; |
| 654 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 655 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 656 | return; |
| 657 | } |
| 658 | |
| 659 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 660 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 661 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 662 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 663 | return; |
| 664 | } |
| 665 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 666 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 667 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 668 | switch (action) { |
| 669 | case STAT_CLI_O_TAB: |
| 670 | if (!ts) |
| 671 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 672 | chunk_reset(&trash); |
| 673 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 674 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 675 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 676 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 677 | |
| 678 | case STAT_CLI_O_CLR: |
| 679 | if (!ts) |
| 680 | return; |
| 681 | if (ts->ref_cnt) { |
| 682 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 683 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 684 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 685 | return; |
| 686 | } |
| 687 | stksess_kill(&px->table, ts); |
| 688 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 689 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 690 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 691 | if (ts) |
| 692 | stktable_touch(&px->table, ts, 1); |
| 693 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 694 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 695 | if (!ts) { |
| 696 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 697 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 698 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 699 | return; |
| 700 | } |
| 701 | stktable_store(&px->table, ts, 1); |
| 702 | } |
| 703 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 704 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 705 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 706 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 707 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 708 | return; |
| 709 | } |
| 710 | |
| 711 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 712 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 713 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 714 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 715 | return; |
| 716 | } |
| 717 | |
| 718 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 719 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 720 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 721 | return; |
| 722 | } |
| 723 | |
| 724 | 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] | 725 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 726 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 727 | return; |
| 728 | } |
| 729 | |
| 730 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 731 | |
| 732 | switch (stktable_data_types[data_type].std_type) { |
| 733 | case STD_T_SINT: |
| 734 | stktable_data_cast(ptr, std_t_sint) = value; |
| 735 | break; |
| 736 | case STD_T_UINT: |
| 737 | stktable_data_cast(ptr, std_t_uint) = value; |
| 738 | break; |
| 739 | case STD_T_ULL: |
| 740 | stktable_data_cast(ptr, std_t_ull) = value; |
| 741 | break; |
| 742 | case STD_T_FRQP: |
| 743 | /* We set both the current and previous values. That way |
| 744 | * the reported frequency is stable during all the period |
| 745 | * then slowly fades out. This allows external tools to |
| 746 | * push measures without having to update them too often. |
| 747 | */ |
| 748 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 749 | frqp->curr_tick = now_ms; |
| 750 | frqp->prev_ctr = 0; |
| 751 | frqp->curr_ctr = value; |
| 752 | break; |
| 753 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 754 | } |
| 755 | break; |
| 756 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 757 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 758 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 759 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 760 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 761 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 762 | } |
| 763 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 764 | 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] | 765 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 766 | struct appctx *appctx = __objt_appctx(si->end); |
| 767 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 768 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 769 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 770 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 771 | return; |
| 772 | } |
| 773 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 774 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 775 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 776 | if (appctx->ctx.table.data_type < 0) { |
| 777 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 778 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 779 | return; |
| 780 | } |
| 781 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 782 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 783 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 784 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 785 | return; |
| 786 | } |
| 787 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 788 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 789 | if (appctx->ctx.table.data_op < 0) { |
| 790 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 791 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 792 | return; |
| 793 | } |
| 794 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 795 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 796 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 797 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 798 | return; |
| 799 | } |
| 800 | } |
| 801 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 802 | 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] | 803 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 804 | struct appctx *appctx = __objt_appctx(si->end); |
| 805 | |
| 806 | appctx->ctx.table.data_type = -1; |
| 807 | appctx->st2 = STAT_ST_INIT; |
| 808 | appctx->ctx.table.target = NULL; |
| 809 | appctx->ctx.table.proxy = NULL; |
| 810 | appctx->ctx.table.entry = NULL; |
| 811 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 812 | |
| 813 | if (*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 814 | appctx->ctx.table.target = find_stktable(args[2]); |
| 815 | if (!appctx->ctx.table.target) { |
| 816 | appctx->ctx.cli.msg = "No such table\n"; |
| 817 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 818 | return; |
| 819 | } |
| 820 | } |
| 821 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 822 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 823 | goto err_args; |
| 824 | return; |
| 825 | } |
| 826 | |
| 827 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 828 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 829 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 830 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 831 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 832 | goto err_args; |
| 833 | |
| 834 | return; |
| 835 | |
| 836 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 837 | switch (action) { |
| 838 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 839 | 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] | 840 | break; |
| 841 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 842 | 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] | 843 | break; |
| 844 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 845 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 846 | break; |
| 847 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 848 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 849 | } |
| 850 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 851 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 852 | * adequate error messages and returns NULL. This function also expects the session |
| 853 | * level to be admin. |
| 854 | */ |
| 855 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 856 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 857 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 858 | struct proxy *px; |
| 859 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 860 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 861 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 862 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 863 | return NULL; |
| 864 | } |
| 865 | |
| 866 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 867 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 868 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 869 | return NULL; |
| 870 | } |
| 871 | |
| 872 | px = findproxy(arg, PR_CAP_FE); |
| 873 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 874 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 875 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 876 | return NULL; |
| 877 | } |
| 878 | return px; |
| 879 | } |
| 880 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 881 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 882 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 883 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 884 | * the <arg> is modified to remove the '/'. |
| 885 | */ |
| 886 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 887 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 888 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 889 | struct proxy *px; |
| 890 | struct server *sv; |
| 891 | char *line; |
| 892 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 893 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 894 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 895 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 896 | return NULL; |
| 897 | } |
| 898 | |
| 899 | /* split "backend/server" and make <line> point to server */ |
| 900 | for (line = arg; *line; line++) |
| 901 | if (*line == '/') { |
| 902 | *line++ = '\0'; |
| 903 | break; |
| 904 | } |
| 905 | |
| 906 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 907 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 908 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 909 | return NULL; |
| 910 | } |
| 911 | |
| 912 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 913 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 914 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 915 | return NULL; |
| 916 | } |
| 917 | |
| 918 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 919 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 920 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 921 | return NULL; |
| 922 | } |
| 923 | |
| 924 | return sv; |
| 925 | } |
| 926 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 927 | /* This function is used with map management. It permits to browse each |
| 928 | * really allocated descriptors of one map reference. The variable |
| 929 | * <appctx->ctx.map.ref> must contain the map reference to browse. |
| 930 | * The variable <appctx->ctx.map.desc> contain the descriptor of the |
| 931 | * current allocated map descriptor. This variable must be initialized |
| 932 | * to NULL. |
| 933 | */ |
| 934 | static inline void stats_map_lookup_next(struct stream_interface *si) |
| 935 | { |
| 936 | struct appctx *appctx = __objt_appctx(si->end); |
| 937 | |
| 938 | /* search the next allocated map */ |
| 939 | while (1) { |
| 940 | /* get next descriptor */ |
| 941 | if (!appctx->ctx.map.desc) |
| 942 | appctx->ctx.map.desc = LIST_NEXT(&appctx->ctx.map.ref->maps, |
| 943 | struct map_descriptor *, list); |
| 944 | else |
| 945 | appctx->ctx.map.desc = LIST_NEXT(&appctx->ctx.map.desc->list, |
| 946 | struct map_descriptor *, list); |
| 947 | |
| 948 | /* detect end of list */ |
| 949 | if (&appctx->ctx.map.desc->list == &appctx->ctx.map.ref->maps) { |
| 950 | appctx->ctx.map.desc = NULL; |
| 951 | return; |
| 952 | } |
| 953 | |
| 954 | /* do not lookup this entry */ |
| 955 | if (!appctx->ctx.map.desc->do_free) |
| 956 | continue; |
| 957 | |
| 958 | /* avalaible descriptor */ |
| 959 | return; |
| 960 | } |
| 961 | } |
| 962 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 963 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 964 | * 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] | 965 | * 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] | 966 | * designating the function which will have to process the request, which can |
| 967 | * 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] | 968 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 969 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 970 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 971 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 972 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 973 | char *args[MAX_STATS_ARGS + 1]; |
| 974 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 975 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 976 | |
| 977 | while (isspace((unsigned char)*line)) |
| 978 | line++; |
| 979 | |
| 980 | arg = 0; |
| 981 | args[arg] = line; |
| 982 | |
| 983 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 984 | if (*line == '\\') { |
| 985 | line++; |
| 986 | if (*line == '\0') |
| 987 | break; |
| 988 | } |
| 989 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 990 | *line++ = '\0'; |
| 991 | |
| 992 | while (isspace((unsigned char)*line)) |
| 993 | line++; |
| 994 | |
| 995 | args[++arg] = line; |
| 996 | continue; |
| 997 | } |
| 998 | |
| 999 | line++; |
| 1000 | } |
| 1001 | |
| 1002 | while (++arg <= MAX_STATS_ARGS) |
| 1003 | args[arg] = line; |
| 1004 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1005 | /* remove \ */ |
| 1006 | arg = 0; |
| 1007 | while (*args[arg] != '\0') { |
| 1008 | j = 0; |
| 1009 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1010 | if (args[arg][i] == '\\') |
| 1011 | continue; |
| 1012 | args[arg][j] = args[arg][i]; |
| 1013 | j++; |
| 1014 | } |
| 1015 | args[arg][j] = '\0'; |
| 1016 | arg++; |
| 1017 | } |
| 1018 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1019 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1020 | if (strcmp(args[0], "show") == 0) { |
| 1021 | if (strcmp(args[1], "stat") == 0) { |
| 1022 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1023 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1024 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1025 | appctx->ctx.stats.type = atoi(args[3]); |
| 1026 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1027 | } |
| 1028 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1029 | appctx->st2 = STAT_ST_INIT; |
| 1030 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1031 | } |
| 1032 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1033 | appctx->st2 = STAT_ST_INIT; |
| 1034 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1035 | } |
| 1036 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1037 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1038 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1039 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1040 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1041 | return 1; |
| 1042 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1043 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1044 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1045 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1046 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1047 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1048 | appctx->ctx.sess.target = NULL; |
| 1049 | appctx->ctx.sess.section = 0; /* start with session status */ |
| 1050 | appctx->ctx.sess.pos = 0; |
| 1051 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1052 | } |
| 1053 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1054 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1055 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1056 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1057 | return 1; |
| 1058 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1059 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1060 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1061 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1062 | appctx->ctx.errors.iid = -1; |
| 1063 | appctx->ctx.errors.px = NULL; |
| 1064 | appctx->st2 = STAT_ST_INIT; |
| 1065 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1066 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1067 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1068 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1069 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1070 | else if (strcmp(args[1], "map") == 0) { |
| 1071 | |
| 1072 | /* no parameter: display all map avalaible */ |
| 1073 | if (!*args[2]) { |
| 1074 | appctx->st2 = STAT_ST_INIT; |
| 1075 | appctx->st0 = STAT_CLI_O_MAPS; |
| 1076 | return 1; |
| 1077 | } |
| 1078 | |
| 1079 | /* lookup into the maps */ |
| 1080 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1081 | if (!appctx->ctx.map.ref) { |
| 1082 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1083 | appctx->st0 = STAT_CLI_PRINT; |
| 1084 | return 1; |
| 1085 | } |
| 1086 | appctx->st2 = STAT_ST_INIT; |
| 1087 | appctx->st0 = STAT_CLI_O_MAP; |
| 1088 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1089 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1090 | return 0; |
| 1091 | } |
| 1092 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1093 | else if (strcmp(args[0], "clear") == 0) { |
| 1094 | if (strcmp(args[1], "counters") == 0) { |
| 1095 | struct proxy *px; |
| 1096 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1097 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1098 | int clrall = 0; |
| 1099 | |
| 1100 | if (strcmp(args[2], "all") == 0) |
| 1101 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1102 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1103 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1104 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1105 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1106 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1107 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1108 | return 1; |
| 1109 | } |
| 1110 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1111 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1112 | if (clrall) { |
| 1113 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1114 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1115 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1116 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1117 | px->be_counters.conn_max = 0; |
| 1118 | px->be_counters.p.http.rps_max = 0; |
| 1119 | px->be_counters.sps_max = 0; |
| 1120 | px->be_counters.cps_max = 0; |
| 1121 | px->be_counters.nbpend_max = 0; |
| 1122 | |
| 1123 | px->fe_counters.conn_max = 0; |
| 1124 | px->fe_counters.p.http.rps_max = 0; |
| 1125 | px->fe_counters.sps_max = 0; |
| 1126 | px->fe_counters.cps_max = 0; |
| 1127 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1128 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1129 | |
| 1130 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1131 | if (clrall) |
| 1132 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1133 | else { |
| 1134 | sv->counters.cur_sess_max = 0; |
| 1135 | sv->counters.nbpend_max = 0; |
| 1136 | sv->counters.sps_max = 0; |
| 1137 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1138 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1139 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1140 | if (li->counters) { |
| 1141 | if (clrall) |
| 1142 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1143 | else |
| 1144 | li->counters->conn_max = 0; |
| 1145 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1146 | } |
| 1147 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1148 | global.cps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1149 | return 1; |
| 1150 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1151 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1152 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1153 | /* end of processing */ |
| 1154 | return 1; |
| 1155 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1156 | else if (strcmp(args[1], "map") == 0) { |
| 1157 | struct map_reference *mref; |
| 1158 | struct map_descriptor *mdesc; |
| 1159 | struct map_entry *ent, *nent; |
| 1160 | |
| 1161 | /* no parameter */ |
| 1162 | if (!*args[2]) { |
| 1163 | appctx->ctx.cli.msg = "Expect map reference.\n"; |
| 1164 | appctx->st0 = STAT_CLI_PRINT; |
| 1165 | return 1; |
| 1166 | } |
| 1167 | |
| 1168 | /* lookup into the maps */ |
| 1169 | mref = map_get_reference(args[2]); |
| 1170 | if (!mref) { |
| 1171 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1172 | appctx->st0 = STAT_CLI_PRINT; |
| 1173 | return 1; |
| 1174 | } |
| 1175 | |
| 1176 | /* clear all maps */ |
| 1177 | list_for_each_entry(mdesc, &mref->maps, list) |
| 1178 | if (mdesc->do_free) |
| 1179 | pattern_prune_expr(mdesc->pat); |
| 1180 | |
| 1181 | /* clear map reference */ |
| 1182 | list_for_each_entry_safe(ent, nent, &mref->entries, list) { |
| 1183 | LIST_DEL(&ent->list); |
| 1184 | free(ent->key); |
| 1185 | free(ent->value); |
| 1186 | free(ent); |
| 1187 | } |
| 1188 | |
| 1189 | /* return response */ |
| 1190 | appctx->ctx.cli.msg = "Done.\n"; |
| 1191 | appctx->st0 = STAT_CLI_PRINT; |
| 1192 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1193 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1194 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1195 | return 0; |
| 1196 | } |
| 1197 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1198 | else if (strcmp(args[0], "get") == 0) { |
| 1199 | if (strcmp(args[1], "weight") == 0) { |
| 1200 | struct proxy *px; |
| 1201 | struct server *sv; |
| 1202 | |
| 1203 | /* split "backend/server" and make <line> point to server */ |
| 1204 | for (line = args[2]; *line; line++) |
| 1205 | if (*line == '/') { |
| 1206 | *line++ = '\0'; |
| 1207 | break; |
| 1208 | } |
| 1209 | |
| 1210 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1211 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1212 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1213 | return 1; |
| 1214 | } |
| 1215 | |
| 1216 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1217 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1218 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1219 | return 1; |
| 1220 | } |
| 1221 | |
| 1222 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1223 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1224 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1225 | return 1; |
| 1226 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1227 | else if (strcmp(args[1], "map") == 0) { |
| 1228 | |
| 1229 | /* no parameter */ |
| 1230 | if (!*args[2] || !*args[3]) { |
| 1231 | appctx->ctx.cli.msg = "Expect map reference and required key.\n"; |
| 1232 | appctx->st0 = STAT_CLI_PRINT; |
| 1233 | return 1; |
| 1234 | } |
| 1235 | |
| 1236 | /* lookup into the maps */ |
| 1237 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1238 | if (!appctx->ctx.map.ref) { |
| 1239 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1240 | appctx->st0 = STAT_CLI_PRINT; |
| 1241 | return 1; |
| 1242 | } |
| 1243 | |
| 1244 | /* copy input string */ |
| 1245 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1246 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1247 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1248 | if (!appctx->ctx.map.chunk.str) { |
| 1249 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1250 | appctx->st0 = STAT_CLI_PRINT; |
| 1251 | return 1; |
| 1252 | } |
| 1253 | |
| 1254 | /* prepare response */ |
| 1255 | appctx->st2 = STAT_ST_INIT; |
| 1256 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1257 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1258 | else { /* not "get weight" */ |
| 1259 | return 0; |
| 1260 | } |
| 1261 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1262 | else if (strcmp(args[0], "set") == 0) { |
| 1263 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1264 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1265 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1266 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1267 | sv = expect_server_admin(s, si, args[2]); |
| 1268 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1269 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1270 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1271 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1272 | /* |
| 1273 | * The user-weight may now be zero and thus |
| 1274 | * the server considered to be draining. |
| 1275 | * Update the server's drain state as necessary. |
| 1276 | */ |
| 1277 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1278 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1279 | appctx->ctx.cli.msg = warning; |
| 1280 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1281 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1282 | return 1; |
| 1283 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1284 | else if (strcmp(args[1], "timeout") == 0) { |
| 1285 | if (strcmp(args[2], "cli") == 0) { |
| 1286 | unsigned timeout; |
| 1287 | const char *res; |
| 1288 | |
| 1289 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1290 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1291 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1292 | return 1; |
| 1293 | } |
| 1294 | |
| 1295 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1296 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1297 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1298 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1299 | return 1; |
| 1300 | } |
| 1301 | |
| 1302 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1303 | return 1; |
| 1304 | } |
| 1305 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1306 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1307 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1308 | return 1; |
| 1309 | } |
| 1310 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1311 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1312 | if (strcmp(args[2], "frontend") == 0) { |
| 1313 | struct proxy *px; |
| 1314 | struct listener *l; |
| 1315 | int v; |
| 1316 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1317 | px = expect_frontend_admin(s, si, args[3]); |
| 1318 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1319 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1320 | |
| 1321 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1322 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1323 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1324 | return 1; |
| 1325 | } |
| 1326 | |
| 1327 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1328 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1329 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1330 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1331 | return 1; |
| 1332 | } |
| 1333 | |
| 1334 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1335 | * its listeners. The blocked ones will be dequeued. |
| 1336 | */ |
| 1337 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1338 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1339 | l->maxconn = v; |
| 1340 | if (l->state == LI_FULL) |
| 1341 | resume_listener(l); |
| 1342 | } |
| 1343 | |
| 1344 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1345 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1346 | |
| 1347 | return 1; |
| 1348 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1349 | else if (strcmp(args[2], "global") == 0) { |
| 1350 | int v; |
| 1351 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1352 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1353 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1354 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1355 | return 1; |
| 1356 | } |
| 1357 | |
| 1358 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1359 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1360 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1361 | return 1; |
| 1362 | } |
| 1363 | |
| 1364 | v = atoi(args[3]); |
| 1365 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1366 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1367 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1368 | return 1; |
| 1369 | } |
| 1370 | |
| 1371 | /* check for unlimited values */ |
| 1372 | if (v <= 0) |
| 1373 | v = global.hardmaxconn; |
| 1374 | |
| 1375 | global.maxconn = v; |
| 1376 | |
| 1377 | /* Dequeues all of the listeners waiting for a resource */ |
| 1378 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1379 | dequeue_all_listeners(&global_listener_queue); |
| 1380 | |
| 1381 | return 1; |
| 1382 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1383 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1384 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1385 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1386 | return 1; |
| 1387 | } |
| 1388 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1389 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1390 | if (strcmp(args[2], "connections") == 0) { |
| 1391 | if (strcmp(args[3], "global") == 0) { |
| 1392 | int v; |
| 1393 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1394 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1395 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1396 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1397 | return 1; |
| 1398 | } |
| 1399 | |
| 1400 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1401 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1402 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1403 | return 1; |
| 1404 | } |
| 1405 | |
| 1406 | v = atoi(args[4]); |
| 1407 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1408 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1409 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1410 | return 1; |
| 1411 | } |
| 1412 | |
| 1413 | global.cps_lim = v; |
| 1414 | |
| 1415 | /* Dequeues all of the listeners waiting for a resource */ |
| 1416 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1417 | dequeue_all_listeners(&global_listener_queue); |
| 1418 | |
| 1419 | return 1; |
| 1420 | } |
| 1421 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1422 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1423 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1424 | return 1; |
| 1425 | } |
| 1426 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1427 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1428 | if (strcmp(args[3], "global") == 0) { |
| 1429 | int v; |
| 1430 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1431 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1432 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1433 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1434 | return 1; |
| 1435 | } |
| 1436 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1437 | v = atoi(args[4]); |
| 1438 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1439 | } |
| 1440 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1441 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1442 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1443 | return 1; |
| 1444 | } |
| 1445 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1446 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1447 | appctx->ctx.cli.msg = "'set rate-limit' supports 'connections' and 'http-compression'.\n"; |
| 1448 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1449 | return 1; |
| 1450 | } |
| 1451 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1452 | else if (strcmp(args[1], "table") == 0) { |
| 1453 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1454 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1455 | else if (strcmp(args[1], "map") == 0) { |
| 1456 | struct pattern *pat_elt; |
| 1457 | struct pat_idx_elt *idx_elt; |
Thierry FOURNIER | 410f810 | 2014-01-15 18:09:36 +0100 | [diff] [blame] | 1458 | char *value = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1459 | |
| 1460 | /* Expect three parameters: map name, key and new value. */ |
| 1461 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 1462 | appctx->ctx.cli.msg = "'set map' expect three parameters: map name, key and value.\n"; |
| 1463 | appctx->st0 = STAT_CLI_PRINT; |
| 1464 | return 1; |
| 1465 | } |
| 1466 | |
| 1467 | /* Lookup the reference in the maps. */ |
| 1468 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1469 | if (!appctx->ctx.map.ref) { |
| 1470 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1471 | appctx->st0 = STAT_CLI_PRINT; |
| 1472 | return 1; |
| 1473 | } |
| 1474 | |
| 1475 | /* Lookup the entry in the reference values. */ |
| 1476 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) |
| 1477 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) |
| 1478 | break; |
| 1479 | |
| 1480 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) { |
| 1481 | appctx->ctx.cli.msg = "Entry not found.\n"; |
| 1482 | appctx->st0 = STAT_CLI_PRINT; |
| 1483 | return 1; |
| 1484 | } |
| 1485 | |
| 1486 | /* Update each reference entries. */ |
| 1487 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) { |
| 1488 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) { |
| 1489 | value = strdup(args[4]); |
| 1490 | if (!value) { |
| 1491 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1492 | appctx->st0 = STAT_CLI_PRINT; |
| 1493 | return 1; |
| 1494 | } |
| 1495 | free(appctx->ctx.map.ent->value); |
| 1496 | appctx->ctx.map.ent->value = value; |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | /* Change the sample. The lookup juste return the first entry, other |
| 1501 | * entries are not changed, but are never matched. |
| 1502 | */ |
| 1503 | appctx->ctx.map.desc = NULL; |
| 1504 | for (stats_map_lookup_next(si); |
| 1505 | appctx->ctx.map.desc; |
| 1506 | stats_map_lookup_next(si)) { |
| 1507 | pattern_lookup(args[3], appctx->ctx.map.desc->pat, &pat_elt, &idx_elt, NULL); |
| 1508 | if (pat_elt != NULL) |
Thierry FOURNIER | 410f810 | 2014-01-15 18:09:36 +0100 | [diff] [blame] | 1509 | appctx->ctx.map.desc->parse(value, pat_elt->smp); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1510 | if (idx_elt != NULL) |
Thierry FOURNIER | 410f810 | 2014-01-15 18:09:36 +0100 | [diff] [blame] | 1511 | appctx->ctx.map.desc->parse(value, idx_elt->smp); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | /* The set is done, send message. */ |
| 1515 | appctx->ctx.cli.msg = "Done.\n"; |
| 1516 | appctx->st0 = STAT_CLI_PRINT; |
| 1517 | return 1; |
| 1518 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1519 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1520 | return 0; |
| 1521 | } |
| 1522 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1523 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1524 | if (strcmp(args[1], "agent") == 0) { |
| 1525 | struct server *sv; |
| 1526 | |
| 1527 | sv = expect_server_admin(s, si, args[2]); |
| 1528 | if (!sv) |
| 1529 | return 1; |
| 1530 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1531 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 1532 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 1533 | appctx->st0 = STAT_CLI_PRINT; |
| 1534 | return 1; |
| 1535 | } |
| 1536 | |
| 1537 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1538 | return 1; |
| 1539 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1540 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1541 | struct server *sv; |
| 1542 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1543 | sv = expect_server_admin(s, si, args[2]); |
| 1544 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1545 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1546 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1547 | if (sv->state & SRV_MAINTAIN) { |
| 1548 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1549 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1550 | /* If this server tracks the status of another one, |
| 1551 | * we must restore the good status. |
| 1552 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1553 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1554 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1555 | 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] | 1556 | } else { |
| 1557 | sv->state &= ~SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1558 | sv->check.state &= ~CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1559 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1560 | } |
| 1561 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1562 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1563 | 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] | 1564 | } |
| 1565 | } |
| 1566 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1567 | return 1; |
| 1568 | } |
| 1569 | else if (strcmp(args[1], "frontend") == 0) { |
| 1570 | struct proxy *px; |
| 1571 | |
| 1572 | px = expect_frontend_admin(s, si, args[2]); |
| 1573 | if (!px) |
| 1574 | return 1; |
| 1575 | |
| 1576 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1577 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1578 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1579 | return 1; |
| 1580 | } |
| 1581 | |
| 1582 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1583 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1584 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1585 | return 1; |
| 1586 | } |
| 1587 | |
| 1588 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1589 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1590 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1591 | return 1; |
| 1592 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1593 | return 1; |
| 1594 | } |
| 1595 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1596 | appctx->ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1597 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1598 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1599 | } |
| 1600 | } |
| 1601 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1602 | if (strcmp(args[1], "agent") == 0) { |
| 1603 | struct server *sv; |
| 1604 | |
| 1605 | sv = expect_server_admin(s, si, args[2]); |
| 1606 | if (!sv) |
| 1607 | return 1; |
| 1608 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 1609 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1610 | return 1; |
| 1611 | } |
| 1612 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1613 | struct server *sv; |
| 1614 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1615 | sv = expect_server_admin(s, si, args[2]); |
| 1616 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1617 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1618 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1619 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1620 | /* Not already in maintenance, we can change the server state */ |
| 1621 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 1622 | sv->check.state |= CHK_ST_PAUSED; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1623 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1624 | } |
| 1625 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1626 | return 1; |
| 1627 | } |
| 1628 | else if (strcmp(args[1], "frontend") == 0) { |
| 1629 | struct proxy *px; |
| 1630 | |
| 1631 | px = expect_frontend_admin(s, si, args[2]); |
| 1632 | if (!px) |
| 1633 | return 1; |
| 1634 | |
| 1635 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1636 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1637 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1638 | return 1; |
| 1639 | } |
| 1640 | |
| 1641 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1642 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1643 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1644 | return 1; |
| 1645 | } |
| 1646 | |
| 1647 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1648 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1649 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1650 | return 1; |
| 1651 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1652 | return 1; |
| 1653 | } |
| 1654 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1655 | appctx->ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1656 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1657 | return 1; |
| 1658 | } |
| 1659 | } |
| 1660 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1661 | if (strcmp(args[1], "frontend") == 0) { |
| 1662 | struct proxy *px; |
| 1663 | |
| 1664 | px = expect_frontend_admin(s, si, args[2]); |
| 1665 | if (!px) |
| 1666 | return 1; |
| 1667 | |
| 1668 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1669 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1670 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1671 | return 1; |
| 1672 | } |
| 1673 | |
| 1674 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1675 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1676 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1677 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1678 | stop_proxy(px); |
| 1679 | return 1; |
| 1680 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1681 | else if (strcmp(args[1], "session") == 0) { |
| 1682 | struct session *sess, *ptr; |
| 1683 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1684 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1685 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1686 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1687 | return 1; |
| 1688 | } |
| 1689 | |
| 1690 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1691 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1692 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1693 | return 1; |
| 1694 | } |
| 1695 | |
| 1696 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1697 | |
| 1698 | /* first, look for the requested session in the session table */ |
| 1699 | list_for_each_entry(sess, &sessions, list) { |
| 1700 | if (sess == ptr) |
| 1701 | break; |
| 1702 | } |
| 1703 | |
| 1704 | /* do we have the session ? */ |
| 1705 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1706 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1707 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1708 | return 1; |
| 1709 | } |
| 1710 | |
| 1711 | session_shutdown(sess, SN_ERR_KILLED); |
| 1712 | return 1; |
| 1713 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1714 | else if (strcmp(args[1], "sessions") == 0) { |
| 1715 | if (strcmp(args[2], "server") == 0) { |
| 1716 | struct server *sv; |
| 1717 | struct session *sess, *sess_bck; |
| 1718 | |
| 1719 | sv = expect_server_admin(s, si, args[3]); |
| 1720 | if (!sv) |
| 1721 | return 1; |
| 1722 | |
| 1723 | /* kill all the session that are on this server */ |
| 1724 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1725 | if (sess->srv_conn == sv) |
| 1726 | session_shutdown(sess, SN_ERR_KILLED); |
| 1727 | |
| 1728 | return 1; |
| 1729 | } |
| 1730 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1731 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1732 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1733 | return 1; |
| 1734 | } |
| 1735 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1736 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1737 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1738 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1739 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1740 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1741 | } |
| 1742 | else if (strcmp(args[0], "del") == 0) { |
| 1743 | if (strcmp(args[1], "map") == 0) { |
| 1744 | struct pattern *pat_elt; |
| 1745 | struct pat_idx_elt *idx_elt; |
| 1746 | struct map_entry *ent; |
| 1747 | |
| 1748 | /* Expect two parameters: map name and key. */ |
| 1749 | if (!*args[2] || !*args[3]) { |
| 1750 | appctx->ctx.cli.msg = "'del map' expect two parameters: map name and key.\n"; |
| 1751 | appctx->st0 = STAT_CLI_PRINT; |
| 1752 | return 1; |
| 1753 | } |
| 1754 | |
| 1755 | /* Lookup the reference in the maps. */ |
| 1756 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1757 | if (!appctx->ctx.map.ref) { |
| 1758 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1759 | appctx->st0 = STAT_CLI_PRINT; |
| 1760 | return 1; |
| 1761 | } |
| 1762 | |
| 1763 | /* Lookup the entry in the reference values. |
| 1764 | * If the entry is not found in the reference, return error message. |
| 1765 | */ |
| 1766 | list_for_each_entry(appctx->ctx.map.ent, &appctx->ctx.map.ref->entries, list) |
| 1767 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) |
| 1768 | break; |
| 1769 | |
| 1770 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) { |
| 1771 | appctx->ctx.cli.msg = "Entry not found.\n"; |
| 1772 | appctx->st0 = STAT_CLI_PRINT; |
| 1773 | return 1; |
| 1774 | } |
| 1775 | |
| 1776 | /* Delete each enties from reference. */ |
| 1777 | list_for_each_entry_safe(appctx->ctx.map.ent, ent, &appctx->ctx.map.ref->entries, list) { |
| 1778 | if (strcmp(args[3], appctx->ctx.map.ent->key) == 0) { |
| 1779 | LIST_DEL(&appctx->ctx.map.ent->list); |
| 1780 | free(appctx->ctx.map.ent->key); |
| 1781 | free(appctx->ctx.map.ent->value); |
| 1782 | free(appctx->ctx.map.ent); |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | /* Delete all matching entries for each map descritor. */ |
| 1787 | appctx->ctx.map.desc = NULL; |
| 1788 | stats_map_lookup_next(si); |
| 1789 | while (appctx->ctx.map.desc) { |
| 1790 | while (pattern_lookup(args[3], appctx->ctx.map.desc->pat, &pat_elt, &idx_elt, NULL)) { |
| 1791 | if (pat_elt != NULL) { |
| 1792 | LIST_DEL(&pat_elt->list); |
| 1793 | pattern_free(pat_elt); |
| 1794 | } |
| 1795 | if (idx_elt != NULL) { |
| 1796 | ebmb_delete(&idx_elt->node); |
| 1797 | free(idx_elt); |
| 1798 | } |
| 1799 | } |
| 1800 | stats_map_lookup_next(si); |
| 1801 | } |
| 1802 | |
| 1803 | /* The deletion is done, send message. */ |
| 1804 | appctx->ctx.cli.msg = "Done.\n"; |
| 1805 | appctx->st0 = STAT_CLI_PRINT; |
| 1806 | return 1; |
| 1807 | } |
| 1808 | else { /* unknown "del" parameter */ |
| 1809 | appctx->ctx.cli.msg = "'del' only supports 'map'.\n"; |
| 1810 | appctx->st0 = STAT_CLI_PRINT; |
| 1811 | return 1; |
| 1812 | } |
| 1813 | } |
| 1814 | else if (strcmp(args[0], "add") == 0) { |
| 1815 | if (strcmp(args[1], "map") == 0) { |
| 1816 | const char *params[2]; |
| 1817 | struct pattern *pat; |
| 1818 | struct map_entry *ent; |
| 1819 | struct sample_storage *smp; |
| 1820 | |
| 1821 | /* Expect three parameters: map name, key and new value. */ |
| 1822 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 1823 | appctx->ctx.cli.msg = "'add map' expect three parameters: map name, key and value.\n"; |
| 1824 | appctx->st0 = STAT_CLI_PRINT; |
| 1825 | return 1; |
| 1826 | } |
| 1827 | |
| 1828 | params[0] = args[3]; |
| 1829 | params[1] = ""; |
| 1830 | |
| 1831 | /* Lookup the reference in the maps. */ |
| 1832 | appctx->ctx.map.ref = map_get_reference(args[2]); |
| 1833 | if (!appctx->ctx.map.ref) { |
| 1834 | appctx->ctx.cli.msg = "Unknown map reference.\n"; |
| 1835 | appctx->st0 = STAT_CLI_PRINT; |
| 1836 | return 1; |
| 1837 | } |
| 1838 | |
| 1839 | /* Prepare and link the new map_entry element. If out of memory |
| 1840 | * error the action is cancelled and the descriptor are left |
| 1841 | * coherents. |
| 1842 | */ |
| 1843 | ent = malloc(sizeof(*ent)); |
| 1844 | if (!ent) { |
| 1845 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1846 | appctx->st0 = STAT_CLI_PRINT; |
| 1847 | return 1; |
| 1848 | } |
| 1849 | ent->key = strdup(args[3]); |
| 1850 | if (!ent->key) { |
| 1851 | free(ent); |
| 1852 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1853 | appctx->st0 = STAT_CLI_PRINT; |
| 1854 | return 1; |
| 1855 | } |
| 1856 | ent->value = strdup(args[4]); |
| 1857 | if (!ent->value) { |
| 1858 | free(ent->key); |
| 1859 | free(ent); |
| 1860 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1861 | appctx->st0 = STAT_CLI_PRINT; |
| 1862 | return 1; |
| 1863 | } |
| 1864 | LIST_ADDQ(&appctx->ctx.map.ref->entries, &ent->list); |
| 1865 | |
| 1866 | /* Browse each map descritor and try to insert this new value. */ |
| 1867 | appctx->ctx.map.desc = NULL; |
| 1868 | for (stats_map_lookup_next(si); |
| 1869 | appctx->ctx.map.desc; |
| 1870 | stats_map_lookup_next(si)) { |
| 1871 | |
| 1872 | /* Create new sample. Return out of memory error |
| 1873 | * if the memory cannot be allocated. The 'add' process |
| 1874 | * is aborted, but the already inserted entries are not |
| 1875 | * deleted. |
| 1876 | */ |
| 1877 | smp = calloc(1, sizeof(*smp)); |
| 1878 | if (!smp) { |
| 1879 | appctx->ctx.cli.msg = "Out of memory error. The value is not added in all maps.\n"; |
| 1880 | appctx->st0 = STAT_CLI_PRINT; |
| 1881 | return 1; |
| 1882 | } |
| 1883 | |
| 1884 | /* Create sample. If this function fails, the insertion |
| 1885 | * is canceled for this 'descriptor', but continue, for |
| 1886 | * the other descriptors. |
| 1887 | */ |
| 1888 | if (!appctx->ctx.map.desc->parse(ent->value, smp)) { |
| 1889 | free(smp); |
| 1890 | continue; |
| 1891 | } |
| 1892 | |
| 1893 | /* If the value can be indexed, get the first pattern. If |
| 1894 | * the return entry is not the indexed entry, new 'pattern' is |
| 1895 | * created by the function pattern_register(). If the 'pattern' |
| 1896 | * is NULL, new entry is created. This is ugly because the |
| 1897 | * following code interfers with the own code of the function |
| 1898 | * pattern_register(). |
| 1899 | */ |
| 1900 | if (appctx->ctx.map.desc->pat->match == pat_match_str || |
| 1901 | appctx->ctx.map.desc->pat->match == pat_match_ip) { |
| 1902 | pat = LIST_NEXT(&appctx->ctx.map.desc->pat->patterns, struct pattern *, list); |
| 1903 | if (&pat->list == &appctx->ctx.map.desc->pat->patterns) |
| 1904 | pat = NULL; |
| 1905 | } |
| 1906 | else |
| 1907 | pat = NULL; |
| 1908 | |
| 1909 | if (!pattern_register(appctx->ctx.map.desc->pat, params, smp, &pat, 0, NULL)) { |
| 1910 | free(smp); |
| 1911 | continue; |
| 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | /* The add is done, send message. */ |
| 1916 | appctx->ctx.cli.msg = "Done.\n"; |
| 1917 | appctx->st0 = STAT_CLI_PRINT; |
| 1918 | return 1; |
| 1919 | } |
| 1920 | else { /* unknown "del" parameter */ |
| 1921 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 1922 | appctx->st0 = STAT_CLI_PRINT; |
| 1923 | return 1; |
| 1924 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1925 | } |
| 1926 | 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] | 1927 | return 0; |
| 1928 | } |
| 1929 | return 1; |
| 1930 | } |
| 1931 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1932 | /* 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] | 1933 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 1934 | * state machine handling requests and various responses. We read a request, |
| 1935 | * 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] | 1936 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 1937 | * 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] | 1938 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1939 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 1940 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1941 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1942 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1943 | struct channel *req = si->ob; |
| 1944 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1945 | int reql; |
| 1946 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1947 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1948 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 1949 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1950 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1951 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1952 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1953 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1954 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 1955 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1956 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1957 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1958 | /* Let's close for real now. We just close the request |
| 1959 | * side, the conditions below will complete if needed. |
| 1960 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1961 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1962 | break; |
| 1963 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1964 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1965 | /* ensure we have some output room left in the event we |
| 1966 | * would want to return some info right after parsing. |
| 1967 | */ |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 1968 | if (buffer_almost_full(si->ib->buf)) { |
| 1969 | si->ib->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1970 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 1971 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1972 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1973 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1974 | if (reql <= 0) { /* closed or EOL not found */ |
| 1975 | if (reql == 0) |
| 1976 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1977 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1978 | continue; |
| 1979 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1980 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1981 | /* seek for a possible semi-colon. If we find one, we |
| 1982 | * replace it with an LF and skip only this part. |
| 1983 | */ |
| 1984 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1985 | if (trash.str[len] == ';') { |
| 1986 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1987 | reql = len + 1; |
| 1988 | break; |
| 1989 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1990 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1991 | /* now it is time to check that we have a full line, |
| 1992 | * remove the trailing \n and possibly \r, then cut the |
| 1993 | * line. |
| 1994 | */ |
| 1995 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1996 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1997 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1998 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1999 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2000 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2001 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2002 | len--; |
| 2003 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2004 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2005 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2006 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2007 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2008 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2009 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2010 | continue; |
| 2011 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2012 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2013 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2014 | else if (strcmp(trash.str, "help") == 0 || |
| 2015 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2016 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2017 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2018 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2019 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2020 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2021 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2022 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2023 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2024 | /* if prompt is disabled, print help on empty lines, |
| 2025 | * so that the user at least knows how to enable |
| 2026 | * prompt and find help. |
| 2027 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2028 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2029 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 2033 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2034 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2035 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2036 | 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] | 2037 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2038 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2039 | continue; |
| 2040 | } |
| 2041 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2042 | switch (appctx->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2043 | case STAT_CLI_PRINT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2044 | if (bi_putstr(si->ib, appctx->ctx.cli.msg) != -1) |
| 2045 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2046 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2047 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2048 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2049 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2050 | break; |
| 2051 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2052 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2053 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2054 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2055 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2056 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2057 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2058 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2059 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2060 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2061 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2062 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2063 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2064 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2065 | if (stats_table_request(si, appctx->st0)) |
| 2066 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2067 | break; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2068 | case STAT_CLI_O_MAPS: |
| 2069 | if (stats_maps_list(si)) |
| 2070 | appctx->st0 = STAT_CLI_PROMPT; |
| 2071 | break; |
| 2072 | case STAT_CLI_O_MAP: |
| 2073 | if (stats_map_list(si)) |
| 2074 | appctx->st0 = STAT_CLI_PROMPT; |
| 2075 | break; |
| 2076 | case STAT_CLI_O_MLOOK: |
| 2077 | if (stats_map_lookup(si)) |
| 2078 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2079 | default: /* abnormal state */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2080 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2081 | break; |
| 2082 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2083 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2084 | /* 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] | 2085 | if (appctx->st0 == STAT_CLI_PROMPT) { |
| 2086 | if (bi_putstr(si->ib, appctx->st1 ? "\n> " : "\n") != -1) |
| 2087 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2088 | } |
| 2089 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2090 | /* 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] | 2091 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2092 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2093 | |
| 2094 | /* Now we close the output if one of the writers did so, |
| 2095 | * or if we're not in interactive mode and the request |
| 2096 | * buffer is empty. This still allows pipelined requests |
| 2097 | * to be sent in non-interactive mode. |
| 2098 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2099 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2100 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2101 | continue; |
| 2102 | } |
| 2103 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2104 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2105 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2106 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2107 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2108 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2109 | 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] | 2110 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2111 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2112 | /* 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] | 2113 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2114 | * we forward the close to the request side so that it flows upstream to |
| 2115 | * the client. |
| 2116 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2117 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2118 | } |
| 2119 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2120 | 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] | 2121 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2122 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2123 | /* We have no more processing to do, and nothing more to send, and |
| 2124 | * the client side has closed. So we'll forward this state downstream |
| 2125 | * on the response buffer. |
| 2126 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2127 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2128 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2132 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2133 | |
| 2134 | /* we don't want to expire timeouts while we're processing requests */ |
| 2135 | si->ib->rex = TICK_ETERNITY; |
| 2136 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2137 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2138 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2139 | 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] | 2140 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2141 | 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] | 2142 | |
| 2143 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 2144 | /* check that we have released everything then unregister */ |
| 2145 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2146 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2147 | } |
| 2148 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2149 | /* This function dumps information onto the stream interface's read buffer. |
| 2150 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2151 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2152 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2153 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2154 | { |
| 2155 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2156 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2157 | chunk_printf(&trash, |
| 2158 | "Name: " PRODUCT_NAME "\n" |
| 2159 | "Version: " HAPROXY_VERSION "\n" |
| 2160 | "Release_date: " HAPROXY_DATE "\n" |
| 2161 | "Nbproc: %d\n" |
| 2162 | "Process_num: %d\n" |
| 2163 | "Pid: %d\n" |
| 2164 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2165 | "Uptime_sec: %d\n" |
| 2166 | "Memmax_MB: %d\n" |
| 2167 | "Ulimit-n: %d\n" |
| 2168 | "Maxsock: %d\n" |
| 2169 | "Maxconn: %d\n" |
| 2170 | "Hard_maxconn: %d\n" |
| 2171 | "Maxpipes: %d\n" |
| 2172 | "CurrConns: %d\n" |
| 2173 | "PipesUsed: %d\n" |
| 2174 | "PipesFree: %d\n" |
| 2175 | "ConnRate: %d\n" |
| 2176 | "ConnRateLimit: %d\n" |
| 2177 | "MaxConnRate: %d\n" |
| 2178 | "CompressBpsIn: %u\n" |
| 2179 | "CompressBpsOut: %u\n" |
| 2180 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2181 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2182 | "ZlibMemUsage: %ld\n" |
| 2183 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2184 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2185 | "Tasks: %d\n" |
| 2186 | "Run_queue: %d\n" |
| 2187 | "Idle_pct: %d\n" |
| 2188 | "node: %s\n" |
| 2189 | "description: %s\n" |
| 2190 | "", |
| 2191 | global.nbproc, |
| 2192 | relative_pid, |
| 2193 | pid, |
| 2194 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2195 | up, |
| 2196 | global.rlimit_memmax, |
| 2197 | global.rlimit_nofile, |
| 2198 | global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes, |
| 2199 | actconn, pipes_used, pipes_free, |
| 2200 | read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max, |
| 2201 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2202 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2203 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2204 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2205 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2206 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 2207 | global.node, global.desc ? global.desc : "" |
| 2208 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2209 | |
| 2210 | if (bi_putchk(si->ib, &trash) == -1) |
| 2211 | return 0; |
| 2212 | |
| 2213 | return 1; |
| 2214 | } |
| 2215 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2216 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 2217 | * the state from stream interface <si>. The caller is responsible for clearing |
| 2218 | * 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] | 2219 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2220 | 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] | 2221 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2222 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2223 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2224 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2225 | if (!(px->cap & PR_CAP_FE)) |
| 2226 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2227 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2228 | 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] | 2229 | return 0; |
| 2230 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2231 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2232 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2233 | /* name, queue */ |
| 2234 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2235 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2236 | 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] | 2237 | /* Column sub-heading for Enable or Disable server */ |
| 2238 | chunk_appendf(&trash, "<td></td>"); |
| 2239 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2240 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2241 | chunk_appendf(&trash, |
| 2242 | "<td class=ac>" |
| 2243 | "<a name=\"%s/Frontend\"></a>" |
| 2244 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2245 | "<td colspan=3></td>" |
| 2246 | "", |
| 2247 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2248 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2249 | chunk_appendf(&trash, |
| 2250 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2251 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2252 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 2253 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 2254 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2255 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 2256 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 2257 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2258 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2259 | if (px->mode == PR_MODE_HTTP) |
| 2260 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2261 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2262 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2263 | |
| 2264 | chunk_appendf(&trash, |
| 2265 | "</table></div></u></td>" |
| 2266 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2267 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2268 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 2269 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 2270 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2271 | U2H(px->fe_counters.sps_max), |
| 2272 | U2H(px->fe_counters.cps_max), |
| 2273 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2274 | |
| 2275 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2276 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2277 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2278 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2279 | |
| 2280 | chunk_appendf(&trash, |
| 2281 | "</table></div></u></td>" |
| 2282 | /* sessions rate : limit */ |
| 2283 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2284 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2285 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2286 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2287 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2288 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2289 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2290 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 2291 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2292 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2293 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 2294 | U2H(px->fe_counters.cum_sess), |
| 2295 | U2H(px->fe_counters.cum_conn), |
| 2296 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2297 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2298 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2299 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2300 | chunk_appendf(&trash, |
| 2301 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2302 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2303 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2304 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2305 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2306 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2307 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2308 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2309 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2310 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2311 | U2H(px->fe_counters.p.http.cum_req), |
| 2312 | U2H(px->fe_counters.p.http.rsp[1]), |
| 2313 | U2H(px->fe_counters.p.http.rsp[2]), |
| 2314 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2315 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2316 | (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] | 2317 | U2H(px->fe_counters.p.http.rsp[3]), |
| 2318 | U2H(px->fe_counters.p.http.rsp[4]), |
| 2319 | U2H(px->fe_counters.p.http.rsp[5]), |
| 2320 | U2H(px->fe_counters.p.http.rsp[0]), |
| 2321 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2322 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2323 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2324 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2325 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2326 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2327 | "<td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2328 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2329 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2330 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2331 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2332 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2333 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2334 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2335 | "<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] | 2336 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2337 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2338 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2339 | px->fe_counters.comp_in ? |
| 2340 | (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] | 2341 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2342 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2343 | chunk_appendf(&trash, |
| 2344 | /* denied: req, resp */ |
| 2345 | "<td>%s</td><td>%s</td>" |
| 2346 | /* errors : request, connect, response */ |
| 2347 | "<td>%s</td><td></td><td></td>" |
| 2348 | /* warnings: retries, redispatches */ |
| 2349 | "<td></td><td></td>" |
| 2350 | /* server status : reflect frontend status */ |
| 2351 | "<td class=ac>%s</td>" |
| 2352 | /* rest of server: nothing */ |
| 2353 | "<td class=ac colspan=8></td></tr>" |
| 2354 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2355 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 2356 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2357 | px->state == PR_STREADY ? "OPEN" : |
| 2358 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2359 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2360 | else { /* CSV mode */ |
| 2361 | chunk_appendf(&trash, |
| 2362 | /* pxid, name, queue cur, queue max, */ |
| 2363 | "%s,FRONTEND,,," |
| 2364 | /* sessions : current, max, limit, total */ |
| 2365 | "%d,%d,%d,%lld," |
| 2366 | /* bytes : in, out */ |
| 2367 | "%lld,%lld," |
| 2368 | /* denied: req, resp */ |
| 2369 | "%lld,%lld," |
| 2370 | /* errors : request, connect, response */ |
| 2371 | "%lld,,," |
| 2372 | /* warnings: retries, redispatches */ |
| 2373 | ",," |
| 2374 | /* server status : reflect frontend status */ |
| 2375 | "%s," |
| 2376 | /* rest of server: nothing */ |
| 2377 | ",,,,,,,," |
| 2378 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2379 | "%d,%d,0,,,,%d," |
| 2380 | /* rate, rate_lim, rate_max */ |
| 2381 | "%u,%u,%u," |
| 2382 | /* check_status, check_code, check_duration */ |
| 2383 | ",,,", |
| 2384 | px->id, |
| 2385 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2386 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2387 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2388 | px->fe_counters.failed_req, |
| 2389 | px->state == PR_STREADY ? "OPEN" : |
| 2390 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 2391 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 2392 | read_freq_ctr(&px->fe_sess_per_sec), |
| 2393 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2394 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2395 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2396 | if (px->mode == PR_MODE_HTTP) { |
| 2397 | for (i=1; i<6; i++) |
| 2398 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 2399 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 2400 | } |
| 2401 | else |
| 2402 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2403 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2404 | /* failed health analyses */ |
| 2405 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2406 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2407 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2408 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 2409 | read_freq_ctr(&px->fe_req_per_sec), |
| 2410 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 2411 | |
| 2412 | /* errors: cli_aborts, srv_aborts */ |
| 2413 | chunk_appendf(&trash, ",,"); |
| 2414 | |
| 2415 | /* compression: in, out, bypassed */ |
| 2416 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2417 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2418 | |
| 2419 | /* compression: comp_rsp */ |
| 2420 | chunk_appendf(&trash, "%lld,", |
| 2421 | px->fe_counters.p.http.comp_rsp); |
| 2422 | |
| 2423 | /* finish with EOL */ |
| 2424 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2425 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2426 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2427 | } |
| 2428 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2429 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2430 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2431 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2432 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2433 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2434 | 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] | 2435 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2436 | struct appctx *appctx = __objt_appctx(si->end); |
| 2437 | |
| 2438 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2439 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2440 | 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] | 2441 | /* Column sub-heading for Enable or Disable server */ |
| 2442 | chunk_appendf(&trash, "<td></td>"); |
| 2443 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2444 | chunk_appendf(&trash, |
| 2445 | /* frontend name, listener name */ |
| 2446 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2447 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2448 | "", |
| 2449 | px->id, l->name, |
| 2450 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2451 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2452 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2453 | if (flags & ST_SHLGNDS) { |
| 2454 | char str[INET6_ADDRSTRLEN]; |
| 2455 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2456 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2457 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2458 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2459 | port = get_host_port(&l->addr); |
| 2460 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2461 | case AF_INET: |
| 2462 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2463 | break; |
| 2464 | case AF_INET6: |
| 2465 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2466 | break; |
| 2467 | case AF_UNIX: |
| 2468 | chunk_appendf(&trash, "unix, "); |
| 2469 | break; |
| 2470 | case -1: |
| 2471 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2472 | break; |
| 2473 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2474 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2475 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2476 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2477 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2478 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2479 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2480 | /* queue */ |
| 2481 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2482 | /* sessions rate: current, max, limit */ |
| 2483 | "<td colspan=3> </td>" |
| 2484 | /* sessions: current, max, limit, total, lbtot */ |
| 2485 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2486 | "<td>%s</td><td> </td>" |
| 2487 | /* bytes: in, out */ |
| 2488 | "<td>%s</td><td>%s</td>" |
| 2489 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2490 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2491 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2492 | 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] | 2493 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2494 | chunk_appendf(&trash, |
| 2495 | /* denied: req, resp */ |
| 2496 | "<td>%s</td><td>%s</td>" |
| 2497 | /* errors: request, connect, response */ |
| 2498 | "<td>%s</td><td></td><td></td>" |
| 2499 | /* warnings: retries, redispatches */ |
| 2500 | "<td></td><td></td>" |
| 2501 | /* server status: reflect listener status */ |
| 2502 | "<td class=ac>%s</td>" |
| 2503 | /* rest of server: nothing */ |
| 2504 | "<td class=ac colspan=8></td></tr>" |
| 2505 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2506 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2507 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2508 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2509 | } |
| 2510 | else { /* CSV mode */ |
| 2511 | chunk_appendf(&trash, |
| 2512 | /* pxid, name, queue cur, queue max, */ |
| 2513 | "%s,%s,,," |
| 2514 | /* sessions: current, max, limit, total */ |
| 2515 | "%d,%d,%d,%lld," |
| 2516 | /* bytes: in, out */ |
| 2517 | "%lld,%lld," |
| 2518 | /* denied: req, resp */ |
| 2519 | "%lld,%lld," |
| 2520 | /* errors: request, connect, response */ |
| 2521 | "%lld,,," |
| 2522 | /* warnings: retries, redispatches */ |
| 2523 | ",," |
| 2524 | /* server status: reflect listener status */ |
| 2525 | "%s," |
| 2526 | /* rest of server: nothing */ |
| 2527 | ",,,,,,,," |
| 2528 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2529 | "%d,%d,%d,,,,%d," |
| 2530 | /* rate, rate_lim, rate_max */ |
| 2531 | ",,," |
| 2532 | /* check_status, check_code, check_duration */ |
| 2533 | ",,," |
| 2534 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2535 | ",,,,,," |
| 2536 | /* failed health analyses */ |
| 2537 | "," |
| 2538 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2539 | ",,," |
| 2540 | /* errors: cli_aborts, srv_aborts */ |
| 2541 | ",," |
| 2542 | /* compression: in, out, bypassed, comp_rsp */ |
| 2543 | ",,,," |
| 2544 | "\n", |
| 2545 | px->id, l->name, |
| 2546 | l->nbconn, l->counters->conn_max, |
| 2547 | l->maxconn, l->counters->cum_conn, |
| 2548 | l->counters->bytes_in, l->counters->bytes_out, |
| 2549 | l->counters->denied_req, l->counters->denied_resp, |
| 2550 | l->counters->failed_req, |
| 2551 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2552 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2553 | } |
| 2554 | return 1; |
| 2555 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2556 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2557 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2558 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2559 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2560 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2561 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2562 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2563 | */ |
| 2564 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2565 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2566 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2567 | struct server *ref = sv->track ? sv->track : sv; |
| 2568 | char str[INET6_ADDRSTRLEN]; |
| 2569 | struct chunk src; |
| 2570 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2571 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2572 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2573 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2574 | "DOWN", |
| 2575 | "DN %d/%d ↑", |
| 2576 | "UP %d/%d ↓", |
| 2577 | "UP", |
| 2578 | "NOLB %d/%d ↓", |
| 2579 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2580 | "DRAIN %d/%d ↓", |
| 2581 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2582 | "<i>no check</i>" |
| 2583 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2584 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2585 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2586 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2587 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2588 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2589 | "<tr class=\"%s%d\">", |
| 2590 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2591 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2592 | 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] | 2593 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2594 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2595 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2596 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2597 | chunk_appendf(&trash, |
| 2598 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2599 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2600 | "", |
| 2601 | px->id, sv->id, |
| 2602 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2603 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2604 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2605 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2606 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2607 | |
| 2608 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2609 | case AF_INET: |
| 2610 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2611 | break; |
| 2612 | case AF_INET6: |
| 2613 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2614 | break; |
| 2615 | case AF_UNIX: |
| 2616 | chunk_appendf(&trash, "unix, "); |
| 2617 | break; |
| 2618 | case -1: |
| 2619 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2620 | break; |
| 2621 | default: /* address family not supported */ |
| 2622 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2623 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2624 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2625 | /* id */ |
| 2626 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2627 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2628 | /* cookie */ |
| 2629 | if (sv->cookie) { |
| 2630 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2631 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2632 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2633 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2634 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2635 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2636 | } |
| 2637 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2638 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2639 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2640 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2641 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2642 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2643 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2644 | /* sessions rate : current, max, limit */ |
| 2645 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2646 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2647 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2648 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2649 | 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] | 2650 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2651 | |
| 2652 | chunk_appendf(&trash, |
| 2653 | /* sessions: current, max, limit, total */ |
| 2654 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2655 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2656 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2657 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2658 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2659 | U2H(sv->counters.cum_sess), |
| 2660 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2661 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2662 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2663 | if (px->mode == PR_MODE_HTTP) { |
| 2664 | unsigned long long tot; |
| 2665 | for (tot = i = 0; i < 6; i++) |
| 2666 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2667 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2668 | chunk_appendf(&trash, |
| 2669 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2670 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2671 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2672 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2673 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2674 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2675 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2676 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2677 | U2H(tot), |
| 2678 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2679 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2680 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2681 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2682 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2683 | 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] | 2684 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2685 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2686 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2687 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2688 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2689 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2690 | U2H(sv->counters.cum_lbconn)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2691 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2692 | chunk_appendf(&trash, |
| 2693 | /* bytes : in, out */ |
| 2694 | "<td>%s</td><td>%s</td>" |
| 2695 | /* denied: req, resp */ |
| 2696 | "<td></td><td>%s</td>" |
| 2697 | /* errors : request, connect */ |
| 2698 | "<td></td><td>%s</td>" |
| 2699 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2700 | "<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] | 2701 | /* warnings: retries, redispatches */ |
| 2702 | "<td>%lld</td><td>%lld</td>" |
| 2703 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2704 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2705 | U2H(sv->counters.failed_secu), |
| 2706 | U2H(sv->counters.failed_conns), |
| 2707 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2708 | sv->counters.cli_aborts, |
| 2709 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2710 | sv->counters.retries, sv->counters.redispatches); |
| 2711 | |
| 2712 | /* status, lest check */ |
| 2713 | chunk_appendf(&trash, "<td class=ac>"); |
| 2714 | |
| 2715 | if (sv->state & SRV_MAINTAIN) { |
| 2716 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2717 | chunk_appendf(&trash, "MAINT"); |
| 2718 | } |
| 2719 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2720 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2721 | chunk_appendf(&trash, "MAINT(via)"); |
| 2722 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2723 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2724 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2725 | chunk_appendf(&trash, |
| 2726 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2727 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2728 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2729 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2730 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2731 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2732 | chunk_appendf(&trash, |
| 2733 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 2734 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2735 | get_check_status_info(sv->check.status)); |
| 2736 | |
| 2737 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2738 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2739 | |
| 2740 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2741 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2742 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2743 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2744 | get_check_status_description(sv->check.status)); |
| 2745 | if (*sv->check.desc) { |
| 2746 | chunk_appendf(&trash, ": "); |
| 2747 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2748 | chunk_htmlencode(&trash, &src); |
| 2749 | } |
| 2750 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2751 | } |
| 2752 | else |
| 2753 | chunk_appendf(&trash, "</td><td>"); |
| 2754 | |
| 2755 | chunk_appendf(&trash, |
| 2756 | /* weight */ |
| 2757 | "</td><td class=ac>%d</td>" |
| 2758 | /* act, bck */ |
| 2759 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2760 | "", |
| 2761 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2762 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2763 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2764 | |
| 2765 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2766 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2767 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2768 | |
| 2769 | if (ref->observe) |
| 2770 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2771 | |
| 2772 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2773 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2774 | "<td>%lld</td><td>%s</td>" |
| 2775 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2776 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2777 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2778 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2779 | else if (sv != ref) { |
| 2780 | if (sv->state & SRV_MAINTAIN) |
| 2781 | chunk_appendf(&trash, |
| 2782 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2783 | ref->proxy->id, ref->id); |
| 2784 | else |
| 2785 | chunk_appendf(&trash, |
| 2786 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2787 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2788 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2789 | else |
| 2790 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2791 | |
| 2792 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2793 | if (sv->state & SRV_WARMINGUP) |
| 2794 | 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] | 2795 | else |
| 2796 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2797 | } |
| 2798 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2799 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2800 | "DOWN,", |
| 2801 | "DOWN %d/%d,", |
| 2802 | "UP %d/%d,", |
| 2803 | "UP,", |
| 2804 | "NOLB %d/%d,", |
| 2805 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2806 | "DRAIN %d/%d,", |
| 2807 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2808 | "no check," |
| 2809 | }; |
| 2810 | |
| 2811 | chunk_appendf(&trash, |
| 2812 | /* pxid, name */ |
| 2813 | "%s,%s," |
| 2814 | /* queue : current, max */ |
| 2815 | "%d,%d," |
| 2816 | /* sessions : current, max, limit, total */ |
| 2817 | "%d,%d,%s,%lld," |
| 2818 | /* bytes : in, out */ |
| 2819 | "%lld,%lld," |
| 2820 | /* denied: req, resp */ |
| 2821 | ",%lld," |
| 2822 | /* errors : request, connect, response */ |
| 2823 | ",%lld,%lld," |
| 2824 | /* warnings: retries, redispatches */ |
| 2825 | "%lld,%lld," |
| 2826 | "", |
| 2827 | px->id, sv->id, |
| 2828 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2829 | 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] | 2830 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2831 | sv->counters.failed_secu, |
| 2832 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2833 | sv->counters.retries, sv->counters.redispatches); |
| 2834 | |
| 2835 | /* status */ |
| 2836 | if (sv->state & SRV_MAINTAIN) |
| 2837 | chunk_appendf(&trash, "MAINT,"); |
| 2838 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2839 | chunk_appendf(&trash, "MAINT(via),"); |
| 2840 | else |
| 2841 | chunk_appendf(&trash, |
| 2842 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2843 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2844 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2845 | |
| 2846 | chunk_appendf(&trash, |
| 2847 | /* weight, active, backup */ |
| 2848 | "%d,%d,%d," |
| 2849 | "", |
| 2850 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2851 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2852 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2853 | |
| 2854 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2855 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2856 | chunk_appendf(&trash, |
| 2857 | "%lld,%lld,%d,%d,", |
| 2858 | sv->counters.failed_checks, sv->counters.down_trans, |
| 2859 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 2860 | else |
| 2861 | chunk_appendf(&trash, ",,,,"); |
| 2862 | |
| 2863 | /* queue limit, pid, iid, sid, */ |
| 2864 | chunk_appendf(&trash, |
| 2865 | "%s," |
| 2866 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2867 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2868 | relative_pid, px->uuid, sv->puid); |
| 2869 | |
| 2870 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2871 | if (sv->state & SRV_WARMINGUP) |
| 2872 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2873 | |
| 2874 | /* sessions: lbtot */ |
| 2875 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 2876 | |
| 2877 | /* tracked */ |
| 2878 | if (sv->track) |
| 2879 | chunk_appendf(&trash, "%s/%s,", |
| 2880 | sv->track->proxy->id, sv->track->id); |
| 2881 | else |
| 2882 | chunk_appendf(&trash, ","); |
| 2883 | |
| 2884 | /* type */ |
| 2885 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 2886 | |
| 2887 | /* rate */ |
| 2888 | chunk_appendf(&trash, "%u,,%u,", |
| 2889 | read_freq_ctr(&sv->sess_per_sec), |
| 2890 | sv->counters.sps_max); |
| 2891 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 2892 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2893 | /* check_status */ |
| 2894 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 2895 | |
| 2896 | /* check_code */ |
| 2897 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2898 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 2899 | else |
| 2900 | chunk_appendf(&trash, ","); |
| 2901 | |
| 2902 | /* check_duration */ |
| 2903 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 2904 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 2905 | else |
| 2906 | chunk_appendf(&trash, ","); |
| 2907 | |
| 2908 | } |
| 2909 | else |
| 2910 | chunk_appendf(&trash, ",,,"); |
| 2911 | |
| 2912 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2913 | if (px->mode == PR_MODE_HTTP) { |
| 2914 | for (i=1; i<6; i++) |
| 2915 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 2916 | |
| 2917 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 2918 | } |
| 2919 | else |
| 2920 | chunk_appendf(&trash, ",,,,,,"); |
| 2921 | |
| 2922 | /* failed health analyses */ |
| 2923 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 2924 | |
| 2925 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2926 | chunk_appendf(&trash, ",,,"); |
| 2927 | |
| 2928 | /* errors: cli_aborts, srv_aborts */ |
| 2929 | chunk_appendf(&trash, "%lld,%lld,", |
| 2930 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 2931 | |
| 2932 | /* compression: in, out, bypassed, comp_rsp */ |
| 2933 | chunk_appendf(&trash, ",,,,"); |
| 2934 | |
| 2935 | /* finish with EOL */ |
| 2936 | chunk_appendf(&trash, "\n"); |
| 2937 | } |
| 2938 | return 1; |
| 2939 | } |
| 2940 | |
| 2941 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 2942 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 2943 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 2944 | */ |
| 2945 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 2946 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2947 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2948 | struct chunk src; |
| 2949 | int i; |
| 2950 | |
| 2951 | if (!(px->cap & PR_CAP_BE)) |
| 2952 | return 0; |
| 2953 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2954 | 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] | 2955 | return 0; |
| 2956 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2957 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2958 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2959 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2960 | /* Column sub-heading for Enable or Disable server */ |
| 2961 | chunk_appendf(&trash, "<td></td>"); |
| 2962 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2963 | chunk_appendf(&trash, |
| 2964 | "<td class=ac>" |
| 2965 | /* name */ |
| 2966 | "%s<a name=\"%s/Backend\"></a>" |
| 2967 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 2968 | "", |
| 2969 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2970 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2971 | |
| 2972 | if (flags & ST_SHLGNDS) { |
| 2973 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2974 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2975 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 2976 | |
| 2977 | /* cookie */ |
| 2978 | if (px->cookie_name) { |
| 2979 | chunk_appendf(&trash, ", cookie: '"); |
| 2980 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 2981 | chunk_htmlencode(&trash, &src); |
| 2982 | chunk_appendf(&trash, "'"); |
| 2983 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2984 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2988 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2989 | /* queue : current, max */ |
| 2990 | "<td>%s</td><td>%s</td><td></td>" |
| 2991 | /* sessions rate : current, max, limit */ |
| 2992 | "<td>%s</td><td>%s</td><td></td>" |
| 2993 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2994 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2995 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 2996 | 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] | 2997 | |
| 2998 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2999 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3000 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3001 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3002 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3003 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3004 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 3005 | U2H(px->be_counters.cum_conn), |
| 3006 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3007 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3008 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3009 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3010 | chunk_appendf(&trash, |
| 3011 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3012 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3013 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3014 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3015 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3016 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3017 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3018 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3019 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3020 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3021 | U2H(px->be_counters.p.http.cum_req), |
| 3022 | U2H(px->be_counters.p.http.rsp[1]), |
| 3023 | U2H(px->be_counters.p.http.rsp[2]), |
| 3024 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3025 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3026 | (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] | 3027 | U2H(px->be_counters.p.http.rsp[3]), |
| 3028 | U2H(px->be_counters.p.http.rsp[4]), |
| 3029 | U2H(px->be_counters.p.http.rsp[5]), |
| 3030 | U2H(px->be_counters.p.http.rsp[0]), |
| 3031 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3035 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3036 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3037 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3038 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3039 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3040 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3041 | U2H(px->be_counters.cum_lbconn), |
| 3042 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3043 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3044 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3045 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3046 | "<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] | 3047 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3048 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3049 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3050 | px->be_counters.comp_in ? |
| 3051 | (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] | 3052 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3053 | |
| 3054 | chunk_appendf(&trash, |
| 3055 | /* denied: req, resp */ |
| 3056 | "<td>%s</td><td>%s</td>" |
| 3057 | /* errors : request, connect */ |
| 3058 | "<td></td><td>%s</td>" |
| 3059 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3060 | "<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] | 3061 | /* warnings: retries, redispatches */ |
| 3062 | "<td>%lld</td><td>%lld</td>" |
| 3063 | /* backend status: reflect backend status (up/down): we display UP |
| 3064 | * if the backend has known working servers or if it has no server at |
| 3065 | * all (eg: for stats). Then we display the total weight, number of |
| 3066 | * active and backups. */ |
| 3067 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3068 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3069 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3070 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 3071 | U2H(px->be_counters.failed_conns), |
| 3072 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3073 | px->be_counters.cli_aborts, |
| 3074 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3075 | px->be_counters.retries, px->be_counters.redispatches, |
| 3076 | human_time(now.tv_sec - px->last_change, 1), |
| 3077 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3078 | "<font color=\"red\"><b>DOWN</b></font>", |
| 3079 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3080 | px->srv_act, px->srv_bck); |
| 3081 | |
| 3082 | chunk_appendf(&trash, |
| 3083 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3084 | "<td class=ac> </td><td>%d</td>" |
| 3085 | "<td>%s</td>" |
| 3086 | "<td></td>" |
| 3087 | "</tr>", |
| 3088 | px->down_trans, |
| 3089 | px->srv?human_time(be_downtime(px), 1):" "); |
| 3090 | } |
| 3091 | else { /* CSV mode */ |
| 3092 | chunk_appendf(&trash, |
| 3093 | /* pxid, name */ |
| 3094 | "%s,BACKEND," |
| 3095 | /* queue : current, max */ |
| 3096 | "%d,%d," |
| 3097 | /* sessions : current, max, limit, total */ |
| 3098 | "%d,%d,%d,%lld," |
| 3099 | /* bytes : in, out */ |
| 3100 | "%lld,%lld," |
| 3101 | /* denied: req, resp */ |
| 3102 | "%lld,%lld," |
| 3103 | /* errors : request, connect, response */ |
| 3104 | ",%lld,%lld," |
| 3105 | /* warnings: retries, redispatches */ |
| 3106 | "%lld,%lld," |
| 3107 | /* backend status: reflect backend status (up/down): we display UP |
| 3108 | * if the backend has known working servers or if it has no server at |
| 3109 | * all (eg: for stats). Then we display the total weight, number of |
| 3110 | * active and backups. */ |
| 3111 | "%s," |
| 3112 | "%d,%d,%d," |
| 3113 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 3114 | ",%d,%d,%d,," |
| 3115 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3116 | "%d,%d,0,,%lld,,%d," |
| 3117 | /* rate, rate_lim, rate_max, */ |
| 3118 | "%u,,%u," |
| 3119 | /* check_status, check_code, check_duration */ |
| 3120 | ",,,", |
| 3121 | px->id, |
| 3122 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3123 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3124 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3125 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3126 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3127 | px->be_counters.retries, px->be_counters.redispatches, |
| 3128 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 3129 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 3130 | px->srv_act, px->srv_bck, |
| 3131 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 3132 | px->srv?be_downtime(px):0, |
| 3133 | relative_pid, px->uuid, |
| 3134 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 3135 | read_freq_ctr(&px->be_sess_per_sec), |
| 3136 | px->be_counters.sps_max); |
| 3137 | |
| 3138 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3139 | if (px->mode == PR_MODE_HTTP) { |
| 3140 | for (i=1; i<6; i++) |
| 3141 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 3142 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 3143 | } |
| 3144 | else |
| 3145 | chunk_appendf(&trash, ",,,,,,"); |
| 3146 | |
| 3147 | /* failed health analyses */ |
| 3148 | chunk_appendf(&trash, ","); |
| 3149 | |
| 3150 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3151 | chunk_appendf(&trash, ",,,"); |
| 3152 | |
| 3153 | /* errors: cli_aborts, srv_aborts */ |
| 3154 | chunk_appendf(&trash, "%lld,%lld,", |
| 3155 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 3156 | |
| 3157 | /* compression: in, out, bypassed */ |
| 3158 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3159 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3160 | |
| 3161 | /* compression: comp_rsp */ |
| 3162 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 3163 | |
| 3164 | /* finish with EOL */ |
| 3165 | chunk_appendf(&trash, "\n"); |
| 3166 | } |
| 3167 | return 1; |
| 3168 | } |
| 3169 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3170 | /* 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] | 3171 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3172 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3173 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3174 | 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] | 3175 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3176 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3177 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3178 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3179 | 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] | 3180 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3181 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3182 | /* 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] | 3183 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3184 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3185 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3186 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3187 | 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] | 3188 | } |
| 3189 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3190 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3191 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 3192 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3193 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3194 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3195 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | /* print a new table */ |
| 3199 | chunk_appendf(&trash, |
| 3200 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3201 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3202 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3203 | |
| 3204 | chunk_appendf(&trash, |
| 3205 | "<a name=\"%s\"></a>%s" |
| 3206 | "<a class=px href=\"#%s\">%s</a>", |
| 3207 | px->id, |
| 3208 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 3209 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3210 | |
| 3211 | if (uri->flags & ST_SHLGNDS) { |
| 3212 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3213 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3214 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3215 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3216 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3220 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3221 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3222 | "</tr>\n" |
| 3223 | "</table>\n" |
| 3224 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3225 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3226 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 3227 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3228 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3229 | 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] | 3230 | /* Column heading for Enable or Disable server */ |
| 3231 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3232 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3233 | |
| 3234 | chunk_appendf(&trash, |
| 3235 | "<th rowspan=2></th>" |
| 3236 | "<th colspan=3>Queue</th>" |
| 3237 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
| 3238 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3239 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 3240 | "<th colspan=9>Server</th>" |
| 3241 | "</tr>\n" |
| 3242 | "<tr class=\"titre\">" |
| 3243 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3244 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 3245 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>" |
| 3246 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3247 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3248 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3249 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 3250 | "<th>Thrtle</th>\n" |
| 3251 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3252 | } |
| 3253 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3254 | /* 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] | 3255 | * 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] | 3256 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3257 | 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] | 3258 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3259 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3260 | chunk_appendf(&trash, "</table>"); |
| 3261 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3262 | 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] | 3263 | /* close the form used to enable/disable this proxy servers */ |
| 3264 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3265 | "Choose the action to perform on the checked servers : " |
| 3266 | "<select name=action>" |
| 3267 | "<option value=\"\"></option>" |
| 3268 | "<option value=\"disable\">Disable</option>" |
| 3269 | "<option value=\"enable\">Enable</option>" |
| 3270 | "<option value=\"stop\">Soft Stop</option>" |
| 3271 | "<option value=\"start\">Soft Start</option>" |
| 3272 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3273 | "</select>" |
| 3274 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3275 | " <input type=\"submit\" value=\"Apply\">" |
| 3276 | "</form>", |
| 3277 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3281 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3282 | |
| 3283 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3284 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 3285 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3286 | * buffer space, or non-zero if everything completed. This function is used |
| 3287 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3288 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3289 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3290 | 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] | 3291 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3292 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3293 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 3294 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3295 | 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] | 3296 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3297 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3298 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3299 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3300 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3301 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3302 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3303 | if (uri && uri->scope) { |
| 3304 | /* we have a limited scope, we have to check the proxy name */ |
| 3305 | struct stat_scope *scope; |
| 3306 | int len; |
| 3307 | |
| 3308 | len = strlen(px->id); |
| 3309 | scope = uri->scope; |
| 3310 | |
| 3311 | while (scope) { |
| 3312 | /* match exact proxy name */ |
| 3313 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3314 | break; |
| 3315 | |
| 3316 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 3317 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3318 | break; |
| 3319 | scope = scope->next; |
| 3320 | } |
| 3321 | |
| 3322 | /* proxy name not found : don't dump anything */ |
| 3323 | if (scope == NULL) |
| 3324 | return 1; |
| 3325 | } |
| 3326 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3327 | /* if the user has requested a limited output and the proxy |
| 3328 | * name does not match, skip it. |
| 3329 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3330 | if (appctx->ctx.stats.scope_len && |
| 3331 | 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] | 3332 | return 1; |
| 3333 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3334 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 3335 | (appctx->ctx.stats.iid != -1) && |
| 3336 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3337 | return 1; |
| 3338 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3339 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3340 | /* fall through */ |
| 3341 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3342 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3343 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3344 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3345 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3346 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3347 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3348 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3349 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3350 | /* fall through */ |
| 3351 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3352 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3353 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3354 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3355 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3356 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3357 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3358 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 3359 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3360 | /* fall through */ |
| 3361 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3362 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3363 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3364 | for (; appctx->ctx.stats.l != &px->conf.listeners; appctx->ctx.stats.l = l->by_fe.n) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3365 | if (buffer_almost_full(rep->buf)) { |
| 3366 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3367 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3368 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3369 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3370 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3371 | if (!l->counters) |
| 3372 | continue; |
| 3373 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3374 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3375 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3376 | break; |
| 3377 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3378 | 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] | 3379 | continue; |
| 3380 | } |
| 3381 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3382 | /* print the frontend */ |
| 3383 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 3384 | if (bi_putchk(rep, &trash) == -1) |
| 3385 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 3386 | } |
| 3387 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3388 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 3389 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3390 | /* fall through */ |
| 3391 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3392 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3393 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3394 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3395 | 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] | 3396 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3397 | if (buffer_almost_full(rep->buf)) { |
| 3398 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3399 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3400 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 3401 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3402 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3403 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3404 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 3405 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3406 | break; |
| 3407 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3408 | 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] | 3409 | continue; |
| 3410 | } |
| 3411 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3412 | if (sv->track) |
| 3413 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3414 | else |
| 3415 | svs = sv; |
| 3416 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3417 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3418 | if (!(svs->check.state & CHK_ST_ENABLED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3419 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3420 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 3421 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3422 | sv_state = 3; /* UP */ |
| 3423 | else |
| 3424 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3425 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3426 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3427 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3428 | else if (svs->state & SRV_GOINGDOWN) |
| 3429 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3430 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3431 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 3432 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3433 | sv_state = 1; /* going up */ |
| 3434 | else |
| 3435 | sv_state = 0; /* DOWN */ |
| 3436 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3437 | 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] | 3438 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3439 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3440 | continue; |
| 3441 | } |
| 3442 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3443 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3444 | if (bi_putchk(rep, &trash) == -1) |
| 3445 | return 0; |
| 3446 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3447 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3448 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3449 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3450 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3451 | case STAT_PX_ST_BE: |
| 3452 | /* print the backend */ |
| 3453 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3454 | if (bi_putchk(rep, &trash) == -1) |
| 3455 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3456 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3457 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3458 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3459 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3460 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3461 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3462 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3463 | if (bi_putchk(rep, &trash) == -1) |
| 3464 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3465 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3466 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3467 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3468 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3469 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3470 | case STAT_PX_ST_FIN: |
| 3471 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3472 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3473 | default: |
| 3474 | /* unknown state, we should put an abort() here ! */ |
| 3475 | return 1; |
| 3476 | } |
| 3477 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3478 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3479 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3480 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3481 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3482 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3483 | { |
| 3484 | /* WARNING! This must fit in the first buffer !!! */ |
| 3485 | chunk_appendf(&trash, |
| 3486 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3487 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3488 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3489 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3490 | "<style type=\"text/css\"><!--\n" |
| 3491 | "body {" |
| 3492 | " font-family: arial, helvetica, sans-serif;" |
| 3493 | " font-size: 12px;" |
| 3494 | " font-weight: normal;" |
| 3495 | " color: black;" |
| 3496 | " background: white;" |
| 3497 | "}\n" |
| 3498 | "th,td {" |
| 3499 | " font-size: 10px;" |
| 3500 | "}\n" |
| 3501 | "h1 {" |
| 3502 | " font-size: x-large;" |
| 3503 | " margin-bottom: 0.5em;" |
| 3504 | "}\n" |
| 3505 | "h2 {" |
| 3506 | " font-family: helvetica, arial;" |
| 3507 | " font-size: x-large;" |
| 3508 | " font-weight: bold;" |
| 3509 | " font-style: italic;" |
| 3510 | " color: #6020a0;" |
| 3511 | " margin-top: 0em;" |
| 3512 | " margin-bottom: 0em;" |
| 3513 | "}\n" |
| 3514 | "h3 {" |
| 3515 | " font-family: helvetica, arial;" |
| 3516 | " font-size: 16px;" |
| 3517 | " font-weight: bold;" |
| 3518 | " color: #b00040;" |
| 3519 | " background: #e8e8d0;" |
| 3520 | " margin-top: 0em;" |
| 3521 | " margin-bottom: 0em;" |
| 3522 | "}\n" |
| 3523 | "li {" |
| 3524 | " margin-top: 0.25em;" |
| 3525 | " margin-right: 2em;" |
| 3526 | "}\n" |
| 3527 | ".hr {margin-top: 0.25em;" |
| 3528 | " border-color: black;" |
| 3529 | " border-bottom-style: solid;" |
| 3530 | "}\n" |
| 3531 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3532 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3533 | ".frontend {background: #e8e8d0;}\n" |
| 3534 | ".socket {background: #d0d0d0;}\n" |
| 3535 | ".backend {background: #e8e8d0;}\n" |
| 3536 | ".active0 {background: #ff9090;}\n" |
| 3537 | ".active1 {background: #ffd020;}\n" |
| 3538 | ".active2 {background: #ffffa0;}\n" |
| 3539 | ".active3 {background: #c0ffc0;}\n" |
| 3540 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3541 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3542 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3543 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3544 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3545 | ".backup0 {background: #ff9090;}\n" |
| 3546 | ".backup1 {background: #ff80ff;}\n" |
| 3547 | ".backup2 {background: #c060ff;}\n" |
| 3548 | ".backup3 {background: #b0d0ff;}\n" |
| 3549 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3550 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3551 | ".backup6 {background: #c060ff;}\n" |
| 3552 | ".backup7 {background: #cc9900;}\n" |
| 3553 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3554 | ".maintain {background: #c07820;}\n" |
| 3555 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3556 | "\n" |
| 3557 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3558 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3559 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3560 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3561 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3562 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3563 | "\n" |
| 3564 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3565 | "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" |
| 3566 | "table.tbl td.ac { text-align: center;}\n" |
| 3567 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3568 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3569 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3570 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3571 | "\n" |
| 3572 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3573 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3574 | "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] | 3575 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3576 | "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" |
Willy Tarreau | 6b9d3a8 | 2013-12-16 09:00:35 +0100 | [diff] [blame] | 3577 | "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;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3578 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3579 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3580 | " display:block;\n" |
| 3581 | " visibility:hidden;\n" |
| 3582 | " z-index:2147483647;\n" |
| 3583 | " position:absolute;\n" |
| 3584 | " padding:2px 4px 3px;\n" |
| 3585 | " background:#f0f060; color:#000000;\n" |
| 3586 | " border:1px solid #7040c0;\n" |
| 3587 | " white-space:nowrap;\n" |
| 3588 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3589 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3590 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3591 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3592 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3593 | "-->\n" |
| 3594 | "</style></head>\n", |
| 3595 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3596 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3597 | ); |
| 3598 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3599 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3600 | /* 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] | 3601 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3602 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3603 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3604 | 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] | 3605 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3606 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3607 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3608 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3609 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3610 | /* WARNING! this has to fit the first packet too. |
| 3611 | * We are around 3.5 kB, add adding entries will |
| 3612 | * become tricky if we want to support 4kB buffers ! |
| 3613 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3614 | chunk_appendf(&trash, |
| 3615 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3616 | PRODUCT_NAME "%s</a></h1>\n" |
| 3617 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3618 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3619 | "<h3>> General process information</h3>\n" |
| 3620 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3621 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3622 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3623 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3624 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3625 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3626 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3627 | "</td><td align=\"center\" nowrap>\n" |
| 3628 | "<table class=\"lgd\"><tr>\n" |
| 3629 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3630 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3631 | "</tr><tr>\n" |
| 3632 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3633 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3634 | "</tr><tr>\n" |
| 3635 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3636 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3637 | "</tr><tr>\n" |
| 3638 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3639 | "</tr><tr>\n" |
| 3640 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3641 | "</tr><tr>\n" |
| 3642 | "<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] | 3643 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3644 | "<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] | 3645 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3646 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3647 | "</td>" |
| 3648 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3649 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3650 | "", |
| 3651 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3652 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3653 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3654 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3655 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3656 | pid, relative_pid, global.nbproc, |
| 3657 | up / 86400, (up % 86400) / 3600, |
| 3658 | (up % 3600) / 60, (up % 60), |
| 3659 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3660 | global.rlimit_memmax ? " MB" : "", |
| 3661 | global.rlimit_nofile, |
| 3662 | global.maxsock, global.maxconn, global.maxpipes, |
| 3663 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3664 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3665 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3666 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3667 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3668 | memcpy(scope_txt, bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3669 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3670 | |
| 3671 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3672 | "<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] | 3673 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3674 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3675 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3676 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3677 | STAT_SCOPE_TXT_MAXLEN); |
| 3678 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3679 | /* 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] | 3680 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3681 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3682 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3683 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 3684 | 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] | 3685 | } |
| 3686 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3687 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3688 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3689 | "<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] | 3690 | uri->uri_prefix, |
| 3691 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3692 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3693 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3694 | else |
| 3695 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3696 | "<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] | 3697 | uri->uri_prefix, |
| 3698 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3699 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3700 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3701 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3702 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3703 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3704 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3705 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3706 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3707 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3708 | "", |
| 3709 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3710 | else |
| 3711 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3712 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3713 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3714 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3715 | ";norefresh", |
| 3716 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3717 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3718 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3719 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3720 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3721 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3722 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3723 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3724 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3725 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3726 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3727 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3728 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3729 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3730 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3731 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3732 | chunk_appendf(&trash, |
| 3733 | "</ul></td>" |
| 3734 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3735 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3736 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3737 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3738 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3739 | "</ul>" |
| 3740 | "</td>" |
| 3741 | "</tr></table>\n" |
| 3742 | "" |
| 3743 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3744 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3745 | if (appctx->ctx.stats.st_code) { |
| 3746 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3747 | case STAT_STATUS_DONE: |
| 3748 | chunk_appendf(&trash, |
| 3749 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3750 | "<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] | 3751 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3752 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3753 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3754 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3755 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3756 | break; |
| 3757 | case STAT_STATUS_NONE: |
| 3758 | chunk_appendf(&trash, |
| 3759 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3760 | "<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] | 3761 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3762 | "</div>\n", uri->uri_prefix, |
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 | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3765 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3766 | break; |
| 3767 | case STAT_STATUS_PART: |
| 3768 | chunk_appendf(&trash, |
| 3769 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3770 | "<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] | 3771 | "Action partially processed.<br>" |
| 3772 | "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] | 3773 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3774 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3775 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3776 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3777 | break; |
| 3778 | case STAT_STATUS_ERRP: |
| 3779 | chunk_appendf(&trash, |
| 3780 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3781 | "<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] | 3782 | "Action not processed because of invalid parameters." |
| 3783 | "<ul>" |
| 3784 | "<li>The action is maybe unknown.</li>" |
| 3785 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3786 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3787 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3788 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3789 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3790 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3791 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3792 | break; |
| 3793 | case STAT_STATUS_EXCD: |
| 3794 | chunk_appendf(&trash, |
| 3795 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3796 | "<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] | 3797 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3798 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3799 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3800 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3801 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3802 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3803 | break; |
| 3804 | case STAT_STATUS_DENY: |
| 3805 | chunk_appendf(&trash, |
| 3806 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3807 | "<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] | 3808 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3809 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3810 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3811 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3812 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3813 | break; |
| 3814 | default: |
| 3815 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3816 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3817 | "<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] | 3818 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3819 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3820 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3821 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3822 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3823 | } |
| 3824 | chunk_appendf(&trash, "<p>\n"); |
| 3825 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3826 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3827 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3828 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3829 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3830 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3831 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3832 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3833 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3834 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3835 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3836 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3837 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3838 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3839 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3840 | * and the session must be closed, or -1 in case of any error. This function is |
| 3841 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3842 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3843 | 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] | 3844 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3845 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3846 | struct channel *rep = si->ib; |
| 3847 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3848 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3849 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3850 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3851 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3852 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3853 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3854 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3855 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3856 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3857 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3858 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3859 | else |
| 3860 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3861 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3862 | if (bi_putchk(rep, &trash) == -1) |
| 3863 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3864 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3865 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3866 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3867 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3868 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3869 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3870 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3871 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3872 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3873 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3874 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3875 | appctx->ctx.stats.px = proxy; |
| 3876 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3877 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3878 | /* fall through */ |
| 3879 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3880 | case STAT_ST_LIST: |
| 3881 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3882 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3883 | if (buffer_almost_full(rep->buf)) { |
| 3884 | rep->flags |= CF_WAKE_WRITE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3885 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 3886 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3887 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3888 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3889 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 3890 | 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] | 3891 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3892 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3893 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3894 | appctx->ctx.stats.px = px->next; |
| 3895 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3896 | } |
| 3897 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3898 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3899 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3900 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3901 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3902 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3903 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3904 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3905 | if (bi_putchk(rep, &trash) == -1) |
| 3906 | return 0; |
| 3907 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3908 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3909 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3910 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 3911 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3912 | case STAT_ST_FIN: |
| 3913 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3914 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3915 | default: |
| 3916 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3917 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3918 | return -1; |
| 3919 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3920 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3921 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3922 | /* We reached the stats page through a POST request. The appctx is |
| 3923 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3924 | * Parse the posted data and enable/disable servers if necessary. |
| 3925 | * Returns 1 if request was parsed or zero if it needs more data. |
| 3926 | */ |
| 3927 | static int stats_process_http_post(struct stream_interface *si) |
| 3928 | { |
| 3929 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3930 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3931 | |
| 3932 | struct proxy *px = NULL; |
| 3933 | struct server *sv = NULL; |
| 3934 | |
| 3935 | char key[LINESIZE]; |
| 3936 | int action = ST_ADM_ACTION_NONE; |
| 3937 | int reprocess = 0; |
| 3938 | |
| 3939 | int total_servers = 0; |
| 3940 | int altered_servers = 0; |
| 3941 | |
| 3942 | char *first_param, *cur_param, *next_param, *end_params; |
| 3943 | char *st_cur_param = NULL; |
| 3944 | char *st_next_param = NULL; |
| 3945 | |
| 3946 | struct chunk *temp; |
| 3947 | int reql; |
| 3948 | |
| 3949 | temp = get_trash_chunk(); |
| 3950 | if (temp->size < s->txn.req.body_len) { |
| 3951 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3952 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3953 | goto out; |
| 3954 | } |
| 3955 | |
| 3956 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 3957 | if (reql <= 0) { |
| 3958 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3959 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3960 | return 0; |
| 3961 | } |
| 3962 | |
| 3963 | first_param = temp->str; |
| 3964 | end_params = temp->str + reql; |
| 3965 | cur_param = next_param = end_params; |
| 3966 | *end_params = '\0'; |
| 3967 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3968 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3969 | |
| 3970 | /* |
| 3971 | * Parse the parameters in reverse order to only store the last value. |
| 3972 | * From the html form, the backend and the action are at the end. |
| 3973 | */ |
| 3974 | while (cur_param > first_param) { |
| 3975 | char *value; |
| 3976 | int poffset, plen; |
| 3977 | |
| 3978 | cur_param--; |
| 3979 | |
| 3980 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 3981 | reprocess_servers: |
| 3982 | /* Parse the key */ |
| 3983 | poffset = (cur_param != first_param ? 1 : 0); |
| 3984 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 3985 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 3986 | strncpy(key, cur_param + poffset, plen); |
| 3987 | key[plen - 1] = '\0'; |
| 3988 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3989 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3990 | goto out; |
| 3991 | } |
| 3992 | |
| 3993 | /* Parse the value */ |
| 3994 | value = key; |
| 3995 | while (*value != '\0' && *value != '=') { |
| 3996 | value++; |
| 3997 | } |
| 3998 | if (*value == '=') { |
| 3999 | /* Ok, a value is found, we can mark the end of the key */ |
| 4000 | *value++ = '\0'; |
| 4001 | } |
| 4002 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 4003 | break; |
| 4004 | |
| 4005 | /* Now we can check the key to see what to do */ |
| 4006 | if (!px && (strcmp(key, "b") == 0)) { |
| 4007 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 4008 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4009 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4010 | goto out; |
| 4011 | } |
| 4012 | } |
| 4013 | else if (!action && (strcmp(key, "action") == 0)) { |
| 4014 | if (strcmp(value, "disable") == 0) { |
| 4015 | action = ST_ADM_ACTION_DISABLE; |
| 4016 | } |
| 4017 | else if (strcmp(value, "enable") == 0) { |
| 4018 | action = ST_ADM_ACTION_ENABLE; |
| 4019 | } |
| 4020 | else if (strcmp(value, "stop") == 0) { |
| 4021 | action = ST_ADM_ACTION_STOP; |
| 4022 | } |
| 4023 | else if (strcmp(value, "start") == 0) { |
| 4024 | action = ST_ADM_ACTION_START; |
| 4025 | } |
| 4026 | else if (strcmp(value, "shutdown") == 0) { |
| 4027 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4028 | } |
| 4029 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4030 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4031 | goto out; |
| 4032 | } |
| 4033 | } |
| 4034 | else if (strcmp(key, "s") == 0) { |
| 4035 | if (!(px && action)) { |
| 4036 | /* |
| 4037 | * Indicates that we'll need to reprocess the parameters |
| 4038 | * as soon as backend and action are known |
| 4039 | */ |
| 4040 | if (!reprocess) { |
| 4041 | st_cur_param = cur_param; |
| 4042 | st_next_param = next_param; |
| 4043 | } |
| 4044 | reprocess = 1; |
| 4045 | } |
| 4046 | else if ((sv = findserver(px, value)) != NULL) { |
| 4047 | switch (action) { |
| 4048 | case ST_ADM_ACTION_DISABLE: |
| 4049 | if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) { |
| 4050 | /* Not already in maintenance, we can change the server state */ |
| 4051 | sv->state |= SRV_MAINTAIN; |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 4052 | sv->check.state |= CHK_ST_PAUSED; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4053 | set_server_down(&sv->check); |
| 4054 | altered_servers++; |
| 4055 | total_servers++; |
| 4056 | } |
| 4057 | break; |
| 4058 | case ST_ADM_ACTION_ENABLE: |
| 4059 | if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) { |
Willy Tarreau | a3ae932 | 2013-12-28 21:28:49 +0100 | [diff] [blame] | 4060 | /* Already in maintenance, we can change the server state. |
| 4061 | * If this server tracks the status of another one, |
| 4062 | * we must restore the good status. |
| 4063 | */ |
| 4064 | if (!sv->track || (sv->track->state & SRV_RUNNING)) { |
| 4065 | set_server_up(&sv->check); |
| 4066 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 4067 | } |
| 4068 | else { |
| 4069 | sv->state &= ~SRV_MAINTAIN; |
| 4070 | sv->check.state &= ~CHK_ST_PAUSED; |
| 4071 | set_server_down(&sv->check); |
| 4072 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4073 | altered_servers++; |
| 4074 | total_servers++; |
| 4075 | } |
| 4076 | break; |
| 4077 | case ST_ADM_ACTION_STOP: |
| 4078 | case ST_ADM_ACTION_START: |
| 4079 | if (action == ST_ADM_ACTION_START) |
| 4080 | sv->uweight = sv->iweight; |
| 4081 | else |
| 4082 | sv->uweight = 0; |
| 4083 | |
| 4084 | server_recalc_eweight(sv); |
| 4085 | set_server_drain_state(sv); |
| 4086 | |
| 4087 | altered_servers++; |
| 4088 | total_servers++; |
| 4089 | break; |
| 4090 | case ST_ADM_ACTION_SHUTDOWN: |
| 4091 | if (px->state != PR_STSTOPPED) { |
| 4092 | struct session *sess, *sess_bck; |
| 4093 | |
| 4094 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 4095 | if (sess->srv_conn == sv) |
| 4096 | session_shutdown(sess, SN_ERR_KILLED); |
| 4097 | |
| 4098 | altered_servers++; |
| 4099 | total_servers++; |
| 4100 | } |
| 4101 | break; |
| 4102 | } |
| 4103 | } else { |
| 4104 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4105 | total_servers++; |
| 4106 | } |
| 4107 | } |
| 4108 | if (reprocess && px && action) { |
| 4109 | /* Now, we know the backend and the action chosen by the user. |
| 4110 | * We can safely restart from the first server parameter |
| 4111 | * to reprocess them |
| 4112 | */ |
| 4113 | cur_param = st_cur_param; |
| 4114 | next_param = st_next_param; |
| 4115 | reprocess = 0; |
| 4116 | goto reprocess_servers; |
| 4117 | } |
| 4118 | |
| 4119 | next_param = cur_param; |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4124 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4125 | } |
| 4126 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4127 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4128 | } |
| 4129 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4130 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4131 | } |
| 4132 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4133 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4134 | } |
| 4135 | out: |
| 4136 | return 1; |
| 4137 | } |
| 4138 | |
| 4139 | |
| 4140 | static int stats_send_http_headers(struct stream_interface *si) |
| 4141 | { |
| 4142 | struct session *s = session_from_task(si->owner); |
| 4143 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4144 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4145 | |
| 4146 | chunk_printf(&trash, |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4147 | "HTTP/1.0 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4148 | "Cache-Control: no-cache\r\n" |
| 4149 | "Connection: close\r\n" |
| 4150 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4151 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4152 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4153 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4154 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 4155 | uri->refresh); |
| 4156 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4157 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4158 | |
| 4159 | s->txn.status = 200; |
| 4160 | s->logs.tv_request = now; |
| 4161 | |
| 4162 | if (bi_putchk(si->ib, &trash) == -1) |
| 4163 | return 0; |
| 4164 | |
| 4165 | return 1; |
| 4166 | } |
| 4167 | |
| 4168 | static int stats_send_http_redirect(struct stream_interface *si) |
| 4169 | { |
| 4170 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4171 | struct session *s = session_from_task(si->owner); |
| 4172 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4173 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4174 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4175 | /* 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] | 4176 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4177 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4178 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4179 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
| 4180 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | /* We don't want to land on the posted stats page because a refresh will |
| 4184 | * repost the data. We don't want this to happen on accident so we redirect |
| 4185 | * the browse to the stats page with a GET. |
| 4186 | */ |
| 4187 | chunk_printf(&trash, |
| 4188 | "HTTP/1.1 303 See Other\r\n" |
| 4189 | "Cache-Control: no-cache\r\n" |
| 4190 | "Content-Type: text/plain\r\n" |
| 4191 | "Connection: close\r\n" |
| 4192 | "Location: %s;st=%s%s%s%s\r\n" |
| 4193 | "\r\n", |
| 4194 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4195 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 4196 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 4197 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 4198 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4199 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4200 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4201 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4202 | scope_txt); |
| 4203 | |
| 4204 | s->txn.status = 303; |
| 4205 | s->logs.tv_request = now; |
| 4206 | |
| 4207 | if (bi_putchk(si->ib, &trash) == -1) |
| 4208 | return 0; |
| 4209 | |
| 4210 | return 1; |
| 4211 | } |
| 4212 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4213 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4214 | * 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] | 4215 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4216 | * automatically unregisters itself once transfer is complete. |
| 4217 | */ |
| 4218 | static void http_stats_io_handler(struct stream_interface *si) |
| 4219 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4220 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4221 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4222 | struct channel *req = si->ob; |
| 4223 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 4224 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4225 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 4226 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4227 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4228 | /* check that the output is not closed */ |
| 4229 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4230 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4231 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4232 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4233 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4234 | if (stats_send_http_headers(si)) { |
| 4235 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4236 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4237 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4238 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4239 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4240 | } |
| 4241 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4242 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4243 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4244 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4245 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4246 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4247 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4248 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4249 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4250 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4251 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4252 | } |
| 4253 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4254 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4255 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4256 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4257 | } |
| 4258 | |
Willy Tarreau | 51437d2 | 2013-12-29 00:43:40 +0100 | [diff] [blame] | 4259 | if (appctx->st0 == STAT_HTTP_DONE) |
| 4260 | si_shutw(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 4261 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4262 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 4263 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4264 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4265 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 4266 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 4267 | si_shutr(si); |
| 4268 | res->flags |= CF_READ_NULL; |
| 4269 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4270 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4271 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4272 | /* update all other flags and resync with the other side */ |
| 4273 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4274 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4275 | /* we don't want to expire timeouts while we're processing requests */ |
| 4276 | si->ib->rex = TICK_ETERNITY; |
| 4277 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4278 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4279 | out: |
| 4280 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 4281 | /* check that we have released everything then unregister */ |
| 4282 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4283 | } |
| 4284 | } |
| 4285 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4286 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4287 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 4288 | { |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 4289 | if (!(conn->flags & CO_FL_CTRL_READY) || !conn->ctrl) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4290 | return "NONE"; |
| 4291 | return conn->ctrl->name; |
| 4292 | } |
| 4293 | |
| 4294 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 4295 | { |
| 4296 | static char ptr[17]; |
| 4297 | |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 4298 | if (!(conn->flags & CO_FL_XPRT_READY) || !conn->xprt) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4299 | return "NONE"; |
| 4300 | |
| 4301 | if (conn->xprt == &raw_sock) |
| 4302 | return "RAW"; |
| 4303 | |
| 4304 | #ifdef USE_OPENSSL |
| 4305 | if (conn->xprt == &ssl_sock) |
| 4306 | return "SSL"; |
| 4307 | #endif |
| 4308 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 4309 | return ptr; |
| 4310 | } |
| 4311 | |
| 4312 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 4313 | { |
| 4314 | static char ptr[17]; |
| 4315 | |
| 4316 | if (!conn->data) |
| 4317 | return "NONE"; |
| 4318 | |
| 4319 | if (conn->data == &sess_conn_cb) |
| 4320 | return "SESS"; |
| 4321 | |
| 4322 | if (conn->data == &si_conn_cb) |
| 4323 | return "STRM"; |
| 4324 | |
| 4325 | if (conn->data == &check_conn_cb) |
| 4326 | return "CHCK"; |
| 4327 | |
| 4328 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 4329 | return ptr; |
| 4330 | } |
| 4331 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4332 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4333 | * 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] | 4334 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 4335 | * 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] | 4336 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4337 | 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] | 4338 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4339 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4340 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4341 | extern const char *monthname[12]; |
| 4342 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4343 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4344 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4345 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4346 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4347 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4348 | 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] | 4349 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4350 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 4351 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4352 | return 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4353 | appctx->ctx.sess.uid = 0; |
| 4354 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4355 | return 1; |
| 4356 | } |
| 4357 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4358 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4359 | case 0: /* main status of the session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4360 | appctx->ctx.sess.uid = sess->uniq_id; |
| 4361 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4362 | /* fall through */ |
| 4363 | |
| 4364 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4365 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4366 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4367 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4368 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4369 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4370 | 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] | 4371 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 4372 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4373 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4374 | conn = objt_conn(sess->si[0].end); |
| 4375 | 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] | 4376 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4377 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4378 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4379 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4380 | break; |
| 4381 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4382 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4383 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4384 | default: |
| 4385 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4386 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4387 | break; |
| 4388 | } |
| 4389 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4390 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4391 | " 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] | 4392 | 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] | 4393 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4394 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4395 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4396 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 4397 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 4398 | sess->listener ? sess->listener->luid : 0); |
| 4399 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4400 | if (conn) |
| 4401 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4402 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4403 | 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] | 4404 | case AF_INET: |
| 4405 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4406 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4407 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4408 | break; |
| 4409 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4410 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4411 | break; |
| 4412 | default: |
| 4413 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4414 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4415 | break; |
| 4416 | } |
| 4417 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4418 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4419 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4420 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4421 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4422 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 4423 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4424 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4425 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4426 | conn = objt_conn(sess->si[1].end); |
| 4427 | if (conn) |
| 4428 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4429 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4430 | 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] | 4431 | case AF_INET: |
| 4432 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4433 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4434 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4435 | break; |
| 4436 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4437 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4438 | break; |
| 4439 | default: |
| 4440 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4441 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4442 | break; |
| 4443 | } |
| 4444 | |
| 4445 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4446 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4447 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4448 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 4449 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4450 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4451 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4452 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4453 | if (conn) |
| 4454 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4455 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4456 | 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] | 4457 | case AF_INET: |
| 4458 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4459 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4460 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4461 | break; |
| 4462 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4463 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4464 | break; |
| 4465 | default: |
| 4466 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4467 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4468 | break; |
| 4469 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4470 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4471 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4472 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4473 | sess->task, |
| 4474 | sess->task->state, |
| 4475 | sess->task->nice, sess->task->calls, |
| 4476 | sess->task->expire ? |
| 4477 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4478 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4479 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4480 | task_in_rq(sess->task) ? ", running" : ""); |
| 4481 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4482 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4483 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4484 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4485 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4486 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4487 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4488 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4489 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4490 | |
| 4491 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4492 | " 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] | 4493 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4494 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4495 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4496 | obj_type_name(sess->si[0].end), |
| 4497 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4498 | sess->si[0].exp ? |
| 4499 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4500 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4501 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4502 | sess->si[0].err_type); |
| 4503 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4504 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 4505 | " 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] | 4506 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4507 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4508 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4509 | obj_type_name(sess->si[1].end), |
| 4510 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4511 | sess->si[1].exp ? |
| 4512 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4513 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4514 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4515 | sess->si[1].err_type); |
| 4516 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4517 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4518 | chunk_appendf(&trash, |
| 4519 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4520 | conn, |
| 4521 | get_conn_ctrl_name(conn), |
| 4522 | get_conn_xprt_name(conn), |
| 4523 | get_conn_data_name(conn), |
| 4524 | obj_type_name(conn->target), |
| 4525 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4526 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4527 | chunk_appendf(&trash, |
| 4528 | " 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] | 4529 | conn->flags, |
| 4530 | conn->t.sock.fd, |
| 4531 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_e : 0, |
| 4532 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_p : 0, |
| 4533 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4534 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4535 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 4536 | chunk_appendf(&trash, |
| 4537 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4538 | tmpctx, |
| 4539 | tmpctx->st0, |
| 4540 | tmpctx->st1, |
| 4541 | tmpctx->st2, |
| 4542 | tmpctx->applet->name); |
| 4543 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4544 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4545 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4546 | chunk_appendf(&trash, |
| 4547 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4548 | conn, |
| 4549 | get_conn_ctrl_name(conn), |
| 4550 | get_conn_xprt_name(conn), |
| 4551 | get_conn_data_name(conn), |
| 4552 | obj_type_name(conn->target), |
| 4553 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4554 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4555 | chunk_appendf(&trash, |
| 4556 | " 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] | 4557 | conn->flags, |
| 4558 | conn->t.sock.fd, |
| 4559 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_e : 0, |
| 4560 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_p : 0, |
| 4561 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4562 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 4563 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 4564 | chunk_appendf(&trash, |
| 4565 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 4566 | tmpctx, |
| 4567 | tmpctx->st0, |
| 4568 | tmpctx->st1, |
| 4569 | tmpctx->st2, |
| 4570 | tmpctx->applet->name); |
| 4571 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4572 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4573 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4574 | " 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] | 4575 | " an_exp=%s", |
| 4576 | sess->req, |
| 4577 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4578 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4579 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4580 | sess->req->analyse_exp ? |
| 4581 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 4582 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4583 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4584 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4585 | " rex=%s", |
| 4586 | sess->req->rex ? |
| 4587 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4588 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4589 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4590 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4591 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4592 | " 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] | 4593 | sess->req->wex ? |
| 4594 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4595 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4596 | sess->req->buf, |
| 4597 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4598 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4599 | sess->txn.req.next, sess->req->buf->i, |
| 4600 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4601 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4602 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4603 | " 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] | 4604 | " an_exp=%s", |
| 4605 | sess->rep, |
| 4606 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4607 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4608 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4609 | sess->rep->analyse_exp ? |
| 4610 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 4611 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4612 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4613 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4614 | " rex=%s", |
| 4615 | sess->rep->rex ? |
| 4616 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4617 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4618 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4619 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4620 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4621 | " 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] | 4622 | sess->rep->wex ? |
| 4623 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4624 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4625 | sess->rep->buf, |
| 4626 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4627 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4628 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4629 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4630 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4631 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4632 | return 0; |
| 4633 | |
| 4634 | /* use other states to dump the contents */ |
| 4635 | } |
| 4636 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4637 | appctx->ctx.sess.uid = 0; |
| 4638 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4639 | return 1; |
| 4640 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4641 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4642 | static int stats_maps_list(struct stream_interface *si) |
| 4643 | { |
| 4644 | struct appctx *appctx = __objt_appctx(si->end); |
| 4645 | |
| 4646 | switch (appctx->st2) { |
| 4647 | case STAT_ST_INIT: |
| 4648 | /* Init to the first entry. The list cannot be change */ |
| 4649 | appctx->ctx.map.ref = LIST_NEXT(&maps, struct map_reference *, list); |
| 4650 | appctx->st2 = STAT_ST_LIST; |
| 4651 | /* fall through */ |
| 4652 | |
| 4653 | case STAT_ST_LIST: |
| 4654 | while (appctx->ctx.map.ref) { |
| 4655 | |
| 4656 | chunk_reset(&trash); |
| 4657 | |
| 4658 | /* build messages */ |
| 4659 | chunk_appendf(&trash, "%s\n", appctx->ctx.map.ref->reference); |
| 4660 | |
| 4661 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4662 | /* let's try again later from this session. We add ourselves into |
| 4663 | * this session's users so that it can remove us upon termination. |
| 4664 | */ |
| 4665 | return 0; |
| 4666 | } |
| 4667 | |
| 4668 | /* get next list entry and check the end of the list */ |
| 4669 | appctx->ctx.map.ref = LIST_NEXT(&appctx->ctx.map.ref->list, |
| 4670 | struct map_reference *, list); |
| 4671 | if (&appctx->ctx.map.ref->list == &maps) |
| 4672 | break; |
| 4673 | } |
| 4674 | |
| 4675 | appctx->st2 = STAT_ST_FIN; |
| 4676 | /* fall through */ |
| 4677 | |
| 4678 | default: |
| 4679 | appctx->st2 = STAT_ST_FIN; |
| 4680 | return 1; |
| 4681 | } |
| 4682 | } |
| 4683 | |
| 4684 | static const char *smp_to_type[SMP_TYPES] = { |
| 4685 | [SMP_T_BOOL] = "bool", |
| 4686 | [SMP_T_UINT] = "uint", |
| 4687 | [SMP_T_SINT] = "sint", |
| 4688 | [SMP_T_ADDR] = "addr", |
| 4689 | [SMP_T_IPV4] = "ipv4", |
| 4690 | [SMP_T_IPV6] = "ipv6", |
| 4691 | [SMP_T_STR] = "str", |
| 4692 | [SMP_T_BIN] = "bin", |
| 4693 | [SMP_T_CSTR] = "cstr", |
| 4694 | [SMP_T_CBIN] = "cbin", |
| 4695 | }; |
| 4696 | |
| 4697 | static int stats_map_lookup(struct stream_interface *si) |
| 4698 | { |
| 4699 | struct appctx *appctx = __objt_appctx(si->end); |
| 4700 | struct sample_storage *smp; |
| 4701 | struct sample sample; |
| 4702 | struct pattern *pat; |
| 4703 | struct pat_idx_elt *elt; |
| 4704 | enum pat_match_res res; |
| 4705 | struct sockaddr_in addr; |
Willy Tarreau | b908bef | 2013-12-16 01:42:03 +0100 | [diff] [blame] | 4706 | char addr_str[INET_ADDRSTRLEN]; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4707 | |
| 4708 | switch (appctx->st2) { |
| 4709 | case STAT_ST_INIT: |
| 4710 | appctx->ctx.map.desc = NULL; |
| 4711 | stats_map_lookup_next(si); |
| 4712 | appctx->st2 = STAT_ST_LIST; |
| 4713 | /* fall through */ |
| 4714 | |
| 4715 | case STAT_ST_LIST: |
| 4716 | /* for each lookup type */ |
| 4717 | while (appctx->ctx.map.desc) { |
| 4718 | /* initialise chunk to build new message */ |
| 4719 | chunk_reset(&trash); |
| 4720 | |
| 4721 | /* execute pattern matching */ |
| 4722 | sample.type = SMP_T_CSTR; |
| 4723 | sample.data.str.len = appctx->ctx.map.chunk.len; |
| 4724 | sample.data.str.str = appctx->ctx.map.chunk.str; |
| 4725 | pat = NULL; |
| 4726 | elt = NULL; |
| 4727 | res = pattern_exec_match(appctx->ctx.map.desc->pat, &sample, &smp, &pat, &elt); |
| 4728 | |
| 4729 | /* build return message: set type of match */ |
| 4730 | /**/ if (appctx->ctx.map.desc->pat->match == NULL) |
| 4731 | chunk_appendf(&trash, "found, "); |
| 4732 | else if (appctx->ctx.map.desc->pat->match == pat_match_nothing) |
| 4733 | chunk_appendf(&trash, "bool, "); |
| 4734 | else if (appctx->ctx.map.desc->pat->match == pat_match_int) |
| 4735 | chunk_appendf(&trash, "int, "); |
| 4736 | else if (appctx->ctx.map.desc->pat->match == pat_match_ip) |
| 4737 | chunk_appendf(&trash, "ip, "); |
| 4738 | else if (appctx->ctx.map.desc->pat->match == pat_match_bin) |
| 4739 | chunk_appendf(&trash, "bin, "); |
| 4740 | else if (appctx->ctx.map.desc->pat->match == pat_match_len) |
| 4741 | chunk_appendf(&trash, "len, "); |
| 4742 | else if (appctx->ctx.map.desc->pat->match == pat_match_str) |
| 4743 | chunk_appendf(&trash, "str, "); |
| 4744 | else if (appctx->ctx.map.desc->pat->match == pat_match_beg) |
| 4745 | chunk_appendf(&trash, "beg, "); |
| 4746 | else if (appctx->ctx.map.desc->pat->match == pat_match_sub) |
| 4747 | chunk_appendf(&trash, "sub, "); |
| 4748 | else if (appctx->ctx.map.desc->pat->match == pat_match_dir) |
| 4749 | chunk_appendf(&trash, "dir, "); |
| 4750 | else if (appctx->ctx.map.desc->pat->match == pat_match_dom) |
| 4751 | chunk_appendf(&trash, "dom, "); |
| 4752 | else if (appctx->ctx.map.desc->pat->match == pat_match_end) |
| 4753 | chunk_appendf(&trash, "end, "); |
| 4754 | else if (appctx->ctx.map.desc->pat->match == pat_match_reg) |
| 4755 | chunk_appendf(&trash, "reg, "); |
| 4756 | else /* The never appens case */ |
| 4757 | chunk_appendf(&trash, "unknown(%p), ", appctx->ctx.map.desc->pat->match); |
| 4758 | |
| 4759 | /* Display no match, and set default value */ |
| 4760 | if (res == PAT_NOMATCH) { |
| 4761 | chunk_appendf(&trash, "no-match, "); |
| 4762 | smp = appctx->ctx.map.desc->def; |
| 4763 | } |
| 4764 | |
| 4765 | /* Display match and match info */ |
| 4766 | else { |
| 4767 | /* display match */ |
| 4768 | chunk_appendf(&trash, "match, "); |
| 4769 | |
| 4770 | /* display search mode */ |
| 4771 | if (elt) |
| 4772 | chunk_appendf(&trash, "tree, "); |
| 4773 | else |
| 4774 | chunk_appendf(&trash, "list, "); |
| 4775 | |
| 4776 | /* display search options */ |
| 4777 | if (pat) { |
| 4778 | /* case sensitive */ |
| 4779 | if (pat->flags & PAT_F_IGNORE_CASE) |
| 4780 | chunk_appendf(&trash, "case-insensitive, "); |
| 4781 | else |
| 4782 | chunk_appendf(&trash, "case-sensitive, "); |
| 4783 | |
| 4784 | /* display source */ |
| 4785 | if (pat->flags & PAT_F_FROM_FILE) |
| 4786 | chunk_appendf(&trash, "from-file, "); |
| 4787 | } |
| 4788 | |
| 4789 | /* display match expresion */ |
| 4790 | if (elt) { |
| 4791 | if (appctx->ctx.map.desc->pat->match == pat_match_str) { |
| 4792 | chunk_appendf(&trash, "match=\"%s\", ", elt->node.key); |
| 4793 | } |
| 4794 | /* only IPv4 */ |
| 4795 | else if (appctx->ctx.map.desc->pat->match == pat_match_ip) { |
| 4796 | /* convert ip */ |
| 4797 | memcpy(&addr.sin_addr, elt->node.key, 4); |
| 4798 | addr.sin_family = AF_INET; |
Willy Tarreau | b908bef | 2013-12-16 01:42:03 +0100 | [diff] [blame] | 4799 | if (addr_to_str((struct sockaddr_storage *)&addr, addr_str, INET_ADDRSTRLEN)) |
| 4800 | chunk_appendf(&trash, "match=\"%s/%d\", ", addr_str, elt->node.node.pfx); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 4801 | } |
| 4802 | } |
| 4803 | } |
| 4804 | |
| 4805 | /* display return value */ |
| 4806 | if (!smp) { |
| 4807 | chunk_appendf(&trash, "return=nothing\n"); |
| 4808 | } |
| 4809 | else { |
| 4810 | memcpy(&sample.data, &smp->data, sizeof(sample.data)); |
| 4811 | sample.type = smp->type; |
| 4812 | if (sample_casts[sample.type][SMP_T_CSTR] && |
| 4813 | sample_casts[sample.type][SMP_T_CSTR](&sample)) |
| 4814 | chunk_appendf(&trash, "return=\"%s\", type=\"%s\"\n", |
| 4815 | sample.data.str.str, smp_to_type[smp->type]); |
| 4816 | else |
| 4817 | chunk_appendf(&trash, "return=cannot-display, type=\"%s\"\n", |
| 4818 | smp_to_type[smp->type]); |
| 4819 | } |
| 4820 | |
| 4821 | /* display response */ |
| 4822 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4823 | /* let's try again later from this session. We add ourselves into |
| 4824 | * this session's users so that it can remove us upon termination. |
| 4825 | */ |
| 4826 | return 0; |
| 4827 | } |
| 4828 | |
| 4829 | /* get next entry */ |
| 4830 | stats_map_lookup_next(si); |
| 4831 | } |
| 4832 | |
| 4833 | appctx->st2 = STAT_ST_FIN; |
| 4834 | /* fall through */ |
| 4835 | |
| 4836 | default: |
| 4837 | appctx->st2 = STAT_ST_FIN; |
| 4838 | free(appctx->ctx.map.chunk.str); |
| 4839 | return 1; |
| 4840 | } |
| 4841 | } |
| 4842 | |
| 4843 | static int stats_map_list(struct stream_interface *si) |
| 4844 | { |
| 4845 | struct appctx *appctx = __objt_appctx(si->end); |
| 4846 | |
| 4847 | switch (appctx->st2) { |
| 4848 | |
| 4849 | case STAT_ST_INIT: |
| 4850 | /* Init to the first entry. The list cannot be change */ |
| 4851 | appctx->ctx.map.ent = LIST_NEXT(&appctx->ctx.map.ref->entries, |
| 4852 | struct map_entry *, list); |
| 4853 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) |
| 4854 | appctx->ctx.map.ent = NULL; |
| 4855 | appctx->st2 = STAT_ST_LIST; |
| 4856 | /* fall through */ |
| 4857 | |
| 4858 | case STAT_ST_LIST: |
| 4859 | while (appctx->ctx.map.ent) { |
| 4860 | chunk_reset(&trash); |
| 4861 | |
| 4862 | /* build messages */ |
| 4863 | chunk_appendf(&trash, "%s %s\n", appctx->ctx.map.ent->key, appctx->ctx.map.ent->value); |
| 4864 | |
| 4865 | if (bi_putchk(si->ib, &trash) == -1) { |
| 4866 | /* let's try again later from this session. We add ourselves into |
| 4867 | * this session's users so that it can remove us upon termination. |
| 4868 | */ |
| 4869 | return 0; |
| 4870 | } |
| 4871 | |
| 4872 | /* get next list entry and check the end of the list */ |
| 4873 | appctx->ctx.map.ent = LIST_NEXT(&appctx->ctx.map.ent->list, |
| 4874 | struct map_entry *, list); |
| 4875 | if (&appctx->ctx.map.ent->list == &appctx->ctx.map.ref->entries) |
| 4876 | break; |
| 4877 | } |
| 4878 | |
| 4879 | appctx->st2 = STAT_ST_FIN; |
| 4880 | /* fall through */ |
| 4881 | |
| 4882 | default: |
| 4883 | appctx->st2 = STAT_ST_FIN; |
| 4884 | return 1; |
| 4885 | } |
| 4886 | } |
| 4887 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4888 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4889 | * 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] | 4890 | * to be called again, otherwise non-zero. It is designed to be called |
| 4891 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4892 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4893 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4894 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4895 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4896 | struct connection *conn; |
| 4897 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4898 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4899 | /* If we're forced to shut down, we might have to remove our |
| 4900 | * reference to the last session being dumped. |
| 4901 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4902 | if (appctx->st2 == STAT_ST_LIST) { |
| 4903 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 4904 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 4905 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4906 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4907 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4908 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4909 | } |
| 4910 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4911 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4912 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4913 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4914 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4915 | /* the function had not been called yet, let's prepare the |
| 4916 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4917 | * pointer to the first in the global list. When a target |
| 4918 | * session is being destroyed, it is responsible for updating |
| 4919 | * this pointer. We know we have reached the end when this |
| 4920 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4921 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4922 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 4923 | appctx->ctx.sess.bref.ref = sessions.n; |
| 4924 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4925 | /* fall through */ |
| 4926 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4927 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4928 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4929 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 4930 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 4931 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | /* and start from where we stopped */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4935 | while (appctx->ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 4936 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4937 | struct session *curr_sess; |
| 4938 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4939 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4940 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4941 | if (appctx->ctx.sess.target) { |
| 4942 | 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] | 4943 | goto next_sess; |
| 4944 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4945 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4946 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4947 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4948 | return 0; |
| 4949 | |
| 4950 | /* session dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4951 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 4952 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 4953 | if (appctx->ctx.sess.target != (void *)-1) { |
| 4954 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4955 | break; |
| 4956 | } |
| 4957 | else |
| 4958 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4959 | } |
| 4960 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4961 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4962 | "%p: proto=%s", |
| 4963 | curr_sess, |
| 4964 | curr_sess->listener->proto->name); |
| 4965 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4966 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4967 | conn = objt_conn(curr_sess->si[0].end); |
| 4968 | 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] | 4969 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4970 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4971 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4972 | " src=%s:%d fe=%s be=%s srv=%s", |
| 4973 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4974 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4975 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4976 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4977 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4978 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4979 | break; |
| 4980 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4981 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4982 | " src=unix:%d fe=%s be=%s srv=%s", |
| 4983 | curr_sess->listener->luid, |
| 4984 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4985 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4986 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4987 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4988 | break; |
| 4989 | } |
| 4990 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4991 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 4992 | " ts=%02x age=%s calls=%d", |
| 4993 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 4994 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 4995 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4996 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4997 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 4998 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4999 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5000 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5001 | curr_sess->req->analysers, |
| 5002 | curr_sess->req->rex ? |
| 5003 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 5004 | TICKS_TO_MS(1000)) : ""); |
| 5005 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5006 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5007 | ",wx=%s", |
| 5008 | curr_sess->req->wex ? |
| 5009 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 5010 | TICKS_TO_MS(1000)) : ""); |
| 5011 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5012 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5013 | ",ax=%s]", |
| 5014 | curr_sess->req->analyse_exp ? |
| 5015 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 5016 | TICKS_TO_MS(1000)) : ""); |
| 5017 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5018 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 5019 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5020 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 5021 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5022 | curr_sess->rep->analysers, |
| 5023 | curr_sess->rep->rex ? |
| 5024 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 5025 | TICKS_TO_MS(1000)) : ""); |
| 5026 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5027 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5028 | ",wx=%s", |
| 5029 | curr_sess->rep->wex ? |
| 5030 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 5031 | TICKS_TO_MS(1000)) : ""); |
| 5032 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5033 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5034 | ",ax=%s]", |
| 5035 | curr_sess->rep->analyse_exp ? |
| 5036 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 5037 | TICKS_TO_MS(1000)) : ""); |
| 5038 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5039 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5040 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5041 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 5042 | curr_sess->si[0].state, |
| 5043 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5044 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5045 | curr_sess->si[0].exp ? |
| 5046 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 5047 | TICKS_TO_MS(1000)) : ""); |
| 5048 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5049 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5050 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5051 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 5052 | curr_sess->si[1].state, |
| 5053 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5054 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5055 | curr_sess->si[1].exp ? |
| 5056 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 5057 | TICKS_TO_MS(1000)) : ""); |
| 5058 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5059 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5060 | " exp=%s", |
| 5061 | curr_sess->task->expire ? |
| 5062 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 5063 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 5064 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5065 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 5066 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5067 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5068 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5069 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 5070 | /* let's try again later from this session. We add ourselves into |
| 5071 | * this session's users so that it can remove us upon termination. |
| 5072 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5073 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5074 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5075 | } |
| 5076 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5077 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5078 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5079 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5080 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5081 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5082 | /* specified session not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5083 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5084 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5085 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5086 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5087 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5088 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5089 | return 0; |
| 5090 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5091 | appctx->ctx.sess.target = NULL; |
| 5092 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5093 | return 1; |
| 5094 | } |
| 5095 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5096 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5097 | /* fall through */ |
| 5098 | |
| 5099 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5100 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 5101 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5102 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 5103 | } |
| 5104 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5105 | /* This is called when the stream interface is closed. For instance, upon an |
| 5106 | * external abort, we won't call the i/o handler anymore so we may need to |
| 5107 | * remove back references to the session currently being dumped. |
| 5108 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 5109 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5110 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5111 | struct appctx *appctx = __objt_appctx(si->end); |
| 5112 | |
| 5113 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 5114 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 5115 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5116 | } |
| 5117 | } |
| 5118 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5119 | /* This function is used to either dump tables states (when action is set |
| 5120 | * 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] | 5121 | * It returns 0 if the output buffer is full and it needs to be called |
| 5122 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5123 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5124 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5125 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5126 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5127 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5128 | struct ebmb_node *eb; |
| 5129 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5130 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 5131 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5132 | |
| 5133 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5134 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5135 | * - STAT_ST_INIT : the first call |
| 5136 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5137 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5138 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5139 | * and the entry pointer points to the next entry to be dumped, |
| 5140 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5141 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5142 | * data though. |
| 5143 | */ |
| 5144 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5145 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5146 | /* 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] | 5147 | if (appctx->st2 == STAT_ST_LIST) { |
| 5148 | appctx->ctx.table.entry->ref_cnt--; |
| 5149 | 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] | 5150 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5151 | return 1; |
| 5152 | } |
| 5153 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5154 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5155 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5156 | while (appctx->st2 != STAT_ST_FIN) { |
| 5157 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5158 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5159 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 5160 | if (!appctx->ctx.table.proxy) |
| 5161 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5162 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5163 | appctx->ctx.table.entry = NULL; |
| 5164 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5165 | break; |
| 5166 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5167 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5168 | if (!appctx->ctx.table.proxy || |
| 5169 | (appctx->ctx.table.target && |
| 5170 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 5171 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5172 | break; |
| 5173 | } |
| 5174 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5175 | if (appctx->ctx.table.proxy->table.size) { |
| 5176 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5177 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5178 | return 0; |
| 5179 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5180 | if (appctx->ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 5181 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5182 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5183 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5184 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5185 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 5186 | appctx->ctx.table.entry->ref_cnt++; |
| 5187 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5188 | break; |
| 5189 | } |
| 5190 | } |
| 5191 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5192 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5193 | break; |
| 5194 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5195 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5196 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5197 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5198 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5199 | /* we're filtering on some data contents */ |
| 5200 | void *ptr; |
| 5201 | long long data; |
| 5202 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5203 | dt = appctx->ctx.table.data_type; |
| 5204 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 5205 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5206 | dt); |
| 5207 | |
| 5208 | data = 0; |
| 5209 | switch (stktable_data_types[dt].std_type) { |
| 5210 | case STD_T_SINT: |
| 5211 | data = stktable_data_cast(ptr, std_t_sint); |
| 5212 | break; |
| 5213 | case STD_T_UINT: |
| 5214 | data = stktable_data_cast(ptr, std_t_uint); |
| 5215 | break; |
| 5216 | case STD_T_ULL: |
| 5217 | data = stktable_data_cast(ptr, std_t_ull); |
| 5218 | break; |
| 5219 | case STD_T_FRQP: |
| 5220 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5221 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5222 | break; |
| 5223 | } |
| 5224 | |
| 5225 | /* 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] | 5226 | if ((data < appctx->ctx.table.value && |
| 5227 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5228 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5229 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 5230 | (data == appctx->ctx.table.value && |
| 5231 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 5232 | appctx->ctx.table.data_op == STD_OP_GT || |
| 5233 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 5234 | (data > appctx->ctx.table.value && |
| 5235 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 5236 | appctx->ctx.table.data_op == STD_OP_LT || |
| 5237 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 5238 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 5239 | } |
| 5240 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5241 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5242 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 5243 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 5244 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5245 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5246 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5247 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5248 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5249 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5250 | struct stksess *old = appctx->ctx.table.entry; |
| 5251 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 5252 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5253 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 5254 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5255 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 5256 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5257 | break; |
| 5258 | } |
| 5259 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5260 | |
| 5261 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5262 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 5263 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 5264 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 5265 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5266 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 5267 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5268 | break; |
| 5269 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 5270 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5271 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 5272 | break; |
| 5273 | } |
| 5274 | } |
| 5275 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5276 | } |
| 5277 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5278 | /* 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] | 5279 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 5280 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 5281 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 5282 | * lines are respected within the limit of 70 output chars. Lines that are |
| 5283 | * continuation of a previous truncated line begin with "+" instead of " " |
| 5284 | * after the offset. The new pointer is returned. |
| 5285 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5286 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 5287 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5288 | { |
| 5289 | int end; |
| 5290 | unsigned char c; |
| 5291 | |
| 5292 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 5293 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5294 | return ptr; |
| 5295 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 5296 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5297 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5298 | while (ptr < len && ptr < bsize) { |
| 5299 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5300 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5301 | if (out->len > end - 2) |
| 5302 | break; |
| 5303 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5304 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5305 | if (out->len > end - 3) |
| 5306 | break; |
| 5307 | out->str[out->len++] = '\\'; |
| 5308 | switch (c) { |
| 5309 | case '\t': c = 't'; break; |
| 5310 | case '\n': c = 'n'; break; |
| 5311 | case '\r': c = 'r'; break; |
| 5312 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 5313 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5314 | } |
| 5315 | out->str[out->len++] = c; |
| 5316 | } else { |
| 5317 | if (out->len > end - 5) |
| 5318 | break; |
| 5319 | out->str[out->len++] = '\\'; |
| 5320 | out->str[out->len++] = 'x'; |
| 5321 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 5322 | out->str[out->len++] = hextab[c & 0xF]; |
| 5323 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 5324 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5325 | /* we had a line break, let's return now */ |
| 5326 | out->str[out->len++] = '\n'; |
| 5327 | *line = ptr; |
| 5328 | return ptr; |
| 5329 | } |
| 5330 | } |
| 5331 | /* we have an incomplete line, we return it as-is */ |
| 5332 | out->str[out->len++] = '\n'; |
| 5333 | return ptr; |
| 5334 | } |
| 5335 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 5336 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5337 | * 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] | 5338 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5339 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5340 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5341 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5342 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5343 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5344 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 5345 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5346 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5347 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5348 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5349 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5350 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5351 | /* the function had not been called yet, let's prepare the |
| 5352 | * buffer for a response. |
| 5353 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5354 | struct tm tm; |
| 5355 | |
| 5356 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5357 | 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] | 5358 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5359 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 5360 | error_snapshot_id); |
| 5361 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5362 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 5363 | /* Socket buffer full. Let's try again later from the same point */ |
| 5364 | return 0; |
| 5365 | } |
| 5366 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5367 | appctx->ctx.errors.px = proxy; |
| 5368 | appctx->ctx.errors.buf = 0; |
| 5369 | appctx->ctx.errors.bol = 0; |
| 5370 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5371 | } |
| 5372 | |
| 5373 | /* we have two inner loops here, one for the proxy, the other one for |
| 5374 | * the buffer. |
| 5375 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5376 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5377 | struct error_snapshot *es; |
| 5378 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5379 | if (appctx->ctx.errors.buf == 0) |
| 5380 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5381 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5382 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5383 | |
| 5384 | if (!es->when.tv_sec) |
| 5385 | goto next; |
| 5386 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5387 | if (appctx->ctx.errors.iid >= 0 && |
| 5388 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 5389 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5390 | goto next; |
| 5391 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5392 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5393 | /* just print headers now */ |
| 5394 | |
| 5395 | char pn[INET6_ADDRSTRLEN]; |
| 5396 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5397 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5398 | |
| 5399 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5400 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5401 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 5402 | 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] | 5403 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5404 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 5405 | case AF_INET: |
| 5406 | case AF_INET6: |
| 5407 | port = get_host_port(&es->src); |
| 5408 | break; |
| 5409 | default: |
| 5410 | port = 0; |
| 5411 | } |
| 5412 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5413 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5414 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5415 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5416 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5417 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5418 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5419 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 5420 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5421 | break; |
| 5422 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5423 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5424 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5425 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5426 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5427 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5428 | break; |
| 5429 | } |
| 5430 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5431 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 5432 | ", server %s (#%d), event #%u\n" |
| 5433 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 5434 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 5435 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 5436 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 5437 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 5438 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 5439 | es->ev_id, |
| 5440 | pn, port, es->sid, es->s_flags, |
| 5441 | es->state, es->m_flags, es->t_flags, |
| 5442 | es->m_clen, es->m_blen, |
| 5443 | es->b_flags, es->b_out, es->b_tot, |
| 5444 | es->len, es->b_wrap, es->pos); |
| 5445 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5446 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5447 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5448 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5449 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5450 | appctx->ctx.errors.ptr = 0; |
| 5451 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5452 | } |
| 5453 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5454 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5455 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5456 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5457 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5458 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5459 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5460 | goto next; |
| 5461 | } |
| 5462 | |
| 5463 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5464 | 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] | 5465 | int newptr; |
| 5466 | int newline; |
| 5467 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5468 | newline = appctx->ctx.errors.bol; |
| 5469 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 5470 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5471 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5472 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5473 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5474 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5475 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5476 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5477 | appctx->ctx.errors.ptr = newptr; |
| 5478 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5479 | }; |
| 5480 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5481 | appctx->ctx.errors.bol = 0; |
| 5482 | appctx->ctx.errors.ptr = -1; |
| 5483 | appctx->ctx.errors.buf++; |
| 5484 | if (appctx->ctx.errors.buf > 1) { |
| 5485 | appctx->ctx.errors.buf = 0; |
| 5486 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5487 | } |
| 5488 | } |
| 5489 | |
| 5490 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 5491 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 5492 | } |
| 5493 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5494 | /* parse the "level" argument on the bind lines */ |
| 5495 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 5496 | { |
| 5497 | if (!*args[cur_arg + 1]) { |
| 5498 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 5499 | return ERR_ALERT | ERR_FATAL; |
| 5500 | } |
| 5501 | |
| 5502 | if (!strcmp(args[cur_arg+1], "user")) |
| 5503 | conf->level = ACCESS_LVL_USER; |
| 5504 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 5505 | conf->level = ACCESS_LVL_OPER; |
| 5506 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 5507 | conf->level = ACCESS_LVL_ADMIN; |
| 5508 | else { |
| 5509 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 5510 | args[cur_arg], args[cur_arg+1]); |
| 5511 | return ERR_ALERT | ERR_FATAL; |
| 5512 | } |
| 5513 | |
| 5514 | return 0; |
| 5515 | } |
| 5516 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5517 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5518 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5519 | .name = "<STATS>", /* used for logging */ |
| 5520 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 5521 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5522 | }; |
| 5523 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 5524 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5525 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5526 | .name = "<CLI>", /* used for logging */ |
| 5527 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 5528 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 5529 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5530 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 5531 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5532 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 5533 | { 0, NULL, NULL }, |
| 5534 | }}; |
| 5535 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5536 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 5537 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 5538 | { NULL, NULL, 0 }, |
| 5539 | }}; |
| 5540 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5541 | __attribute__((constructor)) |
| 5542 | static void __dumpstats_module_init(void) |
| 5543 | { |
| 5544 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 5545 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 5546 | } |
| 5547 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5548 | /* |
| 5549 | * Local variables: |
| 5550 | * c-indent-level: 8 |
| 5551 | * c-basic-offset: 8 |
| 5552 | * End: |
| 5553 | */ |