Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 2 | * Functions dedicated to statistics output and the stats socket |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 27 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 28 | #include <common/compat.h> |
| 29 | #include <common/config.h> |
| 30 | #include <common/debug.h> |
| 31 | #include <common/memory.h> |
| 32 | #include <common/mini-clist.h> |
| 33 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 34 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 35 | #include <common/time.h> |
| 36 | #include <common/uri_auth.h> |
| 37 | #include <common/version.h> |
| 38 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | |
| 41 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 42 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 43 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 44 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 45 | #include <proto/dumpstats.h> |
| 46 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 47 | #include <proto/freq_ctr.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 48 | #include <proto/log.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 49 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 50 | #include <proto/listener.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 51 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 52 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 53 | #include <proto/proxy.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 54 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 55 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 56 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 57 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 58 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 59 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 60 | #ifdef USE_OPENSSL |
| 61 | #include <proto/ssl_sock.h> |
| 62 | #endif |
| 63 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 64 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 65 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 66 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 67 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 68 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 69 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 70 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 71 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 72 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 73 | * cli_io_handler() |
| 74 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 75 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 76 | * -> stats_dump_info_to_buffer() // "show info" |
| 77 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 78 | * -> stats_dump_csv_header() |
| 79 | * -> stats_dump_proxy_to_buffer() |
| 80 | * -> stats_dump_fe_stats() |
| 81 | * -> stats_dump_li_stats() |
| 82 | * -> stats_dump_sv_stats() |
| 83 | * -> stats_dump_be_stats() |
| 84 | * |
| 85 | * http_stats_io_handler() |
| 86 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 87 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 88 | * -> stats_dump_html_head() // emits the HTML headers |
| 89 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 90 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 91 | * -> stats_dump_html_px_hdr() |
| 92 | * -> stats_dump_fe_stats() |
| 93 | * -> stats_dump_li_stats() |
| 94 | * -> stats_dump_sv_stats() |
| 95 | * -> stats_dump_be_stats() |
| 96 | * -> stats_dump_html_px_end() |
| 97 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 98 | */ |
| 99 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 100 | static struct si_applet cli_applet; |
| 101 | |
| 102 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 103 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 104 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 105 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 106 | " help : this message\n" |
| 107 | " prompt : toggle interactive mode with prompt\n" |
| 108 | " quit : disconnect\n" |
| 109 | " show info : report information about the running process\n" |
| 110 | " show stat : report counters for each proxy and server\n" |
| 111 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 112 | " show sess [id] : report the list of current sessions or dump this session\n" |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 113 | " show table [id]: report table usage stats or dump this table's contents\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 114 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 115 | " set weight : change a server's weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 116 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 117 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 118 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 119 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 120 | " disable : put a server or frontend in maintenance mode\n" |
| 121 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 122 | " shutdown : kill a session or a frontend (eg:to release listening ports)\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 123 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 124 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 125 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 126 | "Permission denied\n" |
| 127 | ""; |
| 128 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 129 | /* data transmission states for the stats responses */ |
| 130 | enum { |
| 131 | STAT_ST_INIT = 0, |
| 132 | STAT_ST_HEAD, |
| 133 | STAT_ST_INFO, |
| 134 | STAT_ST_LIST, |
| 135 | STAT_ST_END, |
| 136 | STAT_ST_FIN, |
| 137 | }; |
| 138 | |
| 139 | /* data transmission states for the stats responses inside a proxy */ |
| 140 | enum { |
| 141 | STAT_PX_ST_INIT = 0, |
| 142 | STAT_PX_ST_TH, |
| 143 | STAT_PX_ST_FE, |
| 144 | STAT_PX_ST_LI, |
| 145 | STAT_PX_ST_SV, |
| 146 | STAT_PX_ST_BE, |
| 147 | STAT_PX_ST_END, |
| 148 | STAT_PX_ST_FIN, |
| 149 | }; |
| 150 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 151 | extern const char *stat_status_codes[]; |
| 152 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 153 | /* This function is called from the session-level accept() in order to instanciate |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 154 | * a new stats socket. It returns a positive value upon success, 0 if the connection |
| 155 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 156 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 157 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 158 | { |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 159 | /* we have a dedicated I/O handler for the stats */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 160 | stream_int_register_handler(&s->si[1], &cli_applet); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 161 | s->target = &cli_applet.obj_type; // for logging only |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 162 | s->si[1].appctx.st1 = 0; |
| 163 | s->si[1].appctx.st0 = STAT_CLI_INIT; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 164 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 165 | tv_zero(&s->logs.tv_request); |
| 166 | s->logs.t_queue = 0; |
| 167 | s->logs.t_connect = 0; |
| 168 | s->logs.t_data = 0; |
| 169 | s->logs.t_close = 0; |
| 170 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 171 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 172 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 173 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 174 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 175 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 176 | if (s->listener->timeout) { |
| 177 | s->req->rto = *s->listener->timeout; |
| 178 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 179 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 180 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 183 | /* allocate a new stats frontend named <name>, and return it |
| 184 | * (or NULL in case of lack of memory). |
| 185 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 186 | 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] | 187 | { |
| 188 | struct proxy *fe; |
| 189 | |
| 190 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 191 | if (!fe) |
| 192 | return NULL; |
| 193 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 194 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 195 | fe->next = proxy; |
| 196 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 197 | fe->last_change = now.tv_sec; |
| 198 | fe->id = strdup("GLOBAL"); |
| 199 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 200 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 201 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 202 | fe->conf.file = strdup(file); |
| 203 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 204 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 205 | |
| 206 | /* the stats frontend is the only one able to assign ID #0 */ |
| 207 | fe->conf.id.key = fe->uuid = 0; |
| 208 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 209 | return fe; |
| 210 | } |
| 211 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 212 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 213 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 214 | * error message into the <err> buffer which will be preallocated. The trailing |
| 215 | * '\n' must not be written. The function must be called with <args> pointing to |
| 216 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 217 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 218 | 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] | 219 | struct proxy *defpx, const char *file, int line, |
| 220 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 221 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 222 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 223 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 224 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 225 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 226 | int cur_arg; |
| 227 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 228 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 229 | 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] | 230 | return -1; |
| 231 | } |
| 232 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 233 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 234 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 235 | 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] | 236 | return -1; |
| 237 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 238 | } |
| 239 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 240 | 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] | 241 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 242 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 243 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 244 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 245 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 246 | return -1; |
| 247 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 248 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 249 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 250 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 251 | static int bind_dumped; |
| 252 | struct bind_kw *kw; |
| 253 | |
| 254 | kw = bind_find_kw(args[cur_arg]); |
| 255 | if (kw) { |
| 256 | if (!kw->parse) { |
| 257 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 258 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 259 | return -1; |
| 260 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 261 | |
| 262 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 263 | if (err && *err) |
| 264 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 265 | else |
| 266 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 267 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 268 | return -1; |
| 269 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 270 | |
| 271 | cur_arg += 1 + kw->skip; |
| 272 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 273 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 274 | |
| 275 | if (!bind_dumped) { |
| 276 | bind_dump_kws(err); |
| 277 | indent_msg(err, 4); |
| 278 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 279 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 280 | |
| 281 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 282 | args[0], args[1], args[cur_arg], |
| 283 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 284 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 285 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 286 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 287 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 288 | l->maxconn = global.stats_fe->maxconn; |
| 289 | l->backlog = global.stats_fe->backlog; |
| 290 | l->timeout = &global.stats_fe->timeout.client; |
| 291 | l->accept = session_accept; |
| 292 | l->handler = process_session; |
| 293 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 294 | l->nice = -64; /* we want to boost priority for local stats */ |
| 295 | global.maxsock += l->maxconn; |
| 296 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 297 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 298 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 299 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 300 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 301 | |
| 302 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 303 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 304 | return -1; |
| 305 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 306 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 307 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 308 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 309 | return -1; |
| 310 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 311 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 312 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 313 | 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] | 314 | return -1; |
| 315 | } |
| 316 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 317 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 318 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 319 | else if (!strcmp(args[1], "maxconn")) { |
| 320 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 321 | |
| 322 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 323 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 324 | return -1; |
| 325 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 326 | |
| 327 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 328 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 329 | 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] | 330 | return -1; |
| 331 | } |
| 332 | } |
| 333 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 334 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 335 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 336 | int cur_arg = 2; |
| 337 | unsigned int set = 0; |
| 338 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 339 | if (!global.stats_fe) { |
| 340 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 341 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 342 | return -1; |
| 343 | } |
| 344 | } |
| 345 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 346 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 347 | unsigned int low, high; |
| 348 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 349 | if (strcmp(args[cur_arg], "all") == 0) { |
| 350 | set = 0; |
| 351 | break; |
| 352 | } |
| 353 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 354 | set |= 0x55555555; |
| 355 | } |
| 356 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 357 | set |= 0xAAAAAAAA; |
| 358 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 359 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 360 | char *dash = strchr(args[cur_arg], '-'); |
| 361 | |
| 362 | low = high = str2uic(args[cur_arg]); |
| 363 | if (dash) |
| 364 | high = str2uic(dash + 1); |
| 365 | |
| 366 | if (high < low) { |
| 367 | unsigned int swap = low; |
| 368 | low = high; |
| 369 | high = swap; |
| 370 | } |
| 371 | |
| 372 | if (low < 1 || high > 32) { |
| 373 | memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n", |
| 374 | args[0], args[1]); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 375 | return -1; |
| 376 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 377 | |
| 378 | while (low <= high) |
| 379 | set |= 1 << (low++ - 1); |
| 380 | } |
| 381 | else { |
| 382 | memprintf(err, |
| 383 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 384 | args[0], args[1]); |
| 385 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 386 | } |
| 387 | cur_arg++; |
| 388 | } |
| 389 | global.stats_fe->bind_proc = set; |
| 390 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 391 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 392 | 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] | 393 | return -1; |
| 394 | } |
| 395 | return 0; |
| 396 | } |
| 397 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 398 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 399 | * for clearing it if needed. |
| 400 | */ |
| 401 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 402 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 403 | chunk_appendf(&trash, |
| 404 | "# pxname,svname," |
| 405 | "qcur,qmax," |
| 406 | "scur,smax,slim,stot," |
| 407 | "bin,bout," |
| 408 | "dreq,dresp," |
| 409 | "ereq,econ,eresp," |
| 410 | "wretr,wredis," |
| 411 | "status,weight,act,bck," |
| 412 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 413 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 414 | "rate,rate_lim,rate_max," |
| 415 | "check_status,check_code,check_duration," |
| 416 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 417 | "req_rate,req_rate_max,req_tot," |
| 418 | "cli_abrt,srv_abrt," |
| 419 | "comp_in,comp_out,comp_byp,comp_rsp," |
| 420 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 421 | } |
| 422 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 423 | /* print a string of text buffer to <out>. The format is : |
| 424 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 425 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 426 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 427 | */ |
| 428 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 429 | { |
| 430 | unsigned char c; |
| 431 | int ptr = 0; |
| 432 | |
| 433 | while (buf[ptr] && ptr < bsize) { |
| 434 | c = buf[ptr]; |
| 435 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 436 | if (out->len > out->size - 1) |
| 437 | break; |
| 438 | out->str[out->len++] = c; |
| 439 | } |
| 440 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 441 | if (out->len > out->size - 2) |
| 442 | break; |
| 443 | out->str[out->len++] = '\\'; |
| 444 | switch (c) { |
| 445 | case ' ': c = ' '; break; |
| 446 | case '\t': c = 't'; break; |
| 447 | case '\n': c = 'n'; break; |
| 448 | case '\r': c = 'r'; break; |
| 449 | case '\e': c = 'e'; break; |
| 450 | case '\\': c = '\\'; break; |
| 451 | } |
| 452 | out->str[out->len++] = c; |
| 453 | } |
| 454 | else { |
| 455 | if (out->len > out->size - 4) |
| 456 | break; |
| 457 | out->str[out->len++] = '\\'; |
| 458 | out->str[out->len++] = 'x'; |
| 459 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 460 | out->str[out->len++] = hextab[c & 0xF]; |
| 461 | } |
| 462 | ptr++; |
| 463 | } |
| 464 | |
| 465 | return ptr; |
| 466 | } |
| 467 | |
| 468 | /* print a buffer in hexa. |
| 469 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 470 | */ |
| 471 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 472 | { |
| 473 | unsigned char c; |
| 474 | int ptr = 0; |
| 475 | |
| 476 | while (ptr < bsize) { |
| 477 | c = buf[ptr]; |
| 478 | |
| 479 | if (out->len > out->size - 2) |
| 480 | break; |
| 481 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 482 | out->str[out->len++] = hextab[c & 0xF]; |
| 483 | |
| 484 | ptr++; |
| 485 | } |
| 486 | return ptr; |
| 487 | } |
| 488 | |
| 489 | /* Dump the status of a table to a stream interface's |
| 490 | * read buffer. It returns 0 if the output buffer is full |
| 491 | * and needs to be called again, otherwise non-zero. |
| 492 | */ |
| 493 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 494 | struct proxy *proxy, struct proxy *target) |
| 495 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 496 | struct session *s = session_from_task(si->owner); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 497 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 498 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 499 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 500 | |
| 501 | /* any other information should be dumped here */ |
| 502 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 503 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 504 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 505 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 506 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 507 | return 0; |
| 508 | |
| 509 | return 1; |
| 510 | } |
| 511 | |
| 512 | /* Dump the a table entry to a stream interface's |
| 513 | * read buffer. It returns 0 if the output buffer is full |
| 514 | * and needs to be called again, otherwise non-zero. |
| 515 | */ |
| 516 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 517 | struct proxy *proxy, struct stksess *entry) |
| 518 | { |
| 519 | int dt; |
| 520 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 521 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 522 | |
| 523 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 524 | char addr[INET_ADDRSTRLEN]; |
| 525 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 526 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 527 | } |
| 528 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 529 | char addr[INET6_ADDRSTRLEN]; |
| 530 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 531 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 532 | } |
| 533 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 534 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 535 | } |
| 536 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 537 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 538 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 539 | } |
| 540 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 541 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 542 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 543 | } |
| 544 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 545 | 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] | 546 | |
| 547 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 548 | void *ptr; |
| 549 | |
| 550 | if (proxy->table.data_ofs[dt] == 0) |
| 551 | continue; |
| 552 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 553 | 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] | 554 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 555 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 556 | |
| 557 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 558 | switch (stktable_data_types[dt].std_type) { |
| 559 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 560 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 561 | break; |
| 562 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 563 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 564 | break; |
| 565 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 566 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 567 | break; |
| 568 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 569 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 570 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 571 | proxy->table.data_arg[dt].u)); |
| 572 | break; |
| 573 | } |
| 574 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 575 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 576 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 577 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 578 | return 0; |
| 579 | |
| 580 | return 1; |
| 581 | } |
| 582 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 583 | 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] | 584 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 585 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 586 | struct proxy *px = si->appctx.ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 587 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 588 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 589 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 590 | long long value; |
| 591 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 592 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 593 | void *ptr; |
| 594 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 595 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 596 | si->appctx.st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 597 | |
| 598 | if (!*args[4]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 599 | si->appctx.ctx.cli.msg = "Key value expected\n"; |
| 600 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 601 | return; |
| 602 | } |
| 603 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 604 | switch (px->table.type) { |
| 605 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 606 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 607 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 608 | break; |
| 609 | case STKTABLE_TYPE_IPV6: |
| 610 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 611 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 612 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 613 | case STKTABLE_TYPE_INTEGER: |
| 614 | { |
| 615 | char *endptr; |
| 616 | unsigned long val; |
| 617 | errno = 0; |
| 618 | val = strtoul(args[4], &endptr, 10); |
| 619 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 620 | (errno != 0 && val == 0) || endptr == args[4] || |
| 621 | val > 0xffffffff) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 622 | si->appctx.ctx.cli.msg = "Invalid key\n"; |
| 623 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 624 | return; |
| 625 | } |
| 626 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 627 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 628 | break; |
| 629 | } |
| 630 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 631 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 632 | static_table_key->key = args[4]; |
| 633 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 634 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 635 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 636 | switch (action) { |
| 637 | case STAT_CLI_O_TAB: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 638 | si->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] | 639 | break; |
| 640 | case STAT_CLI_O_CLR: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 641 | si->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] | 642 | break; |
| 643 | default: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 644 | si->appctx.ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 645 | break; |
| 646 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 647 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 648 | return; |
| 649 | } |
| 650 | |
| 651 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 652 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 653 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 654 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 655 | return; |
| 656 | } |
| 657 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 658 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 659 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 660 | switch (action) { |
| 661 | case STAT_CLI_O_TAB: |
| 662 | if (!ts) |
| 663 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 664 | chunk_reset(&trash); |
| 665 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 666 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 667 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 668 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 669 | |
| 670 | case STAT_CLI_O_CLR: |
| 671 | if (!ts) |
| 672 | return; |
| 673 | if (ts->ref_cnt) { |
| 674 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 675 | si->appctx.ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 676 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 677 | return; |
| 678 | } |
| 679 | stksess_kill(&px->table, ts); |
| 680 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 681 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 682 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 683 | if (ts) |
| 684 | stktable_touch(&px->table, ts, 1); |
| 685 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 686 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 687 | if (!ts) { |
| 688 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 689 | si->appctx.ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 690 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 691 | return; |
| 692 | } |
| 693 | stktable_store(&px->table, ts, 1); |
| 694 | } |
| 695 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 696 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 697 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 698 | si->appctx.ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 699 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 700 | return; |
| 701 | } |
| 702 | |
| 703 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 704 | if (data_type < 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 705 | si->appctx.ctx.cli.msg = "Unknown data type\n"; |
| 706 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 707 | return; |
| 708 | } |
| 709 | |
| 710 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 711 | si->appctx.ctx.cli.msg = "Data type not stored in this table\n"; |
| 712 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 713 | return; |
| 714 | } |
| 715 | |
| 716 | if (!*args[cur_arg+1] || strl2llrc(args[cur_arg+1], strlen(args[cur_arg+1]), &value) != 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 717 | si->appctx.ctx.cli.msg = "Require a valid integer value to store\n"; |
| 718 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 719 | return; |
| 720 | } |
| 721 | |
| 722 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 723 | |
| 724 | switch (stktable_data_types[data_type].std_type) { |
| 725 | case STD_T_SINT: |
| 726 | stktable_data_cast(ptr, std_t_sint) = value; |
| 727 | break; |
| 728 | case STD_T_UINT: |
| 729 | stktable_data_cast(ptr, std_t_uint) = value; |
| 730 | break; |
| 731 | case STD_T_ULL: |
| 732 | stktable_data_cast(ptr, std_t_ull) = value; |
| 733 | break; |
| 734 | case STD_T_FRQP: |
| 735 | /* We set both the current and previous values. That way |
| 736 | * the reported frequency is stable during all the period |
| 737 | * then slowly fades out. This allows external tools to |
| 738 | * push measures without having to update them too often. |
| 739 | */ |
| 740 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 741 | frqp->curr_tick = now_ms; |
| 742 | frqp->prev_ctr = 0; |
| 743 | frqp->curr_ctr = value; |
| 744 | break; |
| 745 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 746 | } |
| 747 | break; |
| 748 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 749 | default: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 750 | si->appctx.ctx.cli.msg = "Unknown action\n"; |
| 751 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 752 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 753 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 754 | } |
| 755 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 756 | 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] | 757 | { |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 758 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 759 | si->appctx.ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 760 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 761 | return; |
| 762 | } |
| 763 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 764 | /* condition on stored data value */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 765 | si->appctx.ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 766 | if (si->appctx.ctx.table.data_type < 0) { |
| 767 | si->appctx.ctx.cli.msg = "Unknown data type\n"; |
| 768 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 769 | return; |
| 770 | } |
| 771 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 772 | if (!((struct proxy *)si->appctx.ctx.table.target)->table.data_ofs[si->appctx.ctx.table.data_type]) { |
| 773 | si->appctx.ctx.cli.msg = "Data type not stored in this table\n"; |
| 774 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 775 | return; |
| 776 | } |
| 777 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 778 | si->appctx.ctx.table.data_op = get_std_op(args[4]); |
| 779 | if (si->appctx.ctx.table.data_op < 0) { |
| 780 | si->appctx.ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 781 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 782 | return; |
| 783 | } |
| 784 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 785 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &si->appctx.ctx.table.value) != 0) { |
| 786 | si->appctx.ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 787 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 788 | return; |
| 789 | } |
| 790 | } |
| 791 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 792 | static void stats_sock_table_request(struct stream_interface *si, char **args, int action) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 793 | { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 794 | si->appctx.ctx.table.data_type = -1; |
| 795 | si->appctx.st2 = STAT_ST_INIT; |
| 796 | si->appctx.ctx.table.target = NULL; |
| 797 | si->appctx.ctx.table.proxy = NULL; |
| 798 | si->appctx.ctx.table.entry = NULL; |
| 799 | si->appctx.st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 800 | |
| 801 | if (*args[2]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 802 | si->appctx.ctx.table.target = find_stktable(args[2]); |
| 803 | if (!si->appctx.ctx.table.target) { |
| 804 | si->appctx.ctx.cli.msg = "No such table\n"; |
| 805 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 806 | return; |
| 807 | } |
| 808 | } |
| 809 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 810 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 811 | goto err_args; |
| 812 | return; |
| 813 | } |
| 814 | |
| 815 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 816 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 817 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 818 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 819 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 820 | goto err_args; |
| 821 | |
| 822 | return; |
| 823 | |
| 824 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 825 | switch (action) { |
| 826 | case STAT_CLI_O_TAB: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 827 | si->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] | 828 | break; |
| 829 | case STAT_CLI_O_CLR: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 830 | si->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] | 831 | break; |
| 832 | default: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 833 | si->appctx.ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 834 | break; |
| 835 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 836 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 837 | } |
| 838 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 839 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 840 | * adequate error messages and returns NULL. This function also expects the session |
| 841 | * level to be admin. |
| 842 | */ |
| 843 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 844 | { |
| 845 | struct proxy *px; |
| 846 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 847 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 848 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 849 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 850 | return NULL; |
| 851 | } |
| 852 | |
| 853 | if (!*arg) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 854 | si->appctx.ctx.cli.msg = "A frontend name is expected.\n"; |
| 855 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 856 | return NULL; |
| 857 | } |
| 858 | |
| 859 | px = findproxy(arg, PR_CAP_FE); |
| 860 | if (!px) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 861 | si->appctx.ctx.cli.msg = "No such frontend.\n"; |
| 862 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 863 | return NULL; |
| 864 | } |
| 865 | return px; |
| 866 | } |
| 867 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 868 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 869 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 870 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 871 | * the <arg> is modified to remove the '/'. |
| 872 | */ |
| 873 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 874 | { |
| 875 | struct proxy *px; |
| 876 | struct server *sv; |
| 877 | char *line; |
| 878 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 879 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 880 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 881 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 882 | return NULL; |
| 883 | } |
| 884 | |
| 885 | /* split "backend/server" and make <line> point to server */ |
| 886 | for (line = arg; *line; line++) |
| 887 | if (*line == '/') { |
| 888 | *line++ = '\0'; |
| 889 | break; |
| 890 | } |
| 891 | |
| 892 | if (!*line || !*arg) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 893 | si->appctx.ctx.cli.msg = "Require 'backend/server'.\n"; |
| 894 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 895 | return NULL; |
| 896 | } |
| 897 | |
| 898 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 899 | si->appctx.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 900 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 901 | return NULL; |
| 902 | } |
| 903 | |
| 904 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 905 | si->appctx.ctx.cli.msg = "Proxy is disabled.\n"; |
| 906 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 907 | return NULL; |
| 908 | } |
| 909 | |
| 910 | return sv; |
| 911 | } |
| 912 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 913 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 914 | * called from an applet running in a stream interface. The function returns 1 |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 915 | * if the request was understood, otherwise zero. It sets si->appctx.st0 to a value |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 916 | * designating the function which will have to process the request, which can |
| 917 | * 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] | 918 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 919 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 920 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 921 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 922 | char *args[MAX_STATS_ARGS + 1]; |
| 923 | int arg; |
| 924 | |
| 925 | while (isspace((unsigned char)*line)) |
| 926 | line++; |
| 927 | |
| 928 | arg = 0; |
| 929 | args[arg] = line; |
| 930 | |
| 931 | while (*line && arg < MAX_STATS_ARGS) { |
| 932 | if (isspace((unsigned char)*line)) { |
| 933 | *line++ = '\0'; |
| 934 | |
| 935 | while (isspace((unsigned char)*line)) |
| 936 | line++; |
| 937 | |
| 938 | args[++arg] = line; |
| 939 | continue; |
| 940 | } |
| 941 | |
| 942 | line++; |
| 943 | } |
| 944 | |
| 945 | while (++arg <= MAX_STATS_ARGS) |
| 946 | args[arg] = line; |
| 947 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 948 | si->appctx.ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 949 | if (strcmp(args[0], "show") == 0) { |
| 950 | if (strcmp(args[1], "stat") == 0) { |
| 951 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 952 | si->appctx.ctx.stats.flags |= STAT_BOUND; |
| 953 | si->appctx.ctx.stats.iid = atoi(args[2]); |
| 954 | si->appctx.ctx.stats.type = atoi(args[3]); |
| 955 | si->appctx.ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 956 | } |
| 957 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 958 | si->appctx.st2 = STAT_ST_INIT; |
| 959 | si->appctx.st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 960 | } |
| 961 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 962 | si->appctx.st2 = STAT_ST_INIT; |
| 963 | si->appctx.st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 964 | } |
| 965 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 966 | si->appctx.st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 967 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 968 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 969 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 970 | return 1; |
| 971 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 972 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 973 | si->appctx.ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 974 | else if (*args[2]) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 975 | si->appctx.ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 976 | else |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 977 | si->appctx.ctx.sess.target = NULL; |
| 978 | si->appctx.ctx.sess.section = 0; /* start with session status */ |
| 979 | si->appctx.ctx.sess.pos = 0; |
| 980 | si->appctx.st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 981 | } |
| 982 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 983 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 984 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 985 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 986 | return 1; |
| 987 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 988 | if (*args[2]) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 989 | si->appctx.ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 990 | else |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 991 | si->appctx.ctx.errors.iid = -1; |
| 992 | si->appctx.ctx.errors.px = NULL; |
| 993 | si->appctx.st2 = STAT_ST_INIT; |
| 994 | si->appctx.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 995 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 996 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 997 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 998 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 999 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1000 | return 0; |
| 1001 | } |
| 1002 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1003 | else if (strcmp(args[0], "clear") == 0) { |
| 1004 | if (strcmp(args[1], "counters") == 0) { |
| 1005 | struct proxy *px; |
| 1006 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1007 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1008 | int clrall = 0; |
| 1009 | |
| 1010 | if (strcmp(args[2], "all") == 0) |
| 1011 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1012 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1013 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1014 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1015 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1016 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 1017 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1018 | return 1; |
| 1019 | } |
| 1020 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1021 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1022 | if (clrall) { |
| 1023 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1024 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1025 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1026 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1027 | px->be_counters.conn_max = 0; |
| 1028 | px->be_counters.p.http.rps_max = 0; |
| 1029 | px->be_counters.sps_max = 0; |
| 1030 | px->be_counters.cps_max = 0; |
| 1031 | px->be_counters.nbpend_max = 0; |
| 1032 | |
| 1033 | px->fe_counters.conn_max = 0; |
| 1034 | px->fe_counters.p.http.rps_max = 0; |
| 1035 | px->fe_counters.sps_max = 0; |
| 1036 | px->fe_counters.cps_max = 0; |
| 1037 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1038 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1039 | |
| 1040 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1041 | if (clrall) |
| 1042 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1043 | else { |
| 1044 | sv->counters.cur_sess_max = 0; |
| 1045 | sv->counters.nbpend_max = 0; |
| 1046 | sv->counters.sps_max = 0; |
| 1047 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1048 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1049 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1050 | if (li->counters) { |
| 1051 | if (clrall) |
| 1052 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1053 | else |
| 1054 | li->counters->conn_max = 0; |
| 1055 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1056 | } |
| 1057 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1058 | global.cps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1059 | return 1; |
| 1060 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1061 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1062 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1063 | /* end of processing */ |
| 1064 | return 1; |
| 1065 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1066 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1067 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1068 | return 0; |
| 1069 | } |
| 1070 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1071 | else if (strcmp(args[0], "get") == 0) { |
| 1072 | if (strcmp(args[1], "weight") == 0) { |
| 1073 | struct proxy *px; |
| 1074 | struct server *sv; |
| 1075 | |
| 1076 | /* split "backend/server" and make <line> point to server */ |
| 1077 | for (line = args[2]; *line; line++) |
| 1078 | if (*line == '/') { |
| 1079 | *line++ = '\0'; |
| 1080 | break; |
| 1081 | } |
| 1082 | |
| 1083 | if (!*line) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1084 | si->appctx.ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1085 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1086 | return 1; |
| 1087 | } |
| 1088 | |
| 1089 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1090 | si->appctx.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1091 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1092 | return 1; |
| 1093 | } |
| 1094 | |
| 1095 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1096 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1097 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1098 | return 1; |
| 1099 | } |
| 1100 | else { /* not "get weight" */ |
| 1101 | return 0; |
| 1102 | } |
| 1103 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1104 | else if (strcmp(args[0], "set") == 0) { |
| 1105 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1106 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1107 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1108 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1109 | sv = expect_server_admin(s, si, args[2]); |
| 1110 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1111 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1112 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1113 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1114 | /* |
| 1115 | * The user-weight may now be zero and thus |
| 1116 | * the server considered to be draining. |
| 1117 | * Update the server's drain state as necessary. |
| 1118 | */ |
| 1119 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1120 | if (warning) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1121 | si->appctx.ctx.cli.msg = warning; |
| 1122 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1123 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1124 | return 1; |
| 1125 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1126 | else if (strcmp(args[1], "timeout") == 0) { |
| 1127 | if (strcmp(args[2], "cli") == 0) { |
| 1128 | unsigned timeout; |
| 1129 | const char *res; |
| 1130 | |
| 1131 | if (!*args[3]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1132 | si->appctx.ctx.cli.msg = "Expects an integer value.\n"; |
| 1133 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1134 | return 1; |
| 1135 | } |
| 1136 | |
| 1137 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1138 | if (res || timeout < 1) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1139 | si->appctx.ctx.cli.msg = "Invalid timeout value.\n"; |
| 1140 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1141 | return 1; |
| 1142 | } |
| 1143 | |
| 1144 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1145 | return 1; |
| 1146 | } |
| 1147 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1148 | si->appctx.ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1149 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1150 | return 1; |
| 1151 | } |
| 1152 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1153 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1154 | if (strcmp(args[2], "frontend") == 0) { |
| 1155 | struct proxy *px; |
| 1156 | struct listener *l; |
| 1157 | int v; |
| 1158 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1159 | px = expect_frontend_admin(s, si, args[3]); |
| 1160 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1161 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1162 | |
| 1163 | if (!*args[4]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1164 | si->appctx.ctx.cli.msg = "Integer value expected.\n"; |
| 1165 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1166 | return 1; |
| 1167 | } |
| 1168 | |
| 1169 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1170 | if (v < 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1171 | si->appctx.ctx.cli.msg = "Value out of range.\n"; |
| 1172 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1173 | return 1; |
| 1174 | } |
| 1175 | |
| 1176 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1177 | * its listeners. The blocked ones will be dequeued. |
| 1178 | */ |
| 1179 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1180 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1181 | l->maxconn = v; |
| 1182 | if (l->state == LI_FULL) |
| 1183 | resume_listener(l); |
| 1184 | } |
| 1185 | |
| 1186 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1187 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1188 | |
| 1189 | return 1; |
| 1190 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1191 | else if (strcmp(args[2], "global") == 0) { |
| 1192 | int v; |
| 1193 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1194 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1195 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 1196 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1197 | return 1; |
| 1198 | } |
| 1199 | |
| 1200 | if (!*args[3]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1201 | si->appctx.ctx.cli.msg = "Expects an integer value.\n"; |
| 1202 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1203 | return 1; |
| 1204 | } |
| 1205 | |
| 1206 | v = atoi(args[3]); |
| 1207 | if (v > global.hardmaxconn) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1208 | si->appctx.ctx.cli.msg = "Value out of range.\n"; |
| 1209 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1210 | return 1; |
| 1211 | } |
| 1212 | |
| 1213 | /* check for unlimited values */ |
| 1214 | if (v <= 0) |
| 1215 | v = global.hardmaxconn; |
| 1216 | |
| 1217 | global.maxconn = v; |
| 1218 | |
| 1219 | /* Dequeues all of the listeners waiting for a resource */ |
| 1220 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1221 | dequeue_all_listeners(&global_listener_queue); |
| 1222 | |
| 1223 | return 1; |
| 1224 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1225 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1226 | si->appctx.ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1227 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1228 | return 1; |
| 1229 | } |
| 1230 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1231 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1232 | if (strcmp(args[2], "connections") == 0) { |
| 1233 | if (strcmp(args[3], "global") == 0) { |
| 1234 | int v; |
| 1235 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1236 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1237 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 1238 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1239 | return 1; |
| 1240 | } |
| 1241 | |
| 1242 | if (!*args[4]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1243 | si->appctx.ctx.cli.msg = "Expects an integer value.\n"; |
| 1244 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1245 | return 1; |
| 1246 | } |
| 1247 | |
| 1248 | v = atoi(args[4]); |
| 1249 | if (v < 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1250 | si->appctx.ctx.cli.msg = "Value out of range.\n"; |
| 1251 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1252 | return 1; |
| 1253 | } |
| 1254 | |
| 1255 | global.cps_lim = v; |
| 1256 | |
| 1257 | /* Dequeues all of the listeners waiting for a resource */ |
| 1258 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1259 | dequeue_all_listeners(&global_listener_queue); |
| 1260 | |
| 1261 | return 1; |
| 1262 | } |
| 1263 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1264 | si->appctx.ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1265 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1266 | return 1; |
| 1267 | } |
| 1268 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1269 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1270 | if (strcmp(args[3], "global") == 0) { |
| 1271 | int v; |
| 1272 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1273 | if (!*args[4]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1274 | si->appctx.ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1275 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1276 | return 1; |
| 1277 | } |
| 1278 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1279 | v = atoi(args[4]); |
| 1280 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1281 | } |
| 1282 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1283 | si->appctx.ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1284 | si->appctx.st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1285 | return 1; |
| 1286 | } |
| 1287 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1288 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1289 | si->appctx.ctx.cli.msg = "'set rate-limit' supports 'connections' and 'http-compression'.\n"; |
| 1290 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1291 | return 1; |
| 1292 | } |
| 1293 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1294 | else if (strcmp(args[1], "table") == 0) { |
| 1295 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1296 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1297 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1298 | return 0; |
| 1299 | } |
| 1300 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1301 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1302 | if (strcmp(args[1], "agent") == 0) { |
| 1303 | struct server *sv; |
| 1304 | |
| 1305 | sv = expect_server_admin(s, si, args[2]); |
| 1306 | if (!sv) |
| 1307 | return 1; |
| 1308 | |
| 1309 | sv->agent.state &= ~CHK_STATE_DISABLED; |
| 1310 | |
| 1311 | return 1; |
| 1312 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1313 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1314 | struct server *sv; |
| 1315 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1316 | sv = expect_server_admin(s, si, args[2]); |
| 1317 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1318 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1319 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1320 | if (sv->state & SRV_MAINTAIN) { |
| 1321 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1322 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1323 | /* If this server tracks the status of another one, |
| 1324 | * we must restore the good status. |
| 1325 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1326 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1327 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1328 | 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] | 1329 | } else { |
| 1330 | sv->state &= ~SRV_MAINTAIN; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1331 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1332 | } |
| 1333 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1334 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1335 | 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] | 1336 | } |
| 1337 | } |
| 1338 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1339 | return 1; |
| 1340 | } |
| 1341 | else if (strcmp(args[1], "frontend") == 0) { |
| 1342 | struct proxy *px; |
| 1343 | |
| 1344 | px = expect_frontend_admin(s, si, args[2]); |
| 1345 | if (!px) |
| 1346 | return 1; |
| 1347 | |
| 1348 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1349 | si->appctx.ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1350 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1351 | return 1; |
| 1352 | } |
| 1353 | |
| 1354 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1355 | si->appctx.ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1356 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1357 | return 1; |
| 1358 | } |
| 1359 | |
| 1360 | if (!resume_proxy(px)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1361 | si->appctx.ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1362 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1363 | return 1; |
| 1364 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1365 | return 1; |
| 1366 | } |
| 1367 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1368 | si->appctx.ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1369 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1370 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1371 | } |
| 1372 | } |
| 1373 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1374 | if (strcmp(args[1], "agent") == 0) { |
| 1375 | struct server *sv; |
| 1376 | |
| 1377 | sv = expect_server_admin(s, si, args[2]); |
| 1378 | if (!sv) |
| 1379 | return 1; |
| 1380 | |
| 1381 | sv->agent.state |= CHK_STATE_DISABLED; |
| 1382 | |
| 1383 | return 1; |
| 1384 | } |
| 1385 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1386 | struct server *sv; |
| 1387 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1388 | sv = expect_server_admin(s, si, args[2]); |
| 1389 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1390 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1391 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1392 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1393 | /* Not already in maintenance, we can change the server state */ |
| 1394 | sv->state |= SRV_MAINTAIN; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1395 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1398 | return 1; |
| 1399 | } |
| 1400 | else if (strcmp(args[1], "frontend") == 0) { |
| 1401 | struct proxy *px; |
| 1402 | |
| 1403 | px = expect_frontend_admin(s, si, args[2]); |
| 1404 | if (!px) |
| 1405 | return 1; |
| 1406 | |
| 1407 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1408 | si->appctx.ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1409 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1410 | return 1; |
| 1411 | } |
| 1412 | |
| 1413 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1414 | si->appctx.ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1415 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1416 | return 1; |
| 1417 | } |
| 1418 | |
| 1419 | if (!pause_proxy(px)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1420 | si->appctx.ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1421 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1422 | return 1; |
| 1423 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1424 | return 1; |
| 1425 | } |
| 1426 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1427 | si->appctx.ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1428 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1429 | return 1; |
| 1430 | } |
| 1431 | } |
| 1432 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1433 | if (strcmp(args[1], "frontend") == 0) { |
| 1434 | struct proxy *px; |
| 1435 | |
| 1436 | px = expect_frontend_admin(s, si, args[2]); |
| 1437 | if (!px) |
| 1438 | return 1; |
| 1439 | |
| 1440 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1441 | si->appctx.ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1442 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1443 | return 1; |
| 1444 | } |
| 1445 | |
| 1446 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1447 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1448 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1449 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1450 | stop_proxy(px); |
| 1451 | return 1; |
| 1452 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1453 | else if (strcmp(args[1], "session") == 0) { |
| 1454 | struct session *sess, *ptr; |
| 1455 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1456 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1457 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 1458 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1459 | return 1; |
| 1460 | } |
| 1461 | |
| 1462 | if (!*args[2]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1463 | si->appctx.ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1464 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1465 | return 1; |
| 1466 | } |
| 1467 | |
| 1468 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1469 | |
| 1470 | /* first, look for the requested session in the session table */ |
| 1471 | list_for_each_entry(sess, &sessions, list) { |
| 1472 | if (sess == ptr) |
| 1473 | break; |
| 1474 | } |
| 1475 | |
| 1476 | /* do we have the session ? */ |
| 1477 | if (sess != ptr) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1478 | si->appctx.ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1479 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1480 | return 1; |
| 1481 | } |
| 1482 | |
| 1483 | session_shutdown(sess, SN_ERR_KILLED); |
| 1484 | return 1; |
| 1485 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1486 | else if (strcmp(args[1], "sessions") == 0) { |
| 1487 | if (strcmp(args[2], "server") == 0) { |
| 1488 | struct server *sv; |
| 1489 | struct session *sess, *sess_bck; |
| 1490 | |
| 1491 | sv = expect_server_admin(s, si, args[3]); |
| 1492 | if (!sv) |
| 1493 | return 1; |
| 1494 | |
| 1495 | /* kill all the session that are on this server */ |
| 1496 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1497 | if (sess->srv_conn == sv) |
| 1498 | session_shutdown(sess, SN_ERR_KILLED); |
| 1499 | |
| 1500 | return 1; |
| 1501 | } |
| 1502 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1503 | si->appctx.ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1504 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1505 | return 1; |
| 1506 | } |
| 1507 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1508 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1509 | si->appctx.ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1510 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1511 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1512 | } |
| 1513 | } |
| 1514 | 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] | 1515 | return 0; |
| 1516 | } |
| 1517 | return 1; |
| 1518 | } |
| 1519 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1520 | /* 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] | 1521 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 1522 | * state machine handling requests and various responses. We read a request, |
| 1523 | * then we process it and send the response, and we possibly display a prompt. |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1524 | * Then we can read again. The state is stored in si->appctx.st0 and is one of the |
| 1525 | * STAT_CLI_* constants. si->appctx.st1 is used to indicate whether prompt is enabled |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1526 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1527 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 1528 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1529 | { |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1530 | struct channel *req = si->ob; |
| 1531 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1532 | int reql; |
| 1533 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1534 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1535 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 1536 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1537 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1538 | while (1) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1539 | if (si->appctx.st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1540 | /* Stats output not initialized yet */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1541 | memset(&si->appctx.ctx.stats, 0, sizeof(si->appctx.ctx.stats)); |
| 1542 | si->appctx.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1543 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1544 | else if (si->appctx.st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1545 | /* Let's close for real now. We just close the request |
| 1546 | * side, the conditions below will complete if needed. |
| 1547 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1548 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1549 | break; |
| 1550 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1551 | else if (si->appctx.st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1552 | /* ensure we have some output room left in the event we |
| 1553 | * would want to return some info right after parsing. |
| 1554 | */ |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1555 | if (buffer_almost_full(si->ib->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1556 | break; |
| 1557 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1558 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1559 | if (reql <= 0) { /* closed or EOL not found */ |
| 1560 | if (reql == 0) |
| 1561 | break; |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1562 | si->appctx.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1563 | continue; |
| 1564 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1565 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1566 | /* seek for a possible semi-colon. If we find one, we |
| 1567 | * replace it with an LF and skip only this part. |
| 1568 | */ |
| 1569 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1570 | if (trash.str[len] == ';') { |
| 1571 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1572 | reql = len + 1; |
| 1573 | break; |
| 1574 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1575 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1576 | /* now it is time to check that we have a full line, |
| 1577 | * remove the trailing \n and possibly \r, then cut the |
| 1578 | * line. |
| 1579 | */ |
| 1580 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1581 | if (trash.str[len] != '\n') { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1582 | si->appctx.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1583 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1584 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1585 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1586 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1587 | len--; |
| 1588 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1589 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1590 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1591 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1592 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1593 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1594 | si->appctx.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1595 | continue; |
| 1596 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1597 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1598 | si->appctx.st1 = !si->appctx.st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1599 | else if (strcmp(trash.str, "help") == 0 || |
| 1600 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1601 | si->appctx.ctx.cli.msg = stats_sock_usage_msg; |
| 1602 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1603 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1604 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1605 | * another STAT_CLI_O_* into si->appctx.st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1606 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1607 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1608 | else if (!si->appctx.st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1609 | /* if prompt is disabled, print help on empty lines, |
| 1610 | * so that the user at least knows how to enable |
| 1611 | * prompt and find help. |
| 1612 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1613 | si->appctx.ctx.cli.msg = stats_sock_usage_msg; |
| 1614 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1618 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1619 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1620 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1621 | 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] | 1622 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1623 | si->appctx.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1624 | continue; |
| 1625 | } |
| 1626 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1627 | switch (si->appctx.st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1628 | case STAT_CLI_PRINT: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1629 | if (bi_putstr(si->ib, si->appctx.ctx.cli.msg) != -1) |
| 1630 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1631 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1632 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1633 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1634 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1635 | break; |
| 1636 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1637 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1638 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1639 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1640 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1641 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1642 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1643 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1644 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1645 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1646 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1647 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1648 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1649 | case STAT_CLI_O_CLR: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1650 | if (stats_table_request(si, si->appctx.st0)) |
| 1651 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1652 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1653 | default: /* abnormal state */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1654 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1655 | break; |
| 1656 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1657 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1658 | /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1659 | if (si->appctx.st0 == STAT_CLI_PROMPT) { |
| 1660 | if (bi_putstr(si->ib, si->appctx.st1 ? "\n> " : "\n") != -1) |
| 1661 | si->appctx.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1662 | } |
| 1663 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1664 | /* If the output functions are still there, it means they require more room. */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1665 | if (si->appctx.st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1666 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1667 | |
| 1668 | /* Now we close the output if one of the writers did so, |
| 1669 | * or if we're not in interactive mode and the request |
| 1670 | * buffer is empty. This still allows pipelined requests |
| 1671 | * to be sent in non-interactive mode. |
| 1672 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1673 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!si->appctx.st1 && !req->buf->o)) { |
| 1674 | si->appctx.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1675 | continue; |
| 1676 | } |
| 1677 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1678 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1679 | si->appctx.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1680 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1681 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1682 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1683 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST) && (si->appctx.st0 != STAT_CLI_GETREQ)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1684 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 1685 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1686 | /* 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] | 1687 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 1688 | * we forward the close to the request side so that it flows upstream to |
| 1689 | * the client. |
| 1690 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1691 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1692 | } |
| 1693 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1694 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && (si->appctx.st0 < STAT_CLI_OUTPUT)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1695 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 1696 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 1697 | /* We have no more processing to do, and nothing more to send, and |
| 1698 | * the client side has closed. So we'll forward this state downstream |
| 1699 | * on the response buffer. |
| 1700 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1701 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1702 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1706 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1707 | |
| 1708 | /* we don't want to expire timeouts while we're processing requests */ |
| 1709 | si->ib->rex = TICK_ETERNITY; |
| 1710 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1711 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1712 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1713 | 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] | 1714 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1715 | 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] | 1716 | |
| 1717 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 1718 | /* check that we have released everything then unregister */ |
| 1719 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1720 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1721 | } |
| 1722 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1723 | /* This function dumps information onto the stream interface's read buffer. |
| 1724 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 1725 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1726 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1727 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1728 | { |
| 1729 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 1730 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1731 | chunk_printf(&trash, |
| 1732 | "Name: " PRODUCT_NAME "\n" |
| 1733 | "Version: " HAPROXY_VERSION "\n" |
| 1734 | "Release_date: " HAPROXY_DATE "\n" |
| 1735 | "Nbproc: %d\n" |
| 1736 | "Process_num: %d\n" |
| 1737 | "Pid: %d\n" |
| 1738 | "Uptime: %dd %dh%02dm%02ds\n" |
| 1739 | "Uptime_sec: %d\n" |
| 1740 | "Memmax_MB: %d\n" |
| 1741 | "Ulimit-n: %d\n" |
| 1742 | "Maxsock: %d\n" |
| 1743 | "Maxconn: %d\n" |
| 1744 | "Hard_maxconn: %d\n" |
| 1745 | "Maxpipes: %d\n" |
| 1746 | "CurrConns: %d\n" |
| 1747 | "PipesUsed: %d\n" |
| 1748 | "PipesFree: %d\n" |
| 1749 | "ConnRate: %d\n" |
| 1750 | "ConnRateLimit: %d\n" |
| 1751 | "MaxConnRate: %d\n" |
| 1752 | "CompressBpsIn: %u\n" |
| 1753 | "CompressBpsOut: %u\n" |
| 1754 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1755 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1756 | "ZlibMemUsage: %ld\n" |
| 1757 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1758 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1759 | "Tasks: %d\n" |
| 1760 | "Run_queue: %d\n" |
| 1761 | "Idle_pct: %d\n" |
| 1762 | "node: %s\n" |
| 1763 | "description: %s\n" |
| 1764 | "", |
| 1765 | global.nbproc, |
| 1766 | relative_pid, |
| 1767 | pid, |
| 1768 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 1769 | up, |
| 1770 | global.rlimit_memmax, |
| 1771 | global.rlimit_nofile, |
| 1772 | global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes, |
| 1773 | actconn, pipes_used, pipes_free, |
| 1774 | read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max, |
| 1775 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 1776 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1777 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1778 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1779 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1780 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 1781 | global.node, global.desc ? global.desc : "" |
| 1782 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1783 | |
| 1784 | if (bi_putchk(si->ib, &trash) == -1) |
| 1785 | return 0; |
| 1786 | |
| 1787 | return 1; |
| 1788 | } |
| 1789 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1790 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 1791 | * the state from stream interface <si>. The caller is responsible for clearing |
| 1792 | * 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] | 1793 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1794 | 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] | 1795 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1796 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1797 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1798 | if (!(px->cap & PR_CAP_FE)) |
| 1799 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1800 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1801 | if ((si->appctx.ctx.stats.flags & STAT_BOUND) && !(si->appctx.ctx.stats.type & (1 << STATS_TYPE_FE))) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1802 | return 0; |
| 1803 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1804 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1805 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1806 | /* name, queue */ |
| 1807 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1808 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1809 | if (px->cap & PR_CAP_BE && px->srv && (si->appctx.ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1810 | /* Column sub-heading for Enable or Disable server */ |
| 1811 | chunk_appendf(&trash, "<td></td>"); |
| 1812 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1813 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1814 | chunk_appendf(&trash, |
| 1815 | "<td class=ac>" |
| 1816 | "<a name=\"%s/Frontend\"></a>" |
| 1817 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 1818 | "<td colspan=3></td>" |
| 1819 | "", |
| 1820 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1821 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1822 | chunk_appendf(&trash, |
| 1823 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1824 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1825 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 1826 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 1827 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1828 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 1829 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 1830 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1831 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1832 | if (px->mode == PR_MODE_HTTP) |
| 1833 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1834 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1835 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1836 | |
| 1837 | chunk_appendf(&trash, |
| 1838 | "</table></div></u></td>" |
| 1839 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1840 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1841 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 1842 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 1843 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1844 | U2H(px->fe_counters.sps_max), |
| 1845 | U2H(px->fe_counters.cps_max), |
| 1846 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1847 | |
| 1848 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1849 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1850 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1851 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1852 | |
| 1853 | chunk_appendf(&trash, |
| 1854 | "</table></div></u></td>" |
| 1855 | /* sessions rate : limit */ |
| 1856 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1857 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1858 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1859 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1860 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1861 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1862 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1863 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 1864 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1865 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1866 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 1867 | U2H(px->fe_counters.cum_sess), |
| 1868 | U2H(px->fe_counters.cum_conn), |
| 1869 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1870 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1871 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1872 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1873 | chunk_appendf(&trash, |
| 1874 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 1875 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 1876 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 1877 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1878 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 1879 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 1880 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 1881 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 1882 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 1883 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1884 | U2H(px->fe_counters.p.http.cum_req), |
| 1885 | U2H(px->fe_counters.p.http.rsp[1]), |
| 1886 | U2H(px->fe_counters.p.http.rsp[2]), |
| 1887 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1888 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1889 | (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] | 1890 | U2H(px->fe_counters.p.http.rsp[3]), |
| 1891 | U2H(px->fe_counters.p.http.rsp[4]), |
| 1892 | U2H(px->fe_counters.p.http.rsp[5]), |
| 1893 | U2H(px->fe_counters.p.http.rsp[0]), |
| 1894 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1895 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1896 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1897 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1898 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1899 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1900 | "<td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1901 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1902 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1903 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1904 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1905 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1906 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1907 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1908 | "<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] | 1909 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1910 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1911 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 1912 | px->fe_counters.comp_in ? |
| 1913 | (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] | 1914 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1915 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1916 | chunk_appendf(&trash, |
| 1917 | /* denied: req, resp */ |
| 1918 | "<td>%s</td><td>%s</td>" |
| 1919 | /* errors : request, connect, response */ |
| 1920 | "<td>%s</td><td></td><td></td>" |
| 1921 | /* warnings: retries, redispatches */ |
| 1922 | "<td></td><td></td>" |
| 1923 | /* server status : reflect frontend status */ |
| 1924 | "<td class=ac>%s</td>" |
| 1925 | /* rest of server: nothing */ |
| 1926 | "<td class=ac colspan=8></td></tr>" |
| 1927 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1928 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 1929 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1930 | px->state == PR_STREADY ? "OPEN" : |
| 1931 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1932 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1933 | else { /* CSV mode */ |
| 1934 | chunk_appendf(&trash, |
| 1935 | /* pxid, name, queue cur, queue max, */ |
| 1936 | "%s,FRONTEND,,," |
| 1937 | /* sessions : current, max, limit, total */ |
| 1938 | "%d,%d,%d,%lld," |
| 1939 | /* bytes : in, out */ |
| 1940 | "%lld,%lld," |
| 1941 | /* denied: req, resp */ |
| 1942 | "%lld,%lld," |
| 1943 | /* errors : request, connect, response */ |
| 1944 | "%lld,,," |
| 1945 | /* warnings: retries, redispatches */ |
| 1946 | ",," |
| 1947 | /* server status : reflect frontend status */ |
| 1948 | "%s," |
| 1949 | /* rest of server: nothing */ |
| 1950 | ",,,,,,,," |
| 1951 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 1952 | "%d,%d,0,,,,%d," |
| 1953 | /* rate, rate_lim, rate_max */ |
| 1954 | "%u,%u,%u," |
| 1955 | /* check_status, check_code, check_duration */ |
| 1956 | ",,,", |
| 1957 | px->id, |
| 1958 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 1959 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 1960 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 1961 | px->fe_counters.failed_req, |
| 1962 | px->state == PR_STREADY ? "OPEN" : |
| 1963 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 1964 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 1965 | read_freq_ctr(&px->fe_sess_per_sec), |
| 1966 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1967 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1968 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1969 | if (px->mode == PR_MODE_HTTP) { |
| 1970 | for (i=1; i<6; i++) |
| 1971 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 1972 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 1973 | } |
| 1974 | else |
| 1975 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1976 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1977 | /* failed health analyses */ |
| 1978 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1979 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1980 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 1981 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 1982 | read_freq_ctr(&px->fe_req_per_sec), |
| 1983 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 1984 | |
| 1985 | /* errors: cli_aborts, srv_aborts */ |
| 1986 | chunk_appendf(&trash, ",,"); |
| 1987 | |
| 1988 | /* compression: in, out, bypassed */ |
| 1989 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 1990 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 1991 | |
| 1992 | /* compression: comp_rsp */ |
| 1993 | chunk_appendf(&trash, "%lld,", |
| 1994 | px->fe_counters.p.http.comp_rsp); |
| 1995 | |
| 1996 | /* finish with EOL */ |
| 1997 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1998 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1999 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2000 | } |
| 2001 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2002 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2003 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2004 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2005 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2006 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2007 | 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] | 2008 | { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2009 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2010 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2011 | if (px->cap & PR_CAP_BE && px->srv && (si->appctx.ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2012 | /* Column sub-heading for Enable or Disable server */ |
| 2013 | chunk_appendf(&trash, "<td></td>"); |
| 2014 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2015 | chunk_appendf(&trash, |
| 2016 | /* frontend name, listener name */ |
| 2017 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2018 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2019 | "", |
| 2020 | px->id, l->name, |
| 2021 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2022 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2023 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2024 | if (flags & ST_SHLGNDS) { |
| 2025 | char str[INET6_ADDRSTRLEN]; |
| 2026 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2027 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2028 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2029 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2030 | port = get_host_port(&l->addr); |
| 2031 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2032 | case AF_INET: |
| 2033 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2034 | break; |
| 2035 | case AF_INET6: |
| 2036 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2037 | break; |
| 2038 | case AF_UNIX: |
| 2039 | chunk_appendf(&trash, "unix, "); |
| 2040 | break; |
| 2041 | case -1: |
| 2042 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2043 | break; |
| 2044 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2045 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2046 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2047 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2048 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2049 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2050 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2051 | /* queue */ |
| 2052 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2053 | /* sessions rate: current, max, limit */ |
| 2054 | "<td colspan=3> </td>" |
| 2055 | /* sessions: current, max, limit, total, lbtot */ |
| 2056 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2057 | "<td>%s</td><td> </td>" |
| 2058 | /* bytes: in, out */ |
| 2059 | "<td>%s</td><td>%s</td>" |
| 2060 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2061 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2062 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2063 | 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] | 2064 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2065 | chunk_appendf(&trash, |
| 2066 | /* denied: req, resp */ |
| 2067 | "<td>%s</td><td>%s</td>" |
| 2068 | /* errors: request, connect, response */ |
| 2069 | "<td>%s</td><td></td><td></td>" |
| 2070 | /* warnings: retries, redispatches */ |
| 2071 | "<td></td><td></td>" |
| 2072 | /* server status: reflect listener status */ |
| 2073 | "<td class=ac>%s</td>" |
| 2074 | /* rest of server: nothing */ |
| 2075 | "<td class=ac colspan=8></td></tr>" |
| 2076 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2077 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2078 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2079 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2080 | } |
| 2081 | else { /* CSV mode */ |
| 2082 | chunk_appendf(&trash, |
| 2083 | /* pxid, name, queue cur, queue max, */ |
| 2084 | "%s,%s,,," |
| 2085 | /* sessions: current, max, limit, total */ |
| 2086 | "%d,%d,%d,%lld," |
| 2087 | /* bytes: in, out */ |
| 2088 | "%lld,%lld," |
| 2089 | /* denied: req, resp */ |
| 2090 | "%lld,%lld," |
| 2091 | /* errors: request, connect, response */ |
| 2092 | "%lld,,," |
| 2093 | /* warnings: retries, redispatches */ |
| 2094 | ",," |
| 2095 | /* server status: reflect listener status */ |
| 2096 | "%s," |
| 2097 | /* rest of server: nothing */ |
| 2098 | ",,,,,,,," |
| 2099 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2100 | "%d,%d,%d,,,,%d," |
| 2101 | /* rate, rate_lim, rate_max */ |
| 2102 | ",,," |
| 2103 | /* check_status, check_code, check_duration */ |
| 2104 | ",,," |
| 2105 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2106 | ",,,,,," |
| 2107 | /* failed health analyses */ |
| 2108 | "," |
| 2109 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2110 | ",,," |
| 2111 | /* errors: cli_aborts, srv_aborts */ |
| 2112 | ",," |
| 2113 | /* compression: in, out, bypassed, comp_rsp */ |
| 2114 | ",,,," |
| 2115 | "\n", |
| 2116 | px->id, l->name, |
| 2117 | l->nbconn, l->counters->conn_max, |
| 2118 | l->maxconn, l->counters->cum_conn, |
| 2119 | l->counters->bytes_in, l->counters->bytes_out, |
| 2120 | l->counters->denied_req, l->counters->denied_resp, |
| 2121 | l->counters->failed_req, |
| 2122 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2123 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2124 | } |
| 2125 | return 1; |
| 2126 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2127 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2128 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2129 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2130 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2131 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2132 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2133 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2134 | */ |
| 2135 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2136 | { |
| 2137 | struct server *ref = sv->track ? sv->track : sv; |
| 2138 | char str[INET6_ADDRSTRLEN]; |
| 2139 | struct chunk src; |
| 2140 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2141 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2142 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2143 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2144 | "DOWN", |
| 2145 | "DN %d/%d ↑", |
| 2146 | "UP %d/%d ↓", |
| 2147 | "UP", |
| 2148 | "NOLB %d/%d ↓", |
| 2149 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2150 | "DRAIN %d/%d ↓", |
| 2151 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2152 | "<i>no check</i>" |
| 2153 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2154 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2155 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2156 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2157 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2158 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2159 | "<tr class=\"%s%d\">", |
| 2160 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2161 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2162 | if ((px->cap & PR_CAP_BE) && px->srv && (si->appctx.ctx.stats.flags & STAT_ADMIN)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2163 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2164 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2165 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2166 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2167 | chunk_appendf(&trash, |
| 2168 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2169 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2170 | "", |
| 2171 | px->id, sv->id, |
| 2172 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2173 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2174 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2175 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2176 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2177 | |
| 2178 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2179 | case AF_INET: |
| 2180 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2181 | break; |
| 2182 | case AF_INET6: |
| 2183 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2184 | break; |
| 2185 | case AF_UNIX: |
| 2186 | chunk_appendf(&trash, "unix, "); |
| 2187 | break; |
| 2188 | case -1: |
| 2189 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2190 | break; |
| 2191 | default: /* address family not supported */ |
| 2192 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2193 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2194 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2195 | /* id */ |
| 2196 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2197 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2198 | /* cookie */ |
| 2199 | if (sv->cookie) { |
| 2200 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2201 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2202 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2203 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2204 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2205 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2206 | } |
| 2207 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2208 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2209 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2210 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2211 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2212 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2213 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2214 | /* sessions rate : current, max, limit */ |
| 2215 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2216 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2217 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2218 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2219 | 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] | 2220 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2221 | |
| 2222 | chunk_appendf(&trash, |
| 2223 | /* sessions: current, max, limit, total */ |
| 2224 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2225 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2226 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2227 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2228 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2229 | U2H(sv->counters.cum_sess), |
| 2230 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2231 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2232 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2233 | if (px->mode == PR_MODE_HTTP) { |
| 2234 | unsigned long long tot; |
| 2235 | for (tot = i = 0; i < 6; i++) |
| 2236 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2237 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2238 | chunk_appendf(&trash, |
| 2239 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2240 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2241 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2242 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2243 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2244 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2245 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2246 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2247 | U2H(tot), |
| 2248 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2249 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2250 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2251 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2252 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2253 | 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] | 2254 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2255 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2256 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2257 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2258 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2259 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2260 | U2H(sv->counters.cum_lbconn)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2261 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2262 | chunk_appendf(&trash, |
| 2263 | /* bytes : in, out */ |
| 2264 | "<td>%s</td><td>%s</td>" |
| 2265 | /* denied: req, resp */ |
| 2266 | "<td></td><td>%s</td>" |
| 2267 | /* errors : request, connect */ |
| 2268 | "<td></td><td>%s</td>" |
| 2269 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2270 | "<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] | 2271 | /* warnings: retries, redispatches */ |
| 2272 | "<td>%lld</td><td>%lld</td>" |
| 2273 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2274 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2275 | U2H(sv->counters.failed_secu), |
| 2276 | U2H(sv->counters.failed_conns), |
| 2277 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2278 | sv->counters.cli_aborts, |
| 2279 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2280 | sv->counters.retries, sv->counters.redispatches); |
| 2281 | |
| 2282 | /* status, lest check */ |
| 2283 | chunk_appendf(&trash, "<td class=ac>"); |
| 2284 | |
| 2285 | if (sv->state & SRV_MAINTAIN) { |
| 2286 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2287 | chunk_appendf(&trash, "MAINT"); |
| 2288 | } |
| 2289 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2290 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2291 | chunk_appendf(&trash, "MAINT(via)"); |
| 2292 | } |
| 2293 | else if (ref->state & SRV_CHECKED) { |
| 2294 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2295 | chunk_appendf(&trash, |
| 2296 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2297 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2298 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2299 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2300 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2301 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2302 | chunk_appendf(&trash, |
| 2303 | "</td><td class=ac><u> %s%s", |
Simon Horman | cd5d7b6 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 2304 | (sv->check.state & CHK_STATE_RUNNING) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2305 | get_check_status_info(sv->check.status)); |
| 2306 | |
| 2307 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2308 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2309 | |
| 2310 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2311 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2312 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2313 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2314 | get_check_status_description(sv->check.status)); |
| 2315 | if (*sv->check.desc) { |
| 2316 | chunk_appendf(&trash, ": "); |
| 2317 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2318 | chunk_htmlencode(&trash, &src); |
| 2319 | } |
| 2320 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2321 | } |
| 2322 | else |
| 2323 | chunk_appendf(&trash, "</td><td>"); |
| 2324 | |
| 2325 | chunk_appendf(&trash, |
| 2326 | /* weight */ |
| 2327 | "</td><td class=ac>%d</td>" |
| 2328 | /* act, bck */ |
| 2329 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2330 | "", |
| 2331 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2332 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2333 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2334 | |
| 2335 | /* check failures: unique, fatal, down time */ |
| 2336 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2337 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2338 | |
| 2339 | if (ref->observe) |
| 2340 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2341 | |
| 2342 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2343 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2344 | "<td>%lld</td><td>%s</td>" |
| 2345 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2346 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2347 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2348 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2349 | else if (sv != ref) { |
| 2350 | if (sv->state & SRV_MAINTAIN) |
| 2351 | chunk_appendf(&trash, |
| 2352 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2353 | ref->proxy->id, ref->id); |
| 2354 | else |
| 2355 | chunk_appendf(&trash, |
| 2356 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2357 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2358 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2359 | else |
| 2360 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2361 | |
| 2362 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2363 | if (sv->state & SRV_WARMINGUP) |
| 2364 | 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] | 2365 | else |
| 2366 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2367 | } |
| 2368 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2369 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2370 | "DOWN,", |
| 2371 | "DOWN %d/%d,", |
| 2372 | "UP %d/%d,", |
| 2373 | "UP,", |
| 2374 | "NOLB %d/%d,", |
| 2375 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2376 | "DRAIN %d/%d,", |
| 2377 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2378 | "no check," |
| 2379 | }; |
| 2380 | |
| 2381 | chunk_appendf(&trash, |
| 2382 | /* pxid, name */ |
| 2383 | "%s,%s," |
| 2384 | /* queue : current, max */ |
| 2385 | "%d,%d," |
| 2386 | /* sessions : current, max, limit, total */ |
| 2387 | "%d,%d,%s,%lld," |
| 2388 | /* bytes : in, out */ |
| 2389 | "%lld,%lld," |
| 2390 | /* denied: req, resp */ |
| 2391 | ",%lld," |
| 2392 | /* errors : request, connect, response */ |
| 2393 | ",%lld,%lld," |
| 2394 | /* warnings: retries, redispatches */ |
| 2395 | "%lld,%lld," |
| 2396 | "", |
| 2397 | px->id, sv->id, |
| 2398 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2399 | 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] | 2400 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2401 | sv->counters.failed_secu, |
| 2402 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2403 | sv->counters.retries, sv->counters.redispatches); |
| 2404 | |
| 2405 | /* status */ |
| 2406 | if (sv->state & SRV_MAINTAIN) |
| 2407 | chunk_appendf(&trash, "MAINT,"); |
| 2408 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2409 | chunk_appendf(&trash, "MAINT(via),"); |
| 2410 | else |
| 2411 | chunk_appendf(&trash, |
| 2412 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2413 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2414 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2415 | |
| 2416 | chunk_appendf(&trash, |
| 2417 | /* weight, active, backup */ |
| 2418 | "%d,%d,%d," |
| 2419 | "", |
| 2420 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2421 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2422 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2423 | |
| 2424 | /* check failures: unique, fatal; last change, total downtime */ |
| 2425 | if (sv->state & SRV_CHECKED) |
| 2426 | chunk_appendf(&trash, |
| 2427 | "%lld,%lld,%d,%d,", |
| 2428 | sv->counters.failed_checks, sv->counters.down_trans, |
| 2429 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 2430 | else |
| 2431 | chunk_appendf(&trash, ",,,,"); |
| 2432 | |
| 2433 | /* queue limit, pid, iid, sid, */ |
| 2434 | chunk_appendf(&trash, |
| 2435 | "%s," |
| 2436 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2437 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2438 | relative_pid, px->uuid, sv->puid); |
| 2439 | |
| 2440 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2441 | if (sv->state & SRV_WARMINGUP) |
| 2442 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2443 | |
| 2444 | /* sessions: lbtot */ |
| 2445 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 2446 | |
| 2447 | /* tracked */ |
| 2448 | if (sv->track) |
| 2449 | chunk_appendf(&trash, "%s/%s,", |
| 2450 | sv->track->proxy->id, sv->track->id); |
| 2451 | else |
| 2452 | chunk_appendf(&trash, ","); |
| 2453 | |
| 2454 | /* type */ |
| 2455 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 2456 | |
| 2457 | /* rate */ |
| 2458 | chunk_appendf(&trash, "%u,,%u,", |
| 2459 | read_freq_ctr(&sv->sess_per_sec), |
| 2460 | sv->counters.sps_max); |
| 2461 | |
| 2462 | if (sv->state & SRV_CHECKED) { |
| 2463 | /* check_status */ |
| 2464 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 2465 | |
| 2466 | /* check_code */ |
| 2467 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2468 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 2469 | else |
| 2470 | chunk_appendf(&trash, ","); |
| 2471 | |
| 2472 | /* check_duration */ |
| 2473 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 2474 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 2475 | else |
| 2476 | chunk_appendf(&trash, ","); |
| 2477 | |
| 2478 | } |
| 2479 | else |
| 2480 | chunk_appendf(&trash, ",,,"); |
| 2481 | |
| 2482 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2483 | if (px->mode == PR_MODE_HTTP) { |
| 2484 | for (i=1; i<6; i++) |
| 2485 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 2486 | |
| 2487 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 2488 | } |
| 2489 | else |
| 2490 | chunk_appendf(&trash, ",,,,,,"); |
| 2491 | |
| 2492 | /* failed health analyses */ |
| 2493 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 2494 | |
| 2495 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2496 | chunk_appendf(&trash, ",,,"); |
| 2497 | |
| 2498 | /* errors: cli_aborts, srv_aborts */ |
| 2499 | chunk_appendf(&trash, "%lld,%lld,", |
| 2500 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 2501 | |
| 2502 | /* compression: in, out, bypassed, comp_rsp */ |
| 2503 | chunk_appendf(&trash, ",,,,"); |
| 2504 | |
| 2505 | /* finish with EOL */ |
| 2506 | chunk_appendf(&trash, "\n"); |
| 2507 | } |
| 2508 | return 1; |
| 2509 | } |
| 2510 | |
| 2511 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 2512 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 2513 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 2514 | */ |
| 2515 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 2516 | { |
| 2517 | struct chunk src; |
| 2518 | int i; |
| 2519 | |
| 2520 | if (!(px->cap & PR_CAP_BE)) |
| 2521 | return 0; |
| 2522 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2523 | if ((si->appctx.ctx.stats.flags & STAT_BOUND) && !(si->appctx.ctx.stats.type & (1 << STATS_TYPE_BE))) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2524 | return 0; |
| 2525 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2526 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2527 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2528 | if (px->srv && (si->appctx.ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2529 | /* Column sub-heading for Enable or Disable server */ |
| 2530 | chunk_appendf(&trash, "<td></td>"); |
| 2531 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2532 | chunk_appendf(&trash, |
| 2533 | "<td class=ac>" |
| 2534 | /* name */ |
| 2535 | "%s<a name=\"%s/Backend\"></a>" |
| 2536 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 2537 | "", |
| 2538 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2539 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2540 | |
| 2541 | if (flags & ST_SHLGNDS) { |
| 2542 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2543 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2544 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 2545 | |
| 2546 | /* cookie */ |
| 2547 | if (px->cookie_name) { |
| 2548 | chunk_appendf(&trash, ", cookie: '"); |
| 2549 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 2550 | chunk_htmlencode(&trash, &src); |
| 2551 | chunk_appendf(&trash, "'"); |
| 2552 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2553 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2557 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2558 | /* queue : current, max */ |
| 2559 | "<td>%s</td><td>%s</td><td></td>" |
| 2560 | /* sessions rate : current, max, limit */ |
| 2561 | "<td>%s</td><td>%s</td><td></td>" |
| 2562 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2563 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2564 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 2565 | 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] | 2566 | |
| 2567 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2568 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2569 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2570 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2571 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2572 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2573 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 2574 | U2H(px->be_counters.cum_conn), |
| 2575 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2576 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2577 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2578 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2579 | chunk_appendf(&trash, |
| 2580 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2581 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2582 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2583 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2584 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2585 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2586 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2587 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2588 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2589 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2590 | U2H(px->be_counters.p.http.cum_req), |
| 2591 | U2H(px->be_counters.p.http.rsp[1]), |
| 2592 | U2H(px->be_counters.p.http.rsp[2]), |
| 2593 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2594 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2595 | (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] | 2596 | U2H(px->be_counters.p.http.rsp[3]), |
| 2597 | U2H(px->be_counters.p.http.rsp[4]), |
| 2598 | U2H(px->be_counters.p.http.rsp[5]), |
| 2599 | U2H(px->be_counters.p.http.rsp[0]), |
| 2600 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2604 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2605 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2606 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2607 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2608 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2609 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2610 | U2H(px->be_counters.cum_lbconn), |
| 2611 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2612 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2613 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2614 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2615 | "<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] | 2616 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2617 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2618 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 2619 | px->be_counters.comp_in ? |
| 2620 | (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] | 2621 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 2622 | |
| 2623 | chunk_appendf(&trash, |
| 2624 | /* denied: req, resp */ |
| 2625 | "<td>%s</td><td>%s</td>" |
| 2626 | /* errors : request, connect */ |
| 2627 | "<td></td><td>%s</td>" |
| 2628 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2629 | "<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] | 2630 | /* warnings: retries, redispatches */ |
| 2631 | "<td>%lld</td><td>%lld</td>" |
| 2632 | /* backend status: reflect backend status (up/down): we display UP |
| 2633 | * if the backend has known working servers or if it has no server at |
| 2634 | * all (eg: for stats). Then we display the total weight, number of |
| 2635 | * active and backups. */ |
| 2636 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 2637 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 2638 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2639 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 2640 | U2H(px->be_counters.failed_conns), |
| 2641 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2642 | px->be_counters.cli_aborts, |
| 2643 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2644 | px->be_counters.retries, px->be_counters.redispatches, |
| 2645 | human_time(now.tv_sec - px->last_change, 1), |
| 2646 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 2647 | "<font color=\"red\"><b>DOWN</b></font>", |
| 2648 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2649 | px->srv_act, px->srv_bck); |
| 2650 | |
| 2651 | chunk_appendf(&trash, |
| 2652 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 2653 | "<td class=ac> </td><td>%d</td>" |
| 2654 | "<td>%s</td>" |
| 2655 | "<td></td>" |
| 2656 | "</tr>", |
| 2657 | px->down_trans, |
| 2658 | px->srv?human_time(be_downtime(px), 1):" "); |
| 2659 | } |
| 2660 | else { /* CSV mode */ |
| 2661 | chunk_appendf(&trash, |
| 2662 | /* pxid, name */ |
| 2663 | "%s,BACKEND," |
| 2664 | /* queue : current, max */ |
| 2665 | "%d,%d," |
| 2666 | /* sessions : current, max, limit, total */ |
| 2667 | "%d,%d,%d,%lld," |
| 2668 | /* bytes : in, out */ |
| 2669 | "%lld,%lld," |
| 2670 | /* denied: req, resp */ |
| 2671 | "%lld,%lld," |
| 2672 | /* errors : request, connect, response */ |
| 2673 | ",%lld,%lld," |
| 2674 | /* warnings: retries, redispatches */ |
| 2675 | "%lld,%lld," |
| 2676 | /* backend status: reflect backend status (up/down): we display UP |
| 2677 | * if the backend has known working servers or if it has no server at |
| 2678 | * all (eg: for stats). Then we display the total weight, number of |
| 2679 | * active and backups. */ |
| 2680 | "%s," |
| 2681 | "%d,%d,%d," |
| 2682 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 2683 | ",%d,%d,%d,," |
| 2684 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2685 | "%d,%d,0,,%lld,,%d," |
| 2686 | /* rate, rate_lim, rate_max, */ |
| 2687 | "%u,,%u," |
| 2688 | /* check_status, check_code, check_duration */ |
| 2689 | ",,,", |
| 2690 | px->id, |
| 2691 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 2692 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 2693 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 2694 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 2695 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 2696 | px->be_counters.retries, px->be_counters.redispatches, |
| 2697 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 2698 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2699 | px->srv_act, px->srv_bck, |
| 2700 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 2701 | px->srv?be_downtime(px):0, |
| 2702 | relative_pid, px->uuid, |
| 2703 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 2704 | read_freq_ctr(&px->be_sess_per_sec), |
| 2705 | px->be_counters.sps_max); |
| 2706 | |
| 2707 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2708 | if (px->mode == PR_MODE_HTTP) { |
| 2709 | for (i=1; i<6; i++) |
| 2710 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 2711 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 2712 | } |
| 2713 | else |
| 2714 | chunk_appendf(&trash, ",,,,,,"); |
| 2715 | |
| 2716 | /* failed health analyses */ |
| 2717 | chunk_appendf(&trash, ","); |
| 2718 | |
| 2719 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2720 | chunk_appendf(&trash, ",,,"); |
| 2721 | |
| 2722 | /* errors: cli_aborts, srv_aborts */ |
| 2723 | chunk_appendf(&trash, "%lld,%lld,", |
| 2724 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 2725 | |
| 2726 | /* compression: in, out, bypassed */ |
| 2727 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2728 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 2729 | |
| 2730 | /* compression: comp_rsp */ |
| 2731 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 2732 | |
| 2733 | /* finish with EOL */ |
| 2734 | chunk_appendf(&trash, "\n"); |
| 2735 | } |
| 2736 | return 1; |
| 2737 | } |
| 2738 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2739 | /* 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] | 2740 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2741 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2742 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2743 | 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] | 2744 | { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2745 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 2746 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2747 | if (px->cap & PR_CAP_BE && px->srv && (si->appctx.ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2748 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2749 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2750 | /* scope_txt = search pattern + search query, si->appctx.ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2751 | scope_txt[0] = 0; |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2752 | if (si->appctx.ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2753 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2754 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + si->appctx.ctx.stats.scope_str, si->appctx.ctx.stats.scope_len); |
| 2755 | scope_txt[strlen(STAT_SCOPE_PATTERN) + si->appctx.ctx.stats.scope_len] = 0; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2756 | } |
| 2757 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2758 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2759 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 2760 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2761 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2762 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2763 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | /* print a new table */ |
| 2767 | chunk_appendf(&trash, |
| 2768 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2769 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2770 | "<th class=\"pxname\" width=\"10%%\">"); |
| 2771 | |
| 2772 | chunk_appendf(&trash, |
| 2773 | "<a name=\"%s\"></a>%s" |
| 2774 | "<a class=px href=\"#%s\">%s</a>", |
| 2775 | px->id, |
| 2776 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 2777 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2778 | |
| 2779 | if (uri->flags & ST_SHLGNDS) { |
| 2780 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2781 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2782 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 2783 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2784 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2788 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2789 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 2790 | "</tr>\n" |
| 2791 | "</table>\n" |
| 2792 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2793 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2794 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 2795 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 2796 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2797 | if ((px->cap & PR_CAP_BE) && px->srv && (si->appctx.ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2798 | /* Column heading for Enable or Disable server */ |
| 2799 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2800 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2801 | |
| 2802 | chunk_appendf(&trash, |
| 2803 | "<th rowspan=2></th>" |
| 2804 | "<th colspan=3>Queue</th>" |
| 2805 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
| 2806 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 2807 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 2808 | "<th colspan=9>Server</th>" |
| 2809 | "</tr>\n" |
| 2810 | "<tr class=\"titre\">" |
| 2811 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 2812 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 2813 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>" |
| 2814 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 2815 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 2816 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 2817 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 2818 | "<th>Thrtle</th>\n" |
| 2819 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2820 | } |
| 2821 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2822 | /* 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] | 2823 | * 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] | 2824 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2825 | 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] | 2826 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2827 | chunk_appendf(&trash, "</table>"); |
| 2828 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2829 | if ((px->cap & PR_CAP_BE) && px->srv && (si->appctx.ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2830 | /* close the form used to enable/disable this proxy servers */ |
| 2831 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2832 | "Choose the action to perform on the checked servers : " |
| 2833 | "<select name=action>" |
| 2834 | "<option value=\"\"></option>" |
| 2835 | "<option value=\"disable\">Disable</option>" |
| 2836 | "<option value=\"enable\">Enable</option>" |
| 2837 | "<option value=\"stop\">Soft Stop</option>" |
| 2838 | "<option value=\"start\">Soft Start</option>" |
| 2839 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 2840 | "</select>" |
| 2841 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 2842 | " <input type=\"submit\" value=\"Apply\">" |
| 2843 | "</form>", |
| 2844 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2848 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2849 | |
| 2850 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2851 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 2852 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 2853 | * buffer space, or non-zero if everything completed. This function is used |
| 2854 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 2855 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2856 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2857 | 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] | 2858 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 2859 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2860 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2861 | 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] | 2862 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2863 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2864 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2865 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2866 | switch (si->appctx.ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2867 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2868 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2869 | if (uri && uri->scope) { |
| 2870 | /* we have a limited scope, we have to check the proxy name */ |
| 2871 | struct stat_scope *scope; |
| 2872 | int len; |
| 2873 | |
| 2874 | len = strlen(px->id); |
| 2875 | scope = uri->scope; |
| 2876 | |
| 2877 | while (scope) { |
| 2878 | /* match exact proxy name */ |
| 2879 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 2880 | break; |
| 2881 | |
| 2882 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 2883 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2884 | break; |
| 2885 | scope = scope->next; |
| 2886 | } |
| 2887 | |
| 2888 | /* proxy name not found : don't dump anything */ |
| 2889 | if (scope == NULL) |
| 2890 | return 1; |
| 2891 | } |
| 2892 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2893 | /* if the user has requested a limited output and the proxy |
| 2894 | * name does not match, skip it. |
| 2895 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2896 | if (si->appctx.ctx.stats.scope_len && |
| 2897 | strnistr(px->id, strlen(px->id), bo_ptr(si->ob->buf) + si->appctx.ctx.stats.scope_str, si->appctx.ctx.stats.scope_len) == NULL) |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2898 | return 1; |
| 2899 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2900 | if ((si->appctx.ctx.stats.flags & STAT_BOUND) && |
| 2901 | (si->appctx.ctx.stats.iid != -1) && |
| 2902 | (px->uuid != si->appctx.ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2903 | return 1; |
| 2904 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2905 | si->appctx.ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2906 | /* fall through */ |
| 2907 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2908 | case STAT_PX_ST_TH: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2909 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2910 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2911 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2912 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2913 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2914 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2915 | si->appctx.ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2916 | /* fall through */ |
| 2917 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2918 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2919 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2920 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2921 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2922 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2923 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2924 | si->appctx.ctx.stats.l = px->conf.listeners.n; |
| 2925 | si->appctx.ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2926 | /* fall through */ |
| 2927 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2928 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2929 | /* stats.l has been initialized above */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2930 | for (; si->appctx.ctx.stats.l != &px->conf.listeners; si->appctx.ctx.stats.l = l->by_fe.n) { |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2931 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2932 | return 0; |
| 2933 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2934 | l = LIST_ELEM(si->appctx.ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2935 | if (!l->counters) |
| 2936 | continue; |
| 2937 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2938 | if (si->appctx.ctx.stats.flags & STAT_BOUND) { |
| 2939 | if (!(si->appctx.ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2940 | break; |
| 2941 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2942 | if (si->appctx.ctx.stats.sid != -1 && l->luid != si->appctx.ctx.stats.sid) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2943 | continue; |
| 2944 | } |
| 2945 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2946 | /* print the frontend */ |
| 2947 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 2948 | if (bi_putchk(rep, &trash) == -1) |
| 2949 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2950 | } |
| 2951 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2952 | si->appctx.ctx.stats.sv = px->srv; /* may be NULL */ |
| 2953 | si->appctx.ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2954 | /* fall through */ |
| 2955 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2956 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2957 | /* stats.sv has been initialized above */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2958 | for (; si->appctx.ctx.stats.sv != NULL; si->appctx.ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2959 | 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] | 2960 | |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2961 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2962 | return 0; |
| 2963 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2964 | sv = si->appctx.ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2965 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2966 | if (si->appctx.ctx.stats.flags & STAT_BOUND) { |
| 2967 | if (!(si->appctx.ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2968 | break; |
| 2969 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2970 | if (si->appctx.ctx.stats.sid != -1 && sv->puid != si->appctx.ctx.stats.sid) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2971 | continue; |
| 2972 | } |
| 2973 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2974 | if (sv->track) |
| 2975 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2976 | else |
| 2977 | svs = sv; |
| 2978 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2979 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2980 | if (!(svs->state & SRV_CHECKED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2981 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2982 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2983 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2984 | sv_state = 3; /* UP */ |
| 2985 | else |
| 2986 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2987 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 2988 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2989 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 2990 | else if (svs->state & SRV_GOINGDOWN) |
| 2991 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2992 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2993 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 2994 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2995 | sv_state = 1; /* going up */ |
| 2996 | else |
| 2997 | sv_state = 0; /* DOWN */ |
| 2998 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2999 | if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3000 | /* do not report servers which are DOWN */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3001 | si->appctx.ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3002 | continue; |
| 3003 | } |
| 3004 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3005 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3006 | if (bi_putchk(rep, &trash) == -1) |
| 3007 | return 0; |
| 3008 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3009 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3010 | si->appctx.ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3011 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3012 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3013 | case STAT_PX_ST_BE: |
| 3014 | /* print the backend */ |
| 3015 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3016 | if (bi_putchk(rep, &trash) == -1) |
| 3017 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3018 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3019 | si->appctx.ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3020 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3021 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3022 | case STAT_PX_ST_END: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3023 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3024 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3025 | if (bi_putchk(rep, &trash) == -1) |
| 3026 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3027 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3028 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3029 | si->appctx.ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3030 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3031 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3032 | case STAT_PX_ST_FIN: |
| 3033 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3034 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3035 | default: |
| 3036 | /* unknown state, we should put an abort() here ! */ |
| 3037 | return 1; |
| 3038 | } |
| 3039 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3040 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3041 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3042 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3043 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3044 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3045 | { |
| 3046 | /* WARNING! This must fit in the first buffer !!! */ |
| 3047 | chunk_appendf(&trash, |
| 3048 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3049 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3050 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3051 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3052 | "<style type=\"text/css\"><!--\n" |
| 3053 | "body {" |
| 3054 | " font-family: arial, helvetica, sans-serif;" |
| 3055 | " font-size: 12px;" |
| 3056 | " font-weight: normal;" |
| 3057 | " color: black;" |
| 3058 | " background: white;" |
| 3059 | "}\n" |
| 3060 | "th,td {" |
| 3061 | " font-size: 10px;" |
| 3062 | "}\n" |
| 3063 | "h1 {" |
| 3064 | " font-size: x-large;" |
| 3065 | " margin-bottom: 0.5em;" |
| 3066 | "}\n" |
| 3067 | "h2 {" |
| 3068 | " font-family: helvetica, arial;" |
| 3069 | " font-size: x-large;" |
| 3070 | " font-weight: bold;" |
| 3071 | " font-style: italic;" |
| 3072 | " color: #6020a0;" |
| 3073 | " margin-top: 0em;" |
| 3074 | " margin-bottom: 0em;" |
| 3075 | "}\n" |
| 3076 | "h3 {" |
| 3077 | " font-family: helvetica, arial;" |
| 3078 | " font-size: 16px;" |
| 3079 | " font-weight: bold;" |
| 3080 | " color: #b00040;" |
| 3081 | " background: #e8e8d0;" |
| 3082 | " margin-top: 0em;" |
| 3083 | " margin-bottom: 0em;" |
| 3084 | "}\n" |
| 3085 | "li {" |
| 3086 | " margin-top: 0.25em;" |
| 3087 | " margin-right: 2em;" |
| 3088 | "}\n" |
| 3089 | ".hr {margin-top: 0.25em;" |
| 3090 | " border-color: black;" |
| 3091 | " border-bottom-style: solid;" |
| 3092 | "}\n" |
| 3093 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3094 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3095 | ".frontend {background: #e8e8d0;}\n" |
| 3096 | ".socket {background: #d0d0d0;}\n" |
| 3097 | ".backend {background: #e8e8d0;}\n" |
| 3098 | ".active0 {background: #ff9090;}\n" |
| 3099 | ".active1 {background: #ffd020;}\n" |
| 3100 | ".active2 {background: #ffffa0;}\n" |
| 3101 | ".active3 {background: #c0ffc0;}\n" |
| 3102 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3103 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3104 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3105 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3106 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3107 | ".backup0 {background: #ff9090;}\n" |
| 3108 | ".backup1 {background: #ff80ff;}\n" |
| 3109 | ".backup2 {background: #c060ff;}\n" |
| 3110 | ".backup3 {background: #b0d0ff;}\n" |
| 3111 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3112 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3113 | ".backup6 {background: #c060ff;}\n" |
| 3114 | ".backup7 {background: #cc9900;}\n" |
| 3115 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3116 | ".maintain {background: #c07820;}\n" |
| 3117 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3118 | "\n" |
| 3119 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3120 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3121 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3122 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3123 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3124 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3125 | "\n" |
| 3126 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3127 | "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" |
| 3128 | "table.tbl td.ac { text-align: center;}\n" |
| 3129 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3130 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3131 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3132 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3133 | "\n" |
| 3134 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3135 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3136 | "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] | 3137 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3138 | "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" |
| 3139 | "table.det td { text-align: right; border-width: 0px; padding: 0px 0px 0px 4px; white-space: nowrap; font-style:normal;font-size:11px;font-weight:normal;font-family: monospace;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3140 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3141 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3142 | " display:block;\n" |
| 3143 | " visibility:hidden;\n" |
| 3144 | " z-index:2147483647;\n" |
| 3145 | " position:absolute;\n" |
| 3146 | " padding:2px 4px 3px;\n" |
| 3147 | " background:#f0f060; color:#000000;\n" |
| 3148 | " border:1px solid #7040c0;\n" |
| 3149 | " white-space:nowrap;\n" |
| 3150 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3151 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3152 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3153 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3154 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3155 | "-->\n" |
| 3156 | "</style></head>\n", |
| 3157 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3158 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3159 | ); |
| 3160 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3161 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3162 | /* 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] | 3163 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3164 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3165 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3166 | 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] | 3167 | { |
| 3168 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3169 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3170 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3171 | /* WARNING! this has to fit the first packet too. |
| 3172 | * We are around 3.5 kB, add adding entries will |
| 3173 | * become tricky if we want to support 4kB buffers ! |
| 3174 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3175 | chunk_appendf(&trash, |
| 3176 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3177 | PRODUCT_NAME "%s</a></h1>\n" |
| 3178 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3179 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3180 | "<h3>> General process information</h3>\n" |
| 3181 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3182 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3183 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3184 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3185 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3186 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3187 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3188 | "</td><td align=\"center\" nowrap>\n" |
| 3189 | "<table class=\"lgd\"><tr>\n" |
| 3190 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3191 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3192 | "</tr><tr>\n" |
| 3193 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3194 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3195 | "</tr><tr>\n" |
| 3196 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3197 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3198 | "</tr><tr>\n" |
| 3199 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3200 | "</tr><tr>\n" |
| 3201 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3202 | "</tr><tr>\n" |
| 3203 | "<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] | 3204 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3205 | "<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] | 3206 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3207 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3208 | "</td>" |
| 3209 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3210 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3211 | "", |
| 3212 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3213 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3214 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3215 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3216 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3217 | pid, relative_pid, global.nbproc, |
| 3218 | up / 86400, (up % 86400) / 3600, |
| 3219 | (up % 3600) / 60, (up % 60), |
| 3220 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3221 | global.rlimit_memmax ? " MB" : "", |
| 3222 | global.rlimit_nofile, |
| 3223 | global.maxsock, global.maxconn, global.maxpipes, |
| 3224 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3225 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3226 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3227 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3228 | /* scope_txt = search query, si->appctx.ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3229 | memcpy(scope_txt, bo_ptr(si->ob->buf) + si->appctx.ctx.stats.scope_str, si->appctx.ctx.stats.scope_len); |
| 3230 | scope_txt[si->appctx.ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3231 | |
| 3232 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3233 | "<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] | 3234 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3235 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3236 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3237 | (si->appctx.ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3238 | STAT_SCOPE_TXT_MAXLEN); |
| 3239 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3240 | /* scope_txt = search pattern + search query, si->appctx.ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3241 | scope_txt[0] = 0; |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3242 | if (si->appctx.ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3243 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3244 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + si->appctx.ctx.stats.scope_str, si->appctx.ctx.stats.scope_len); |
| 3245 | scope_txt[strlen(STAT_SCOPE_PATTERN) + si->appctx.ctx.stats.scope_len] = 0; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3246 | } |
| 3247 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3248 | if (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3249 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3250 | "<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] | 3251 | uri->uri_prefix, |
| 3252 | "", |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3253 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3254 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3255 | else |
| 3256 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3257 | "<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] | 3258 | uri->uri_prefix, |
| 3259 | ";up", |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3260 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3261 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3262 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3263 | if (uri->refresh > 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3264 | if (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3265 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3266 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3267 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3268 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3269 | "", |
| 3270 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3271 | else |
| 3272 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3273 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3274 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3275 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3276 | ";norefresh", |
| 3277 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3278 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3279 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3280 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3281 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3282 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3283 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3284 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3285 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3286 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3287 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3288 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3289 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3290 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3291 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3292 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3293 | chunk_appendf(&trash, |
| 3294 | "</ul></td>" |
| 3295 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3296 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3297 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3298 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3299 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3300 | "</ul>" |
| 3301 | "</td>" |
| 3302 | "</tr></table>\n" |
| 3303 | "" |
| 3304 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3305 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3306 | if (si->appctx.ctx.stats.st_code) { |
| 3307 | switch (si->appctx.ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3308 | case STAT_STATUS_DONE: |
| 3309 | chunk_appendf(&trash, |
| 3310 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3311 | "<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] | 3312 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3313 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3314 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3315 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3316 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3317 | break; |
| 3318 | case STAT_STATUS_NONE: |
| 3319 | chunk_appendf(&trash, |
| 3320 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3321 | "<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] | 3322 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3323 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3324 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3325 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3326 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3327 | break; |
| 3328 | case STAT_STATUS_PART: |
| 3329 | chunk_appendf(&trash, |
| 3330 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3331 | "<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] | 3332 | "Action partially processed.<br>" |
| 3333 | "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] | 3334 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3335 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3336 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3337 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3338 | break; |
| 3339 | case STAT_STATUS_ERRP: |
| 3340 | chunk_appendf(&trash, |
| 3341 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3342 | "<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] | 3343 | "Action not processed because of invalid parameters." |
| 3344 | "<ul>" |
| 3345 | "<li>The action is maybe unknown.</li>" |
| 3346 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3347 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3348 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3349 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3350 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3351 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3352 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3353 | break; |
| 3354 | case STAT_STATUS_EXCD: |
| 3355 | chunk_appendf(&trash, |
| 3356 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3357 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3358 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3359 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3360 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3361 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3362 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3363 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3364 | break; |
| 3365 | case STAT_STATUS_DENY: |
| 3366 | chunk_appendf(&trash, |
| 3367 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3368 | "<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] | 3369 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3370 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3371 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3372 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3373 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3374 | break; |
| 3375 | default: |
| 3376 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3377 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3378 | "<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] | 3379 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3380 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3381 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3382 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3383 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3384 | } |
| 3385 | chunk_appendf(&trash, "<p>\n"); |
| 3386 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3387 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3388 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3389 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3390 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3391 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3392 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3393 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3394 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3395 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3396 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3397 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3398 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3399 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3400 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3401 | * and the session must be closed, or -1 in case of any error. This function is |
| 3402 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3403 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3404 | 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] | 3405 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3406 | struct channel *rep = si->ib; |
| 3407 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3408 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3409 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3410 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3411 | switch (si->appctx.st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3412 | case STAT_ST_INIT: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3413 | si->appctx.st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3414 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3415 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3416 | case STAT_ST_HEAD: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3417 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3418 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3419 | else |
| 3420 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3421 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3422 | if (bi_putchk(rep, &trash) == -1) |
| 3423 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3424 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3425 | si->appctx.st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3426 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3427 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3428 | case STAT_ST_INFO: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3429 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3430 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3431 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3432 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3433 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3434 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3435 | si->appctx.ctx.stats.px = proxy; |
| 3436 | si->appctx.ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3437 | si->appctx.st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3438 | /* fall through */ |
| 3439 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3440 | case STAT_ST_LIST: |
| 3441 | /* dump proxies */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3442 | while (si->appctx.ctx.stats.px) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3443 | if (buffer_almost_full(rep->buf)) |
| 3444 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3445 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3446 | px = si->appctx.ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3447 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 3448 | 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] | 3449 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3450 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3451 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3452 | si->appctx.ctx.stats.px = px->next; |
| 3453 | si->appctx.ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3454 | } |
| 3455 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3456 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3457 | si->appctx.st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3458 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3459 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3460 | case STAT_ST_END: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3461 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3462 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3463 | if (bi_putchk(rep, &trash) == -1) |
| 3464 | return 0; |
| 3465 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3466 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3467 | si->appctx.st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3468 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 3469 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3470 | case STAT_ST_FIN: |
| 3471 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3472 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3473 | default: |
| 3474 | /* unknown state ! */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3475 | si->appctx.st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3476 | return -1; |
| 3477 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3478 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3479 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3480 | /* We reached the stats page through a POST request. |
| 3481 | * Parse the posted data and enable/disable servers if necessary. |
| 3482 | * Returns 1 if request was parsed or zero if it needs more data. |
| 3483 | */ |
| 3484 | static int stats_process_http_post(struct stream_interface *si) |
| 3485 | { |
| 3486 | struct session *s = session_from_task(si->owner); |
| 3487 | |
| 3488 | struct proxy *px = NULL; |
| 3489 | struct server *sv = NULL; |
| 3490 | |
| 3491 | char key[LINESIZE]; |
| 3492 | int action = ST_ADM_ACTION_NONE; |
| 3493 | int reprocess = 0; |
| 3494 | |
| 3495 | int total_servers = 0; |
| 3496 | int altered_servers = 0; |
| 3497 | |
| 3498 | char *first_param, *cur_param, *next_param, *end_params; |
| 3499 | char *st_cur_param = NULL; |
| 3500 | char *st_next_param = NULL; |
| 3501 | |
| 3502 | struct chunk *temp; |
| 3503 | int reql; |
| 3504 | |
| 3505 | temp = get_trash_chunk(); |
| 3506 | if (temp->size < s->txn.req.body_len) { |
| 3507 | /* too large request */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3508 | si->appctx.ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3509 | goto out; |
| 3510 | } |
| 3511 | |
| 3512 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 3513 | if (reql <= 0) { |
| 3514 | /* we need more data */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3515 | si->appctx.ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3516 | return 0; |
| 3517 | } |
| 3518 | |
| 3519 | first_param = temp->str; |
| 3520 | end_params = temp->str + reql; |
| 3521 | cur_param = next_param = end_params; |
| 3522 | *end_params = '\0'; |
| 3523 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3524 | si->appctx.ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3525 | |
| 3526 | /* |
| 3527 | * Parse the parameters in reverse order to only store the last value. |
| 3528 | * From the html form, the backend and the action are at the end. |
| 3529 | */ |
| 3530 | while (cur_param > first_param) { |
| 3531 | char *value; |
| 3532 | int poffset, plen; |
| 3533 | |
| 3534 | cur_param--; |
| 3535 | |
| 3536 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 3537 | reprocess_servers: |
| 3538 | /* Parse the key */ |
| 3539 | poffset = (cur_param != first_param ? 1 : 0); |
| 3540 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 3541 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 3542 | strncpy(key, cur_param + poffset, plen); |
| 3543 | key[plen - 1] = '\0'; |
| 3544 | } else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3545 | si->appctx.ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3546 | goto out; |
| 3547 | } |
| 3548 | |
| 3549 | /* Parse the value */ |
| 3550 | value = key; |
| 3551 | while (*value != '\0' && *value != '=') { |
| 3552 | value++; |
| 3553 | } |
| 3554 | if (*value == '=') { |
| 3555 | /* Ok, a value is found, we can mark the end of the key */ |
| 3556 | *value++ = '\0'; |
| 3557 | } |
| 3558 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 3559 | break; |
| 3560 | |
| 3561 | /* Now we can check the key to see what to do */ |
| 3562 | if (!px && (strcmp(key, "b") == 0)) { |
| 3563 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 3564 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3565 | si->appctx.ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3566 | goto out; |
| 3567 | } |
| 3568 | } |
| 3569 | else if (!action && (strcmp(key, "action") == 0)) { |
| 3570 | if (strcmp(value, "disable") == 0) { |
| 3571 | action = ST_ADM_ACTION_DISABLE; |
| 3572 | } |
| 3573 | else if (strcmp(value, "enable") == 0) { |
| 3574 | action = ST_ADM_ACTION_ENABLE; |
| 3575 | } |
| 3576 | else if (strcmp(value, "stop") == 0) { |
| 3577 | action = ST_ADM_ACTION_STOP; |
| 3578 | } |
| 3579 | else if (strcmp(value, "start") == 0) { |
| 3580 | action = ST_ADM_ACTION_START; |
| 3581 | } |
| 3582 | else if (strcmp(value, "shutdown") == 0) { |
| 3583 | action = ST_ADM_ACTION_SHUTDOWN; |
| 3584 | } |
| 3585 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3586 | si->appctx.ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3587 | goto out; |
| 3588 | } |
| 3589 | } |
| 3590 | else if (strcmp(key, "s") == 0) { |
| 3591 | if (!(px && action)) { |
| 3592 | /* |
| 3593 | * Indicates that we'll need to reprocess the parameters |
| 3594 | * as soon as backend and action are known |
| 3595 | */ |
| 3596 | if (!reprocess) { |
| 3597 | st_cur_param = cur_param; |
| 3598 | st_next_param = next_param; |
| 3599 | } |
| 3600 | reprocess = 1; |
| 3601 | } |
| 3602 | else if ((sv = findserver(px, value)) != NULL) { |
| 3603 | switch (action) { |
| 3604 | case ST_ADM_ACTION_DISABLE: |
| 3605 | if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) { |
| 3606 | /* Not already in maintenance, we can change the server state */ |
| 3607 | sv->state |= SRV_MAINTAIN; |
| 3608 | set_server_down(&sv->check); |
| 3609 | altered_servers++; |
| 3610 | total_servers++; |
| 3611 | } |
| 3612 | break; |
| 3613 | case ST_ADM_ACTION_ENABLE: |
| 3614 | if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) { |
| 3615 | /* Already in maintenance, we can change the server state */ |
| 3616 | set_server_up(&sv->check); |
| 3617 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 3618 | altered_servers++; |
| 3619 | total_servers++; |
| 3620 | } |
| 3621 | break; |
| 3622 | case ST_ADM_ACTION_STOP: |
| 3623 | case ST_ADM_ACTION_START: |
| 3624 | if (action == ST_ADM_ACTION_START) |
| 3625 | sv->uweight = sv->iweight; |
| 3626 | else |
| 3627 | sv->uweight = 0; |
| 3628 | |
| 3629 | server_recalc_eweight(sv); |
| 3630 | set_server_drain_state(sv); |
| 3631 | |
| 3632 | altered_servers++; |
| 3633 | total_servers++; |
| 3634 | break; |
| 3635 | case ST_ADM_ACTION_SHUTDOWN: |
| 3636 | if (px->state != PR_STSTOPPED) { |
| 3637 | struct session *sess, *sess_bck; |
| 3638 | |
| 3639 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 3640 | if (sess->srv_conn == sv) |
| 3641 | session_shutdown(sess, SN_ERR_KILLED); |
| 3642 | |
| 3643 | altered_servers++; |
| 3644 | total_servers++; |
| 3645 | } |
| 3646 | break; |
| 3647 | } |
| 3648 | } else { |
| 3649 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 3650 | total_servers++; |
| 3651 | } |
| 3652 | } |
| 3653 | if (reprocess && px && action) { |
| 3654 | /* Now, we know the backend and the action chosen by the user. |
| 3655 | * We can safely restart from the first server parameter |
| 3656 | * to reprocess them |
| 3657 | */ |
| 3658 | cur_param = st_cur_param; |
| 3659 | next_param = st_next_param; |
| 3660 | reprocess = 0; |
| 3661 | goto reprocess_servers; |
| 3662 | } |
| 3663 | |
| 3664 | next_param = cur_param; |
| 3665 | } |
| 3666 | } |
| 3667 | |
| 3668 | if (total_servers == 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3669 | si->appctx.ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3670 | } |
| 3671 | else if (altered_servers == 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3672 | si->appctx.ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3673 | } |
| 3674 | else if (altered_servers == total_servers) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3675 | si->appctx.ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3676 | } |
| 3677 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3678 | si->appctx.ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3679 | } |
| 3680 | out: |
| 3681 | return 1; |
| 3682 | } |
| 3683 | |
| 3684 | |
| 3685 | static int stats_send_http_headers(struct stream_interface *si) |
| 3686 | { |
| 3687 | struct session *s = session_from_task(si->owner); |
| 3688 | struct uri_auth *uri = s->be->uri_auth; |
| 3689 | |
| 3690 | chunk_printf(&trash, |
| 3691 | "HTTP/1.0 200 OK\r\n" |
| 3692 | "Cache-Control: no-cache\r\n" |
| 3693 | "Connection: close\r\n" |
| 3694 | "Content-Type: %s\r\n", |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3695 | (si->appctx.ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3696 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3697 | if (uri->refresh > 0 && !(si->appctx.ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3698 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 3699 | uri->refresh); |
| 3700 | |
| 3701 | chunk_appendf(&trash, "\r\n"); |
| 3702 | |
| 3703 | s->txn.status = 200; |
| 3704 | s->logs.tv_request = now; |
| 3705 | |
| 3706 | if (bi_putchk(si->ib, &trash) == -1) |
| 3707 | return 0; |
| 3708 | |
| 3709 | return 1; |
| 3710 | } |
| 3711 | |
| 3712 | static int stats_send_http_redirect(struct stream_interface *si) |
| 3713 | { |
| 3714 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3715 | struct session *s = session_from_task(si->owner); |
| 3716 | struct uri_auth *uri = s->be->uri_auth; |
| 3717 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3718 | /* scope_txt = search pattern + search query, si->appctx.ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3719 | scope_txt[0] = 0; |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3720 | if (si->appctx.ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3721 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3722 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + si->appctx.ctx.stats.scope_str, si->appctx.ctx.stats.scope_len); |
| 3723 | scope_txt[strlen(STAT_SCOPE_PATTERN) + si->appctx.ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | /* We don't want to land on the posted stats page because a refresh will |
| 3727 | * repost the data. We don't want this to happen on accident so we redirect |
| 3728 | * the browse to the stats page with a GET. |
| 3729 | */ |
| 3730 | chunk_printf(&trash, |
| 3731 | "HTTP/1.1 303 See Other\r\n" |
| 3732 | "Cache-Control: no-cache\r\n" |
| 3733 | "Content-Type: text/plain\r\n" |
| 3734 | "Connection: close\r\n" |
| 3735 | "Location: %s;st=%s%s%s%s\r\n" |
| 3736 | "\r\n", |
| 3737 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3738 | ((si->appctx.ctx.stats.st_code > STAT_STATUS_INIT) && |
| 3739 | (si->appctx.ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 3740 | stat_status_codes[si->appctx.ctx.stats.st_code]) ? |
| 3741 | stat_status_codes[si->appctx.ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3742 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3743 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3744 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3745 | scope_txt); |
| 3746 | |
| 3747 | s->txn.status = 303; |
| 3748 | s->logs.tv_request = now; |
| 3749 | |
| 3750 | if (bi_putchk(si->ib, &trash) == -1) |
| 3751 | return 0; |
| 3752 | |
| 3753 | return 1; |
| 3754 | } |
| 3755 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3756 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 3757 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3758 | * si->appctx.st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3759 | * automatically unregisters itself once transfer is complete. |
| 3760 | */ |
| 3761 | static void http_stats_io_handler(struct stream_interface *si) |
| 3762 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3763 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3764 | struct channel *req = si->ob; |
| 3765 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3766 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3767 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 3768 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3769 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3770 | /* check that the output is not closed */ |
| 3771 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3772 | si->appctx.st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3773 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3774 | /* all states are processed in sequence */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3775 | if (si->appctx.st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3776 | if (stats_send_http_headers(si)) { |
| 3777 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3778 | si->appctx.st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3779 | else |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3780 | si->appctx.st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3781 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3782 | } |
| 3783 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3784 | if (si->appctx.st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3785 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3786 | si->appctx.st0 = STAT_HTTP_DONE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3787 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3788 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3789 | if (si->appctx.st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3790 | if (stats_process_http_post(si)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3791 | si->appctx.st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3792 | else if (si->ob->flags & CF_SHUTR) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3793 | si->appctx.st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3794 | } |
| 3795 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3796 | if (si->appctx.st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3797 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3798 | si->appctx.st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3799 | } |
| 3800 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3801 | if (si->appctx.st0 == STAT_HTTP_DONE) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3802 | si_shutw(si); |
| 3803 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3804 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 3805 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3806 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3807 | if (si->appctx.st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 3808 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 3809 | si_shutr(si); |
| 3810 | res->flags |= CF_READ_NULL; |
| 3811 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3812 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3813 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3814 | /* update all other flags and resync with the other side */ |
| 3815 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3816 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3817 | /* we don't want to expire timeouts while we're processing requests */ |
| 3818 | si->ib->rex = TICK_ETERNITY; |
| 3819 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3820 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3821 | out: |
| 3822 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 3823 | /* check that we have released everything then unregister */ |
| 3824 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3825 | } |
| 3826 | } |
| 3827 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3828 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3829 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 3830 | { |
| 3831 | if (!conn->ctrl) |
| 3832 | return "NONE"; |
| 3833 | return conn->ctrl->name; |
| 3834 | } |
| 3835 | |
| 3836 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 3837 | { |
| 3838 | static char ptr[17]; |
| 3839 | |
| 3840 | if (!conn->xprt) |
| 3841 | return "NONE"; |
| 3842 | |
| 3843 | if (conn->xprt == &raw_sock) |
| 3844 | return "RAW"; |
| 3845 | |
| 3846 | #ifdef USE_OPENSSL |
| 3847 | if (conn->xprt == &ssl_sock) |
| 3848 | return "SSL"; |
| 3849 | #endif |
| 3850 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 3851 | return ptr; |
| 3852 | } |
| 3853 | |
| 3854 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 3855 | { |
| 3856 | static char ptr[17]; |
| 3857 | |
| 3858 | if (!conn->data) |
| 3859 | return "NONE"; |
| 3860 | |
| 3861 | if (conn->data == &sess_conn_cb) |
| 3862 | return "SESS"; |
| 3863 | |
| 3864 | if (conn->data == &si_conn_cb) |
| 3865 | return "STRM"; |
| 3866 | |
| 3867 | if (conn->data == &check_conn_cb) |
| 3868 | return "CHCK"; |
| 3869 | |
| 3870 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 3871 | return ptr; |
| 3872 | } |
| 3873 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 3874 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3875 | * 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] | 3876 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 3877 | * 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] | 3878 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3879 | 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] | 3880 | { |
| 3881 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3882 | extern const char *monthname[12]; |
| 3883 | char pn[INET6_ADDRSTRLEN]; |
| 3884 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3885 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3886 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3887 | if (si->appctx.ctx.sess.section > 0 && si->appctx.ctx.sess.uid != sess->uniq_id) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3888 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3889 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 3890 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3891 | return 0; |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3892 | si->appctx.ctx.sess.uid = 0; |
| 3893 | si->appctx.ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3894 | return 1; |
| 3895 | } |
| 3896 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3897 | switch (si->appctx.ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3898 | case 0: /* main status of the session */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3899 | si->appctx.ctx.sess.uid = sess->uniq_id; |
| 3900 | si->appctx.ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3901 | /* fall through */ |
| 3902 | |
| 3903 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3904 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3905 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3906 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3907 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3908 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 3909 | 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] | 3910 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 3911 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3912 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 3913 | switch ((obj_type(sess->si[0].end) == OBJ_TYPE_CONN) ? |
| 3914 | addr_to_str(&sess->si[0].conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3915 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3916 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3917 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3918 | pn, get_host_port(&sess->si[0].conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3919 | break; |
| 3920 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3921 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3922 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3923 | default: |
| 3924 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3925 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3926 | break; |
| 3927 | } |
| 3928 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3929 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3930 | " 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] | 3931 | 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] | 3932 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3933 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3934 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3935 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 3936 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 3937 | sess->listener ? sess->listener->luid : 0); |
| 3938 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 3939 | if (obj_type(sess->si[0].end) == OBJ_TYPE_CONN) |
| 3940 | conn_get_to_addr(sess->si[0].conn); |
| 3941 | |
| 3942 | switch ((obj_type(sess->si[0].end) == OBJ_TYPE_CONN) ? |
| 3943 | addr_to_str(&sess->si[0].conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3944 | case AF_INET: |
| 3945 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3946 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3947 | pn, get_host_port(&sess->si[0].conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3948 | break; |
| 3949 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3950 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3951 | break; |
| 3952 | default: |
| 3953 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3954 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3955 | break; |
| 3956 | } |
| 3957 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3958 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3959 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3960 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3961 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3962 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 3963 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3964 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3965 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 3966 | if (obj_type(sess->si[1].end) == OBJ_TYPE_CONN) |
| 3967 | conn_get_from_addr(sess->si[1].conn); |
| 3968 | |
| 3969 | switch ((obj_type(sess->si[1].end) == OBJ_TYPE_CONN) ? |
| 3970 | addr_to_str(&sess->si[1].conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3971 | case AF_INET: |
| 3972 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3973 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3974 | pn, get_host_port(&sess->si[1].conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3975 | break; |
| 3976 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3977 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3978 | break; |
| 3979 | default: |
| 3980 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3981 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3982 | break; |
| 3983 | } |
| 3984 | |
| 3985 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3986 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3987 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 3988 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 3989 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3990 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3991 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3992 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 3993 | if (obj_type(sess->si[1].end) == OBJ_TYPE_CONN) |
| 3994 | conn_get_to_addr(sess->si[1].conn); |
| 3995 | |
| 3996 | switch ((obj_type(sess->si[1].end) == OBJ_TYPE_CONN) ? |
| 3997 | addr_to_str(&sess->si[1].conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3998 | case AF_INET: |
| 3999 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4000 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4001 | pn, get_host_port(&sess->si[1].conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4002 | break; |
| 4003 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4004 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4005 | break; |
| 4006 | default: |
| 4007 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4008 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4009 | break; |
| 4010 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4011 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4012 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4013 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4014 | sess->task, |
| 4015 | sess->task->state, |
| 4016 | sess->task->nice, sess->task->calls, |
| 4017 | sess->task->expire ? |
| 4018 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4019 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4020 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4021 | task_in_rq(sess->task) ? ", running" : ""); |
| 4022 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4023 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4024 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4025 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4026 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4027 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4028 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4029 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4030 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4031 | |
| 4032 | chunk_appendf(&trash, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4033 | " si[0]=%p (state=%s flags=0x%02x endp0=%s:%p conn0=%p exp=%s, et=0x%03x)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4034 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4035 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4036 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4037 | obj_type_name(sess->si[0].end), |
| 4038 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4039 | sess->si[0].conn, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4040 | sess->si[0].exp ? |
| 4041 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4042 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4043 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4044 | sess->si[0].err_type); |
| 4045 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4046 | chunk_appendf(&trash, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4047 | " si[1]=%p (state=%s flags=0x%02x endp1=%s:%p conn1=%p exp=%s, et=0x%03x)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4048 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4049 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4050 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4051 | obj_type_name(sess->si[1].end), |
| 4052 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4053 | sess->si[1].conn, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4054 | sess->si[1].exp ? |
| 4055 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4056 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4057 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4058 | sess->si[1].err_type); |
| 4059 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4060 | if (obj_type(sess->si[0].end) == OBJ_TYPE_CONN) { |
| 4061 | chunk_appendf(&trash, |
| 4062 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
| 4063 | sess->si[0].conn, |
| 4064 | get_conn_ctrl_name(sess->si[0].conn), |
| 4065 | get_conn_xprt_name(sess->si[0].conn), |
| 4066 | get_conn_data_name(sess->si[0].conn), |
| 4067 | obj_type_name(sess->si[0].conn->target), |
| 4068 | obj_base_ptr(sess->si[0].conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4069 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4070 | chunk_appendf(&trash, |
| 4071 | " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n", |
| 4072 | sess->si[0].conn->flags, |
| 4073 | sess->si[0].conn->t.sock.fd, |
| 4074 | sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].spec_e : 0, |
| 4075 | sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].spec_p : 0, |
| 4076 | sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].updated : 0); |
| 4077 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4078 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4079 | if (obj_type(sess->si[1].end) == OBJ_TYPE_CONN) { |
| 4080 | chunk_appendf(&trash, |
| 4081 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
| 4082 | sess->si[1].conn, |
| 4083 | get_conn_ctrl_name(sess->si[1].conn), |
| 4084 | get_conn_xprt_name(sess->si[1].conn), |
| 4085 | get_conn_data_name(sess->si[1].conn), |
| 4086 | obj_type_name(sess->si[1].conn->target), |
| 4087 | obj_base_ptr(sess->si[1].conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4088 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4089 | chunk_appendf(&trash, |
| 4090 | " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n", |
| 4091 | sess->si[1].conn->flags, |
| 4092 | sess->si[1].conn->t.sock.fd, |
| 4093 | sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].spec_e : 0, |
| 4094 | sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].spec_p : 0, |
| 4095 | sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].updated : 0); |
| 4096 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4097 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4098 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4099 | " 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] | 4100 | " an_exp=%s", |
| 4101 | sess->req, |
| 4102 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4103 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4104 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4105 | sess->req->analyse_exp ? |
| 4106 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 4107 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4108 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4109 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4110 | " rex=%s", |
| 4111 | sess->req->rex ? |
| 4112 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4113 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4114 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4115 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4116 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4117 | " 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] | 4118 | sess->req->wex ? |
| 4119 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4120 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4121 | sess->req->buf, |
| 4122 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4123 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4124 | sess->txn.req.next, sess->req->buf->i, |
| 4125 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4126 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4127 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4128 | " 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] | 4129 | " an_exp=%s", |
| 4130 | sess->rep, |
| 4131 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4132 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4133 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4134 | sess->rep->analyse_exp ? |
| 4135 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 4136 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4137 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4138 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4139 | " rex=%s", |
| 4140 | sess->rep->rex ? |
| 4141 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4142 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4143 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4144 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4145 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4146 | " 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] | 4147 | sess->rep->wex ? |
| 4148 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4149 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4150 | sess->rep->buf, |
| 4151 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4152 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4153 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4154 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4155 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4156 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4157 | return 0; |
| 4158 | |
| 4159 | /* use other states to dump the contents */ |
| 4160 | } |
| 4161 | /* end of dump */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4162 | si->appctx.ctx.sess.uid = 0; |
| 4163 | si->appctx.ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4164 | return 1; |
| 4165 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4166 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4167 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4168 | * 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] | 4169 | * to be called again, otherwise non-zero. It is designed to be called |
| 4170 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4171 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4172 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4173 | { |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4174 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4175 | /* If we're forced to shut down, we might have to remove our |
| 4176 | * reference to the last session being dumped. |
| 4177 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4178 | if (si->appctx.st2 == STAT_ST_LIST) { |
| 4179 | if (!LIST_ISEMPTY(&si->appctx.ctx.sess.bref.users)) { |
| 4180 | LIST_DEL(&si->appctx.ctx.sess.bref.users); |
| 4181 | LIST_INIT(&si->appctx.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4182 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4183 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4184 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4185 | } |
| 4186 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4187 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4188 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4189 | switch (si->appctx.st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4190 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4191 | /* the function had not been called yet, let's prepare the |
| 4192 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4193 | * pointer to the first in the global list. When a target |
| 4194 | * session is being destroyed, it is responsible for updating |
| 4195 | * this pointer. We know we have reached the end when this |
| 4196 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4197 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4198 | LIST_INIT(&si->appctx.ctx.sess.bref.users); |
| 4199 | si->appctx.ctx.sess.bref.ref = sessions.n; |
| 4200 | si->appctx.st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4201 | /* fall through */ |
| 4202 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4203 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4204 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4205 | if (!LIST_ISEMPTY(&si->appctx.ctx.sess.bref.users)) { |
| 4206 | LIST_DEL(&si->appctx.ctx.sess.bref.users); |
| 4207 | LIST_INIT(&si->appctx.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | /* and start from where we stopped */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4211 | while (si->appctx.ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 4212 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4213 | struct session *curr_sess; |
| 4214 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4215 | curr_sess = LIST_ELEM(si->appctx.ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4216 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4217 | if (si->appctx.ctx.sess.target) { |
| 4218 | if (si->appctx.ctx.sess.target != (void *)-1 && si->appctx.ctx.sess.target != curr_sess) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4219 | goto next_sess; |
| 4220 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4221 | LIST_ADDQ(&curr_sess->back_refs, &si->appctx.ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4222 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4223 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4224 | return 0; |
| 4225 | |
| 4226 | /* session dump complete */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4227 | LIST_DEL(&si->appctx.ctx.sess.bref.users); |
| 4228 | LIST_INIT(&si->appctx.ctx.sess.bref.users); |
| 4229 | if (si->appctx.ctx.sess.target != (void *)-1) { |
| 4230 | si->appctx.ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4231 | break; |
| 4232 | } |
| 4233 | else |
| 4234 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4235 | } |
| 4236 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4237 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4238 | "%p: proto=%s", |
| 4239 | curr_sess, |
| 4240 | curr_sess->listener->proto->name); |
| 4241 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4242 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4243 | switch ((obj_type(curr_sess->si[0].end) == OBJ_TYPE_CONN) ? |
| 4244 | addr_to_str(&curr_sess->si[0].conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 4245 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4246 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4247 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4248 | " src=%s:%d fe=%s be=%s srv=%s", |
| 4249 | pn, |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4250 | get_host_port(&curr_sess->si[0].conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4251 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4252 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4253 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4254 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4255 | break; |
| 4256 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4257 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4258 | " src=unix:%d fe=%s be=%s srv=%s", |
| 4259 | curr_sess->listener->luid, |
| 4260 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4261 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4262 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4263 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4264 | break; |
| 4265 | } |
| 4266 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4267 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 4268 | " ts=%02x age=%s calls=%d", |
| 4269 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 4270 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 4271 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4272 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4273 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 4274 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4275 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4276 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4277 | curr_sess->req->analysers, |
| 4278 | curr_sess->req->rex ? |
| 4279 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 4280 | TICKS_TO_MS(1000)) : ""); |
| 4281 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4282 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4283 | ",wx=%s", |
| 4284 | curr_sess->req->wex ? |
| 4285 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 4286 | TICKS_TO_MS(1000)) : ""); |
| 4287 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4288 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4289 | ",ax=%s]", |
| 4290 | curr_sess->req->analyse_exp ? |
| 4291 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 4292 | TICKS_TO_MS(1000)) : ""); |
| 4293 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4294 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 4295 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4296 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4297 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4298 | curr_sess->rep->analysers, |
| 4299 | curr_sess->rep->rex ? |
| 4300 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 4301 | TICKS_TO_MS(1000)) : ""); |
| 4302 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4303 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4304 | ",wx=%s", |
| 4305 | curr_sess->rep->wex ? |
| 4306 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 4307 | TICKS_TO_MS(1000)) : ""); |
| 4308 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4309 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4310 | ",ax=%s]", |
| 4311 | curr_sess->rep->analyse_exp ? |
| 4312 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 4313 | TICKS_TO_MS(1000)) : ""); |
| 4314 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4315 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4316 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 4317 | curr_sess->si[0].state, |
| 4318 | curr_sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4319 | (obj_type(curr_sess->si[0].end) == OBJ_TYPE_CONN) ? |
| 4320 | curr_sess->si[0].conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4321 | curr_sess->si[0].exp ? |
| 4322 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 4323 | TICKS_TO_MS(1000)) : ""); |
| 4324 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4325 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4326 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 4327 | curr_sess->si[1].state, |
| 4328 | curr_sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4329 | (obj_type(curr_sess->si[1].end) == OBJ_TYPE_CONN) ? |
| 4330 | curr_sess->si[1].conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4331 | curr_sess->si[1].exp ? |
| 4332 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 4333 | TICKS_TO_MS(1000)) : ""); |
| 4334 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4335 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4336 | " exp=%s", |
| 4337 | curr_sess->task->expire ? |
| 4338 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 4339 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 4340 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4341 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4342 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4343 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4344 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4345 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4346 | /* let's try again later from this session. We add ourselves into |
| 4347 | * this session's users so that it can remove us upon termination. |
| 4348 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4349 | LIST_ADDQ(&curr_sess->back_refs, &si->appctx.ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4350 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4351 | } |
| 4352 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4353 | next_sess: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4354 | si->appctx.ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4355 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4356 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4357 | if (si->appctx.ctx.sess.target && si->appctx.ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4358 | /* specified session not found */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4359 | if (si->appctx.ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4360 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4361 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4362 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4363 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4364 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4365 | return 0; |
| 4366 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4367 | si->appctx.ctx.sess.target = NULL; |
| 4368 | si->appctx.ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4369 | return 1; |
| 4370 | } |
| 4371 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4372 | si->appctx.st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4373 | /* fall through */ |
| 4374 | |
| 4375 | default: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4376 | si->appctx.st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4377 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4378 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 4379 | } |
| 4380 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4381 | /* This is called when the stream interface is closed. For instance, upon an |
| 4382 | * external abort, we won't call the i/o handler anymore so we may need to |
| 4383 | * remove back references to the session currently being dumped. |
| 4384 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 4385 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4386 | { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4387 | if (si->appctx.st0 == STAT_CLI_O_SESS && si->appctx.st2 == STAT_ST_LIST) { |
| 4388 | if (!LIST_ISEMPTY(&si->appctx.ctx.sess.bref.users)) |
| 4389 | LIST_DEL(&si->appctx.ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4390 | } |
| 4391 | } |
| 4392 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4393 | /* This function is used to either dump tables states (when action is set |
| 4394 | * 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] | 4395 | * It returns 0 if the output buffer is full and it needs to be called |
| 4396 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4397 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4398 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4399 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4400 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4401 | struct ebmb_node *eb; |
| 4402 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4403 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4404 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4405 | |
| 4406 | /* |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4407 | * We have 3 possible states in si->appctx.st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4408 | * - STAT_ST_INIT : the first call |
| 4409 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4410 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4411 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4412 | * and the entry pointer points to the next entry to be dumped, |
| 4413 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4414 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4415 | * data though. |
| 4416 | */ |
| 4417 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4418 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4419 | /* in case of abort, remove any refcount we might have set on an entry */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4420 | if (si->appctx.st2 == STAT_ST_LIST) { |
| 4421 | si->appctx.ctx.table.entry->ref_cnt--; |
| 4422 | stksess_kill_if_expired(&si->appctx.ctx.table.proxy->table, si->appctx.ctx.table.entry); |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 4423 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4424 | return 1; |
| 4425 | } |
| 4426 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4427 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4428 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4429 | while (si->appctx.st2 != STAT_ST_FIN) { |
| 4430 | switch (si->appctx.st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4431 | case STAT_ST_INIT: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4432 | si->appctx.ctx.table.proxy = si->appctx.ctx.table.target; |
| 4433 | if (!si->appctx.ctx.table.proxy) |
| 4434 | si->appctx.ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4435 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4436 | si->appctx.ctx.table.entry = NULL; |
| 4437 | si->appctx.st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4438 | break; |
| 4439 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4440 | case STAT_ST_INFO: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4441 | if (!si->appctx.ctx.table.proxy || |
| 4442 | (si->appctx.ctx.table.target && |
| 4443 | si->appctx.ctx.table.proxy != si->appctx.ctx.table.target)) { |
| 4444 | si->appctx.st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4445 | break; |
| 4446 | } |
| 4447 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4448 | if (si->appctx.ctx.table.proxy->table.size) { |
| 4449 | if (show && !stats_dump_table_head_to_buffer(&trash, si, si->appctx.ctx.table.proxy, |
| 4450 | si->appctx.ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4451 | return 0; |
| 4452 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4453 | if (si->appctx.ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 4454 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4455 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4456 | eb = ebmb_first(&si->appctx.ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4457 | if (eb) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4458 | si->appctx.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 4459 | si->appctx.ctx.table.entry->ref_cnt++; |
| 4460 | si->appctx.st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4461 | break; |
| 4462 | } |
| 4463 | } |
| 4464 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4465 | si->appctx.ctx.table.proxy = si->appctx.ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4466 | break; |
| 4467 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4468 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4469 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4470 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4471 | if (si->appctx.ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4472 | /* we're filtering on some data contents */ |
| 4473 | void *ptr; |
| 4474 | long long data; |
| 4475 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4476 | dt = si->appctx.ctx.table.data_type; |
| 4477 | ptr = stktable_data_ptr(&si->appctx.ctx.table.proxy->table, |
| 4478 | si->appctx.ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4479 | dt); |
| 4480 | |
| 4481 | data = 0; |
| 4482 | switch (stktable_data_types[dt].std_type) { |
| 4483 | case STD_T_SINT: |
| 4484 | data = stktable_data_cast(ptr, std_t_sint); |
| 4485 | break; |
| 4486 | case STD_T_UINT: |
| 4487 | data = stktable_data_cast(ptr, std_t_uint); |
| 4488 | break; |
| 4489 | case STD_T_ULL: |
| 4490 | data = stktable_data_cast(ptr, std_t_ull); |
| 4491 | break; |
| 4492 | case STD_T_FRQP: |
| 4493 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4494 | si->appctx.ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4495 | break; |
| 4496 | } |
| 4497 | |
| 4498 | /* skip the entry if the data does not match the test and the value */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4499 | if ((data < si->appctx.ctx.table.value && |
| 4500 | (si->appctx.ctx.table.data_op == STD_OP_EQ || |
| 4501 | si->appctx.ctx.table.data_op == STD_OP_GT || |
| 4502 | si->appctx.ctx.table.data_op == STD_OP_GE)) || |
| 4503 | (data == si->appctx.ctx.table.value && |
| 4504 | (si->appctx.ctx.table.data_op == STD_OP_NE || |
| 4505 | si->appctx.ctx.table.data_op == STD_OP_GT || |
| 4506 | si->appctx.ctx.table.data_op == STD_OP_LT)) || |
| 4507 | (data > si->appctx.ctx.table.value && |
| 4508 | (si->appctx.ctx.table.data_op == STD_OP_EQ || |
| 4509 | si->appctx.ctx.table.data_op == STD_OP_LT || |
| 4510 | si->appctx.ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4511 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4512 | } |
| 4513 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4514 | if (show && !skip_entry && |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4515 | !stats_dump_table_entry_to_buffer(&trash, si, si->appctx.ctx.table.proxy, |
| 4516 | si->appctx.ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 4517 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4518 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4519 | si->appctx.ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4520 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4521 | eb = ebmb_next(&si->appctx.ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4522 | if (eb) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4523 | struct stksess *old = si->appctx.ctx.table.entry; |
| 4524 | si->appctx.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 4525 | if (show) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4526 | stksess_kill_if_expired(&si->appctx.ctx.table.proxy->table, old); |
| 4527 | else if (!skip_entry && !si->appctx.ctx.table.entry->ref_cnt) |
| 4528 | stksess_kill(&si->appctx.ctx.table.proxy->table, old); |
| 4529 | si->appctx.ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4530 | break; |
| 4531 | } |
| 4532 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4533 | |
| 4534 | if (show) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4535 | stksess_kill_if_expired(&si->appctx.ctx.table.proxy->table, si->appctx.ctx.table.entry); |
| 4536 | else if (!skip_entry && !si->appctx.ctx.table.entry->ref_cnt) |
| 4537 | stksess_kill(&si->appctx.ctx.table.proxy->table, si->appctx.ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4538 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4539 | si->appctx.ctx.table.proxy = si->appctx.ctx.table.proxy->next; |
| 4540 | si->appctx.st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4541 | break; |
| 4542 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4543 | case STAT_ST_END: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4544 | si->appctx.st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4545 | break; |
| 4546 | } |
| 4547 | } |
| 4548 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4549 | } |
| 4550 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4551 | /* 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] | 4552 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 4553 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 4554 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 4555 | * lines are respected within the limit of 70 output chars. Lines that are |
| 4556 | * continuation of a previous truncated line begin with "+" instead of " " |
| 4557 | * after the offset. The new pointer is returned. |
| 4558 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4559 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 4560 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4561 | { |
| 4562 | int end; |
| 4563 | unsigned char c; |
| 4564 | |
| 4565 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4566 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4567 | return ptr; |
| 4568 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 4569 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4570 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4571 | while (ptr < len && ptr < bsize) { |
| 4572 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4573 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4574 | if (out->len > end - 2) |
| 4575 | break; |
| 4576 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4577 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4578 | if (out->len > end - 3) |
| 4579 | break; |
| 4580 | out->str[out->len++] = '\\'; |
| 4581 | switch (c) { |
| 4582 | case '\t': c = 't'; break; |
| 4583 | case '\n': c = 'n'; break; |
| 4584 | case '\r': c = 'r'; break; |
| 4585 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4586 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4587 | } |
| 4588 | out->str[out->len++] = c; |
| 4589 | } else { |
| 4590 | if (out->len > end - 5) |
| 4591 | break; |
| 4592 | out->str[out->len++] = '\\'; |
| 4593 | out->str[out->len++] = 'x'; |
| 4594 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 4595 | out->str[out->len++] = hextab[c & 0xF]; |
| 4596 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4597 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4598 | /* we had a line break, let's return now */ |
| 4599 | out->str[out->len++] = '\n'; |
| 4600 | *line = ptr; |
| 4601 | return ptr; |
| 4602 | } |
| 4603 | } |
| 4604 | /* we have an incomplete line, we return it as-is */ |
| 4605 | out->str[out->len++] = '\n'; |
| 4606 | return ptr; |
| 4607 | } |
| 4608 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4609 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4610 | * 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] | 4611 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4612 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4613 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4614 | { |
| 4615 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4616 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4617 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4618 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4619 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4620 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4621 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4622 | if (!si->appctx.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4623 | /* the function had not been called yet, let's prepare the |
| 4624 | * buffer for a response. |
| 4625 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4626 | struct tm tm; |
| 4627 | |
| 4628 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4629 | 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] | 4630 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4631 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 4632 | error_snapshot_id); |
| 4633 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4634 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4635 | /* Socket buffer full. Let's try again later from the same point */ |
| 4636 | return 0; |
| 4637 | } |
| 4638 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4639 | si->appctx.ctx.errors.px = proxy; |
| 4640 | si->appctx.ctx.errors.buf = 0; |
| 4641 | si->appctx.ctx.errors.bol = 0; |
| 4642 | si->appctx.ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | /* we have two inner loops here, one for the proxy, the other one for |
| 4646 | * the buffer. |
| 4647 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4648 | while (si->appctx.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4649 | struct error_snapshot *es; |
| 4650 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4651 | if (si->appctx.ctx.errors.buf == 0) |
| 4652 | es = &si->appctx.ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4653 | else |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4654 | es = &si->appctx.ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4655 | |
| 4656 | if (!es->when.tv_sec) |
| 4657 | goto next; |
| 4658 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4659 | if (si->appctx.ctx.errors.iid >= 0 && |
| 4660 | si->appctx.ctx.errors.px->uuid != si->appctx.ctx.errors.iid && |
| 4661 | es->oe->uuid != si->appctx.ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4662 | goto next; |
| 4663 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4664 | if (si->appctx.ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4665 | /* just print headers now */ |
| 4666 | |
| 4667 | char pn[INET6_ADDRSTRLEN]; |
| 4668 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4669 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4670 | |
| 4671 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4672 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4673 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4674 | 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] | 4675 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4676 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 4677 | case AF_INET: |
| 4678 | case AF_INET6: |
| 4679 | port = get_host_port(&es->src); |
| 4680 | break; |
| 4681 | default: |
| 4682 | port = 0; |
| 4683 | } |
| 4684 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4685 | switch (si->appctx.ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4686 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4687 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4688 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4689 | " backend %s (#%d)", |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4690 | si->appctx.ctx.errors.px->id, si->appctx.ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4691 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 4692 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4693 | break; |
| 4694 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4695 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4696 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4697 | " frontend %s (#%d)", |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4698 | si->appctx.ctx.errors.px->id, si->appctx.ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4699 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4700 | break; |
| 4701 | } |
| 4702 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4703 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4704 | ", server %s (#%d), event #%u\n" |
| 4705 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 4706 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 4707 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 4708 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 4709 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 4710 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 4711 | es->ev_id, |
| 4712 | pn, port, es->sid, es->s_flags, |
| 4713 | es->state, es->m_flags, es->t_flags, |
| 4714 | es->m_clen, es->m_blen, |
| 4715 | es->b_flags, es->b_out, es->b_tot, |
| 4716 | es->len, es->b_wrap, es->pos); |
| 4717 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4718 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4719 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4720 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4721 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4722 | si->appctx.ctx.errors.ptr = 0; |
| 4723 | si->appctx.ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4724 | } |
| 4725 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4726 | if (si->appctx.ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4727 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4728 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4729 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4730 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4731 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4732 | goto next; |
| 4733 | } |
| 4734 | |
| 4735 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4736 | while (si->appctx.ctx.errors.ptr < es->len && si->appctx.ctx.errors.ptr < sizeof(es->buf)) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4737 | int newptr; |
| 4738 | int newline; |
| 4739 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4740 | newline = si->appctx.ctx.errors.bol; |
| 4741 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, si->appctx.ctx.errors.ptr); |
| 4742 | if (newptr == si->appctx.ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4743 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4744 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4745 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4746 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4747 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4748 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4749 | si->appctx.ctx.errors.ptr = newptr; |
| 4750 | si->appctx.ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4751 | }; |
| 4752 | next: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4753 | si->appctx.ctx.errors.bol = 0; |
| 4754 | si->appctx.ctx.errors.ptr = -1; |
| 4755 | si->appctx.ctx.errors.buf++; |
| 4756 | if (si->appctx.ctx.errors.buf > 1) { |
| 4757 | si->appctx.ctx.errors.buf = 0; |
| 4758 | si->appctx.ctx.errors.px = si->appctx.ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4759 | } |
| 4760 | } |
| 4761 | |
| 4762 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4763 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4764 | } |
| 4765 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4766 | /* parse the "level" argument on the bind lines */ |
| 4767 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 4768 | { |
| 4769 | if (!*args[cur_arg + 1]) { |
| 4770 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 4771 | return ERR_ALERT | ERR_FATAL; |
| 4772 | } |
| 4773 | |
| 4774 | if (!strcmp(args[cur_arg+1], "user")) |
| 4775 | conf->level = ACCESS_LVL_USER; |
| 4776 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 4777 | conf->level = ACCESS_LVL_OPER; |
| 4778 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 4779 | conf->level = ACCESS_LVL_ADMIN; |
| 4780 | else { |
| 4781 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 4782 | args[cur_arg], args[cur_arg+1]); |
| 4783 | return ERR_ALERT | ERR_FATAL; |
| 4784 | } |
| 4785 | |
| 4786 | return 0; |
| 4787 | } |
| 4788 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4789 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4790 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4791 | .name = "<STATS>", /* used for logging */ |
| 4792 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 4793 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4794 | }; |
| 4795 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4796 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4797 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4798 | .name = "<CLI>", /* used for logging */ |
| 4799 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4800 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4801 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4802 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 4803 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4804 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 4805 | { 0, NULL, NULL }, |
| 4806 | }}; |
| 4807 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4808 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 4809 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 4810 | { NULL, NULL, 0 }, |
| 4811 | }}; |
| 4812 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4813 | __attribute__((constructor)) |
| 4814 | static void __dumpstats_module_init(void) |
| 4815 | { |
| 4816 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4817 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4818 | } |
| 4819 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4820 | /* |
| 4821 | * Local variables: |
| 4822 | * c-indent-level: 8 |
| 4823 | * c-basic-offset: 8 |
| 4824 | * End: |
| 4825 | */ |