Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 2 | * Functions dedicated to statistics output and the stats socket |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 27 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 28 | #include <common/compat.h> |
| 29 | #include <common/config.h> |
| 30 | #include <common/debug.h> |
| 31 | #include <common/memory.h> |
| 32 | #include <common/mini-clist.h> |
| 33 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 34 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 35 | #include <common/time.h> |
| 36 | #include <common/uri_auth.h> |
| 37 | #include <common/version.h> |
| 38 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | |
| 41 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 42 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 43 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 44 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 45 | #include <proto/dumpstats.h> |
| 46 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 47 | #include <proto/freq_ctr.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 48 | #include <proto/log.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 49 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 50 | #include <proto/listener.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 51 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 52 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 53 | #include <proto/proxy.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 54 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 55 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 56 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 57 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 58 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 59 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 60 | #ifdef USE_OPENSSL |
| 61 | #include <proto/ssl_sock.h> |
| 62 | #endif |
| 63 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 64 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 65 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 66 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 67 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 68 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 69 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 70 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 71 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 72 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 73 | * cli_io_handler() |
| 74 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 75 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 76 | * -> stats_dump_info_to_buffer() // "show info" |
| 77 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 78 | * -> stats_dump_csv_header() |
| 79 | * -> stats_dump_proxy_to_buffer() |
| 80 | * -> stats_dump_fe_stats() |
| 81 | * -> stats_dump_li_stats() |
| 82 | * -> stats_dump_sv_stats() |
| 83 | * -> stats_dump_be_stats() |
| 84 | * |
| 85 | * http_stats_io_handler() |
| 86 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 87 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 88 | * -> stats_dump_html_head() // emits the HTML headers |
| 89 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 90 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 91 | * -> stats_dump_html_px_hdr() |
| 92 | * -> stats_dump_fe_stats() |
| 93 | * -> stats_dump_li_stats() |
| 94 | * -> stats_dump_sv_stats() |
| 95 | * -> stats_dump_be_stats() |
| 96 | * -> stats_dump_html_px_end() |
| 97 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 98 | */ |
| 99 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 100 | static struct si_applet cli_applet; |
| 101 | |
| 102 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 103 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 104 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 105 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 106 | " help : this message\n" |
| 107 | " prompt : toggle interactive mode with prompt\n" |
| 108 | " quit : disconnect\n" |
| 109 | " show info : report information about the running process\n" |
| 110 | " show stat : report counters for each proxy and server\n" |
| 111 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 112 | " show sess [id] : report the list of current sessions or dump this session\n" |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 113 | " show table [id]: report table usage stats or dump this table's contents\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 114 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 115 | " set weight : change a server's weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 116 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 117 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 118 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 119 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 120 | " disable : put a server or frontend in maintenance mode\n" |
| 121 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 122 | " shutdown : kill a session or a frontend (eg:to release listening ports)\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 123 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 124 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 125 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 126 | "Permission denied\n" |
| 127 | ""; |
| 128 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 129 | /* data transmission states for the stats responses */ |
| 130 | enum { |
| 131 | STAT_ST_INIT = 0, |
| 132 | STAT_ST_HEAD, |
| 133 | STAT_ST_INFO, |
| 134 | STAT_ST_LIST, |
| 135 | STAT_ST_END, |
| 136 | STAT_ST_FIN, |
| 137 | }; |
| 138 | |
| 139 | /* data transmission states for the stats responses inside a proxy */ |
| 140 | enum { |
| 141 | STAT_PX_ST_INIT = 0, |
| 142 | STAT_PX_ST_TH, |
| 143 | STAT_PX_ST_FE, |
| 144 | STAT_PX_ST_LI, |
| 145 | STAT_PX_ST_SV, |
| 146 | STAT_PX_ST_BE, |
| 147 | STAT_PX_ST_END, |
| 148 | STAT_PX_ST_FIN, |
| 149 | }; |
| 150 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 151 | extern const char *stat_status_codes[]; |
| 152 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 153 | /* This function is called from the session-level accept() in order to instanciate |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 154 | * a new stats socket. It returns a positive value upon success, 0 if the session |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 155 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 156 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 157 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 158 | { |
Willy Tarreau | ce9dbcd | 2013-10-01 17:12:05 +0200 | [diff] [blame^] | 159 | /* we have a dedicated I/O handler for the CLI/stats, so we can safely |
| 160 | * release the pre-allocated connection that we will never use. |
| 161 | */ |
| 162 | pool_free2(pool2_connection, s->si[1].conn); |
| 163 | s->si[1].conn = NULL; |
| 164 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 165 | stream_int_register_handler(&s->si[1], &cli_applet); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 166 | s->target = &cli_applet.obj_type; // for logging only |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 167 | s->si[1].appctx.st1 = 0; |
| 168 | s->si[1].appctx.st0 = STAT_CLI_INIT; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 169 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 170 | tv_zero(&s->logs.tv_request); |
| 171 | s->logs.t_queue = 0; |
| 172 | s->logs.t_connect = 0; |
| 173 | s->logs.t_data = 0; |
| 174 | s->logs.t_close = 0; |
| 175 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 176 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 177 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 178 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 179 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 180 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 181 | if (s->listener->timeout) { |
| 182 | s->req->rto = *s->listener->timeout; |
| 183 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 184 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 185 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 188 | /* allocate a new stats frontend named <name>, and return it |
| 189 | * (or NULL in case of lack of memory). |
| 190 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 191 | 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] | 192 | { |
| 193 | struct proxy *fe; |
| 194 | |
| 195 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 196 | if (!fe) |
| 197 | return NULL; |
| 198 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 199 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 200 | fe->next = proxy; |
| 201 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 202 | fe->last_change = now.tv_sec; |
| 203 | fe->id = strdup("GLOBAL"); |
| 204 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 205 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 206 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 207 | fe->conf.file = strdup(file); |
| 208 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 209 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 210 | |
| 211 | /* the stats frontend is the only one able to assign ID #0 */ |
| 212 | fe->conf.id.key = fe->uuid = 0; |
| 213 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 214 | return fe; |
| 215 | } |
| 216 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 217 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 218 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 219 | * error message into the <err> buffer which will be preallocated. The trailing |
| 220 | * '\n' must not be written. The function must be called with <args> pointing to |
| 221 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 222 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 223 | 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] | 224 | struct proxy *defpx, const char *file, int line, |
| 225 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 226 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 227 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 228 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 229 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 230 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 231 | int cur_arg; |
| 232 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 233 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 234 | 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] | 235 | return -1; |
| 236 | } |
| 237 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 238 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 239 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 240 | 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] | 241 | return -1; |
| 242 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 245 | 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] | 246 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 247 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 248 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 249 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 250 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 251 | return -1; |
| 252 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 253 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 254 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 255 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 256 | static int bind_dumped; |
| 257 | struct bind_kw *kw; |
| 258 | |
| 259 | kw = bind_find_kw(args[cur_arg]); |
| 260 | if (kw) { |
| 261 | if (!kw->parse) { |
| 262 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 263 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 264 | return -1; |
| 265 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 266 | |
| 267 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 268 | if (err && *err) |
| 269 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 270 | else |
| 271 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 272 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 273 | return -1; |
| 274 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 275 | |
| 276 | cur_arg += 1 + kw->skip; |
| 277 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 278 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 279 | |
| 280 | if (!bind_dumped) { |
| 281 | bind_dump_kws(err); |
| 282 | indent_msg(err, 4); |
| 283 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 284 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 285 | |
| 286 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 287 | args[0], args[1], args[cur_arg], |
| 288 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 289 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 290 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 291 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 292 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 293 | l->maxconn = global.stats_fe->maxconn; |
| 294 | l->backlog = global.stats_fe->backlog; |
| 295 | l->timeout = &global.stats_fe->timeout.client; |
| 296 | l->accept = session_accept; |
| 297 | l->handler = process_session; |
| 298 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 299 | l->nice = -64; /* we want to boost priority for local stats */ |
| 300 | global.maxsock += l->maxconn; |
| 301 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 302 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 303 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 304 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 305 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 306 | |
| 307 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 308 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 309 | return -1; |
| 310 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 311 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 312 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 313 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 314 | return -1; |
| 315 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 316 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 317 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 318 | 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] | 319 | return -1; |
| 320 | } |
| 321 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 322 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 323 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 324 | else if (!strcmp(args[1], "maxconn")) { |
| 325 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 326 | |
| 327 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 328 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 329 | return -1; |
| 330 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 331 | |
| 332 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 333 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 334 | 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] | 335 | return -1; |
| 336 | } |
| 337 | } |
| 338 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 339 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 340 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 341 | int cur_arg = 2; |
| 342 | unsigned int set = 0; |
| 343 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 344 | if (!global.stats_fe) { |
| 345 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 346 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 347 | return -1; |
| 348 | } |
| 349 | } |
| 350 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 351 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 352 | unsigned int low, high; |
| 353 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 354 | if (strcmp(args[cur_arg], "all") == 0) { |
| 355 | set = 0; |
| 356 | break; |
| 357 | } |
| 358 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 359 | set |= 0x55555555; |
| 360 | } |
| 361 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 362 | set |= 0xAAAAAAAA; |
| 363 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 364 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 365 | char *dash = strchr(args[cur_arg], '-'); |
| 366 | |
| 367 | low = high = str2uic(args[cur_arg]); |
| 368 | if (dash) |
| 369 | high = str2uic(dash + 1); |
| 370 | |
| 371 | if (high < low) { |
| 372 | unsigned int swap = low; |
| 373 | low = high; |
| 374 | high = swap; |
| 375 | } |
| 376 | |
| 377 | if (low < 1 || high > 32) { |
| 378 | memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n", |
| 379 | args[0], args[1]); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 380 | return -1; |
| 381 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 382 | |
| 383 | while (low <= high) |
| 384 | set |= 1 << (low++ - 1); |
| 385 | } |
| 386 | else { |
| 387 | memprintf(err, |
| 388 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 389 | args[0], args[1]); |
| 390 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 391 | } |
| 392 | cur_arg++; |
| 393 | } |
| 394 | global.stats_fe->bind_proc = set; |
| 395 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 396 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 397 | 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] | 398 | return -1; |
| 399 | } |
| 400 | return 0; |
| 401 | } |
| 402 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 403 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 404 | * for clearing it if needed. |
| 405 | */ |
| 406 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 407 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 408 | chunk_appendf(&trash, |
| 409 | "# pxname,svname," |
| 410 | "qcur,qmax," |
| 411 | "scur,smax,slim,stot," |
| 412 | "bin,bout," |
| 413 | "dreq,dresp," |
| 414 | "ereq,econ,eresp," |
| 415 | "wretr,wredis," |
| 416 | "status,weight,act,bck," |
| 417 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 418 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 419 | "rate,rate_lim,rate_max," |
| 420 | "check_status,check_code,check_duration," |
| 421 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 422 | "req_rate,req_rate_max,req_tot," |
| 423 | "cli_abrt,srv_abrt," |
| 424 | "comp_in,comp_out,comp_byp,comp_rsp," |
| 425 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 426 | } |
| 427 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 428 | /* print a string of text buffer to <out>. The format is : |
| 429 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 430 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 431 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 432 | */ |
| 433 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 434 | { |
| 435 | unsigned char c; |
| 436 | int ptr = 0; |
| 437 | |
| 438 | while (buf[ptr] && ptr < bsize) { |
| 439 | c = buf[ptr]; |
| 440 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 441 | if (out->len > out->size - 1) |
| 442 | break; |
| 443 | out->str[out->len++] = c; |
| 444 | } |
| 445 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 446 | if (out->len > out->size - 2) |
| 447 | break; |
| 448 | out->str[out->len++] = '\\'; |
| 449 | switch (c) { |
| 450 | case ' ': c = ' '; break; |
| 451 | case '\t': c = 't'; break; |
| 452 | case '\n': c = 'n'; break; |
| 453 | case '\r': c = 'r'; break; |
| 454 | case '\e': c = 'e'; break; |
| 455 | case '\\': c = '\\'; break; |
| 456 | } |
| 457 | out->str[out->len++] = c; |
| 458 | } |
| 459 | else { |
| 460 | if (out->len > out->size - 4) |
| 461 | break; |
| 462 | out->str[out->len++] = '\\'; |
| 463 | out->str[out->len++] = 'x'; |
| 464 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 465 | out->str[out->len++] = hextab[c & 0xF]; |
| 466 | } |
| 467 | ptr++; |
| 468 | } |
| 469 | |
| 470 | return ptr; |
| 471 | } |
| 472 | |
| 473 | /* print a buffer in hexa. |
| 474 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 475 | */ |
| 476 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 477 | { |
| 478 | unsigned char c; |
| 479 | int ptr = 0; |
| 480 | |
| 481 | while (ptr < bsize) { |
| 482 | c = buf[ptr]; |
| 483 | |
| 484 | if (out->len > out->size - 2) |
| 485 | break; |
| 486 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 487 | out->str[out->len++] = hextab[c & 0xF]; |
| 488 | |
| 489 | ptr++; |
| 490 | } |
| 491 | return ptr; |
| 492 | } |
| 493 | |
| 494 | /* Dump the status of a table to a stream interface's |
| 495 | * read buffer. It returns 0 if the output buffer is full |
| 496 | * and needs to be called again, otherwise non-zero. |
| 497 | */ |
| 498 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 499 | struct proxy *proxy, struct proxy *target) |
| 500 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 501 | struct session *s = session_from_task(si->owner); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 502 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 503 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 504 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 505 | |
| 506 | /* any other information should be dumped here */ |
| 507 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 508 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 509 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 510 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 511 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 512 | return 0; |
| 513 | |
| 514 | return 1; |
| 515 | } |
| 516 | |
| 517 | /* Dump the a table entry to a stream interface's |
| 518 | * read buffer. It returns 0 if the output buffer is full |
| 519 | * and needs to be called again, otherwise non-zero. |
| 520 | */ |
| 521 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 522 | struct proxy *proxy, struct stksess *entry) |
| 523 | { |
| 524 | int dt; |
| 525 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 526 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 527 | |
| 528 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 529 | char addr[INET_ADDRSTRLEN]; |
| 530 | inet_ntop(AF_INET, (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_IPV6) { |
| 534 | char addr[INET6_ADDRSTRLEN]; |
| 535 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 536 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 537 | } |
| 538 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 539 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 540 | } |
| 541 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 542 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 543 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 544 | } |
| 545 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 546 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 547 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 548 | } |
| 549 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 550 | 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] | 551 | |
| 552 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 553 | void *ptr; |
| 554 | |
| 555 | if (proxy->table.data_ofs[dt] == 0) |
| 556 | continue; |
| 557 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 558 | 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] | 559 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 560 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 561 | |
| 562 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 563 | switch (stktable_data_types[dt].std_type) { |
| 564 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 565 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 566 | break; |
| 567 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 568 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 569 | break; |
| 570 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 571 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 572 | break; |
| 573 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 574 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 575 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 576 | proxy->table.data_arg[dt].u)); |
| 577 | break; |
| 578 | } |
| 579 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 580 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 581 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 582 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 583 | return 0; |
| 584 | |
| 585 | return 1; |
| 586 | } |
| 587 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 588 | 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] | 589 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 590 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 591 | struct proxy *px = si->appctx.ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 592 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 593 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 594 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 595 | long long value; |
| 596 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 597 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 598 | void *ptr; |
| 599 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 600 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 601 | si->appctx.st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 602 | |
| 603 | if (!*args[4]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 604 | si->appctx.ctx.cli.msg = "Key value expected\n"; |
| 605 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 606 | return; |
| 607 | } |
| 608 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 609 | switch (px->table.type) { |
| 610 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 611 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 612 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 613 | break; |
| 614 | case STKTABLE_TYPE_IPV6: |
| 615 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 616 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 617 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 618 | case STKTABLE_TYPE_INTEGER: |
| 619 | { |
| 620 | char *endptr; |
| 621 | unsigned long val; |
| 622 | errno = 0; |
| 623 | val = strtoul(args[4], &endptr, 10); |
| 624 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 625 | (errno != 0 && val == 0) || endptr == args[4] || |
| 626 | val > 0xffffffff) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 627 | si->appctx.ctx.cli.msg = "Invalid key\n"; |
| 628 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 629 | return; |
| 630 | } |
| 631 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 632 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 633 | break; |
| 634 | } |
| 635 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 636 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 637 | static_table_key->key = args[4]; |
| 638 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 639 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 640 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 641 | switch (action) { |
| 642 | case STAT_CLI_O_TAB: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 643 | 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] | 644 | break; |
| 645 | case STAT_CLI_O_CLR: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 646 | 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] | 647 | break; |
| 648 | default: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 649 | si->appctx.ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 650 | break; |
| 651 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 652 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 653 | return; |
| 654 | } |
| 655 | |
| 656 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 657 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 658 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 659 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 660 | return; |
| 661 | } |
| 662 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 663 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 664 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 665 | switch (action) { |
| 666 | case STAT_CLI_O_TAB: |
| 667 | if (!ts) |
| 668 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 669 | chunk_reset(&trash); |
| 670 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 671 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 672 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 673 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 674 | |
| 675 | case STAT_CLI_O_CLR: |
| 676 | if (!ts) |
| 677 | return; |
| 678 | if (ts->ref_cnt) { |
| 679 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 680 | si->appctx.ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 681 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 682 | return; |
| 683 | } |
| 684 | stksess_kill(&px->table, ts); |
| 685 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 686 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 687 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 688 | if (ts) |
| 689 | stktable_touch(&px->table, ts, 1); |
| 690 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 691 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 692 | if (!ts) { |
| 693 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 694 | si->appctx.ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 695 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 696 | return; |
| 697 | } |
| 698 | stktable_store(&px->table, ts, 1); |
| 699 | } |
| 700 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 701 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 702 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 703 | si->appctx.ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 704 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 705 | return; |
| 706 | } |
| 707 | |
| 708 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 709 | if (data_type < 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 710 | si->appctx.ctx.cli.msg = "Unknown data type\n"; |
| 711 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | |
| 715 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 716 | si->appctx.ctx.cli.msg = "Data type not stored in this table\n"; |
| 717 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 718 | return; |
| 719 | } |
| 720 | |
| 721 | 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] | 722 | si->appctx.ctx.cli.msg = "Require a valid integer value to store\n"; |
| 723 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | |
| 727 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 728 | |
| 729 | switch (stktable_data_types[data_type].std_type) { |
| 730 | case STD_T_SINT: |
| 731 | stktable_data_cast(ptr, std_t_sint) = value; |
| 732 | break; |
| 733 | case STD_T_UINT: |
| 734 | stktable_data_cast(ptr, std_t_uint) = value; |
| 735 | break; |
| 736 | case STD_T_ULL: |
| 737 | stktable_data_cast(ptr, std_t_ull) = value; |
| 738 | break; |
| 739 | case STD_T_FRQP: |
| 740 | /* We set both the current and previous values. That way |
| 741 | * the reported frequency is stable during all the period |
| 742 | * then slowly fades out. This allows external tools to |
| 743 | * push measures without having to update them too often. |
| 744 | */ |
| 745 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 746 | frqp->curr_tick = now_ms; |
| 747 | frqp->prev_ctr = 0; |
| 748 | frqp->curr_ctr = value; |
| 749 | break; |
| 750 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 751 | } |
| 752 | break; |
| 753 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 754 | default: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 755 | si->appctx.ctx.cli.msg = "Unknown action\n"; |
| 756 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 757 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 758 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 759 | } |
| 760 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 761 | 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] | 762 | { |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 763 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 764 | si->appctx.ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 765 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 766 | return; |
| 767 | } |
| 768 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 769 | /* condition on stored data value */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 770 | si->appctx.ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 771 | if (si->appctx.ctx.table.data_type < 0) { |
| 772 | si->appctx.ctx.cli.msg = "Unknown data type\n"; |
| 773 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 774 | return; |
| 775 | } |
| 776 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 777 | if (!((struct proxy *)si->appctx.ctx.table.target)->table.data_ofs[si->appctx.ctx.table.data_type]) { |
| 778 | si->appctx.ctx.cli.msg = "Data type not stored in this table\n"; |
| 779 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 780 | return; |
| 781 | } |
| 782 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 783 | si->appctx.ctx.table.data_op = get_std_op(args[4]); |
| 784 | if (si->appctx.ctx.table.data_op < 0) { |
| 785 | si->appctx.ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 786 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 787 | return; |
| 788 | } |
| 789 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 790 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &si->appctx.ctx.table.value) != 0) { |
| 791 | si->appctx.ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 792 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 793 | return; |
| 794 | } |
| 795 | } |
| 796 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 797 | 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] | 798 | { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 799 | si->appctx.ctx.table.data_type = -1; |
| 800 | si->appctx.st2 = STAT_ST_INIT; |
| 801 | si->appctx.ctx.table.target = NULL; |
| 802 | si->appctx.ctx.table.proxy = NULL; |
| 803 | si->appctx.ctx.table.entry = NULL; |
| 804 | si->appctx.st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 805 | |
| 806 | if (*args[2]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 807 | si->appctx.ctx.table.target = find_stktable(args[2]); |
| 808 | if (!si->appctx.ctx.table.target) { |
| 809 | si->appctx.ctx.cli.msg = "No such table\n"; |
| 810 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 811 | return; |
| 812 | } |
| 813 | } |
| 814 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 815 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 816 | goto err_args; |
| 817 | return; |
| 818 | } |
| 819 | |
| 820 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 821 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 822 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 823 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 824 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 825 | goto err_args; |
| 826 | |
| 827 | return; |
| 828 | |
| 829 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 830 | switch (action) { |
| 831 | case STAT_CLI_O_TAB: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 832 | 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] | 833 | break; |
| 834 | case STAT_CLI_O_CLR: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 835 | 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] | 836 | break; |
| 837 | default: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 838 | si->appctx.ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 839 | break; |
| 840 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 841 | si->appctx.st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 842 | } |
| 843 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 844 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 845 | * adequate error messages and returns NULL. This function also expects the session |
| 846 | * level to be admin. |
| 847 | */ |
| 848 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 849 | { |
| 850 | struct proxy *px; |
| 851 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 852 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 853 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 854 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 855 | return NULL; |
| 856 | } |
| 857 | |
| 858 | if (!*arg) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 859 | si->appctx.ctx.cli.msg = "A frontend name is expected.\n"; |
| 860 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 861 | return NULL; |
| 862 | } |
| 863 | |
| 864 | px = findproxy(arg, PR_CAP_FE); |
| 865 | if (!px) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 866 | si->appctx.ctx.cli.msg = "No such frontend.\n"; |
| 867 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 868 | return NULL; |
| 869 | } |
| 870 | return px; |
| 871 | } |
| 872 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 873 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 874 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 875 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 876 | * the <arg> is modified to remove the '/'. |
| 877 | */ |
| 878 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 879 | { |
| 880 | struct proxy *px; |
| 881 | struct server *sv; |
| 882 | char *line; |
| 883 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 884 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 885 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 886 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 887 | return NULL; |
| 888 | } |
| 889 | |
| 890 | /* split "backend/server" and make <line> point to server */ |
| 891 | for (line = arg; *line; line++) |
| 892 | if (*line == '/') { |
| 893 | *line++ = '\0'; |
| 894 | break; |
| 895 | } |
| 896 | |
| 897 | if (!*line || !*arg) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 898 | si->appctx.ctx.cli.msg = "Require 'backend/server'.\n"; |
| 899 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 900 | return NULL; |
| 901 | } |
| 902 | |
| 903 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 904 | si->appctx.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 905 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 906 | return NULL; |
| 907 | } |
| 908 | |
| 909 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 910 | si->appctx.ctx.cli.msg = "Proxy is disabled.\n"; |
| 911 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 912 | return NULL; |
| 913 | } |
| 914 | |
| 915 | return sv; |
| 916 | } |
| 917 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 918 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 919 | * 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] | 920 | * 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] | 921 | * designating the function which will have to process the request, which can |
| 922 | * 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] | 923 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 924 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 925 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 926 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 927 | char *args[MAX_STATS_ARGS + 1]; |
| 928 | int arg; |
| 929 | |
| 930 | while (isspace((unsigned char)*line)) |
| 931 | line++; |
| 932 | |
| 933 | arg = 0; |
| 934 | args[arg] = line; |
| 935 | |
| 936 | while (*line && arg < MAX_STATS_ARGS) { |
| 937 | if (isspace((unsigned char)*line)) { |
| 938 | *line++ = '\0'; |
| 939 | |
| 940 | while (isspace((unsigned char)*line)) |
| 941 | line++; |
| 942 | |
| 943 | args[++arg] = line; |
| 944 | continue; |
| 945 | } |
| 946 | |
| 947 | line++; |
| 948 | } |
| 949 | |
| 950 | while (++arg <= MAX_STATS_ARGS) |
| 951 | args[arg] = line; |
| 952 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 953 | si->appctx.ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 954 | if (strcmp(args[0], "show") == 0) { |
| 955 | if (strcmp(args[1], "stat") == 0) { |
| 956 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 957 | si->appctx.ctx.stats.flags |= STAT_BOUND; |
| 958 | si->appctx.ctx.stats.iid = atoi(args[2]); |
| 959 | si->appctx.ctx.stats.type = atoi(args[3]); |
| 960 | si->appctx.ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 961 | } |
| 962 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 963 | si->appctx.st2 = STAT_ST_INIT; |
| 964 | si->appctx.st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 965 | } |
| 966 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 967 | si->appctx.st2 = STAT_ST_INIT; |
| 968 | si->appctx.st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 969 | } |
| 970 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 971 | si->appctx.st2 = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 972 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 973 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 974 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 975 | return 1; |
| 976 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 977 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 978 | si->appctx.ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 979 | else if (*args[2]) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 980 | si->appctx.ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 981 | else |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 982 | si->appctx.ctx.sess.target = NULL; |
| 983 | si->appctx.ctx.sess.section = 0; /* start with session status */ |
| 984 | si->appctx.ctx.sess.pos = 0; |
| 985 | si->appctx.st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 986 | } |
| 987 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 988 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 989 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 990 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 991 | return 1; |
| 992 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 993 | if (*args[2]) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 994 | si->appctx.ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 995 | else |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 996 | si->appctx.ctx.errors.iid = -1; |
| 997 | si->appctx.ctx.errors.px = NULL; |
| 998 | si->appctx.st2 = STAT_ST_INIT; |
| 999 | si->appctx.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1000 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1001 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1002 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1003 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1004 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1005 | return 0; |
| 1006 | } |
| 1007 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1008 | else if (strcmp(args[0], "clear") == 0) { |
| 1009 | if (strcmp(args[1], "counters") == 0) { |
| 1010 | struct proxy *px; |
| 1011 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1012 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1013 | int clrall = 0; |
| 1014 | |
| 1015 | if (strcmp(args[2], "all") == 0) |
| 1016 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1017 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1018 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1019 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1020 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1021 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 1022 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1023 | return 1; |
| 1024 | } |
| 1025 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1026 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1027 | if (clrall) { |
| 1028 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1029 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1030 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1031 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1032 | px->be_counters.conn_max = 0; |
| 1033 | px->be_counters.p.http.rps_max = 0; |
| 1034 | px->be_counters.sps_max = 0; |
| 1035 | px->be_counters.cps_max = 0; |
| 1036 | px->be_counters.nbpend_max = 0; |
| 1037 | |
| 1038 | px->fe_counters.conn_max = 0; |
| 1039 | px->fe_counters.p.http.rps_max = 0; |
| 1040 | px->fe_counters.sps_max = 0; |
| 1041 | px->fe_counters.cps_max = 0; |
| 1042 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1043 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1044 | |
| 1045 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1046 | if (clrall) |
| 1047 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1048 | else { |
| 1049 | sv->counters.cur_sess_max = 0; |
| 1050 | sv->counters.nbpend_max = 0; |
| 1051 | sv->counters.sps_max = 0; |
| 1052 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1053 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1054 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1055 | if (li->counters) { |
| 1056 | if (clrall) |
| 1057 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1058 | else |
| 1059 | li->counters->conn_max = 0; |
| 1060 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1061 | } |
| 1062 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1063 | global.cps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1064 | return 1; |
| 1065 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1066 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1067 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1068 | /* end of processing */ |
| 1069 | return 1; |
| 1070 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1071 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1072 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1073 | return 0; |
| 1074 | } |
| 1075 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1076 | else if (strcmp(args[0], "get") == 0) { |
| 1077 | if (strcmp(args[1], "weight") == 0) { |
| 1078 | struct proxy *px; |
| 1079 | struct server *sv; |
| 1080 | |
| 1081 | /* split "backend/server" and make <line> point to server */ |
| 1082 | for (line = args[2]; *line; line++) |
| 1083 | if (*line == '/') { |
| 1084 | *line++ = '\0'; |
| 1085 | break; |
| 1086 | } |
| 1087 | |
| 1088 | if (!*line) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1089 | si->appctx.ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1090 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1091 | return 1; |
| 1092 | } |
| 1093 | |
| 1094 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1095 | si->appctx.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1096 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1097 | return 1; |
| 1098 | } |
| 1099 | |
| 1100 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1101 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1102 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1103 | return 1; |
| 1104 | } |
| 1105 | else { /* not "get weight" */ |
| 1106 | return 0; |
| 1107 | } |
| 1108 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1109 | else if (strcmp(args[0], "set") == 0) { |
| 1110 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1111 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1112 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1113 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1114 | sv = expect_server_admin(s, si, args[2]); |
| 1115 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1116 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1117 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1118 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1119 | /* |
| 1120 | * The user-weight may now be zero and thus |
| 1121 | * the server considered to be draining. |
| 1122 | * Update the server's drain state as necessary. |
| 1123 | */ |
| 1124 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1125 | if (warning) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1126 | si->appctx.ctx.cli.msg = warning; |
| 1127 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1128 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1129 | return 1; |
| 1130 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1131 | else if (strcmp(args[1], "timeout") == 0) { |
| 1132 | if (strcmp(args[2], "cli") == 0) { |
| 1133 | unsigned timeout; |
| 1134 | const char *res; |
| 1135 | |
| 1136 | if (!*args[3]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1137 | si->appctx.ctx.cli.msg = "Expects an integer value.\n"; |
| 1138 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1139 | return 1; |
| 1140 | } |
| 1141 | |
| 1142 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1143 | if (res || timeout < 1) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1144 | si->appctx.ctx.cli.msg = "Invalid timeout value.\n"; |
| 1145 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1146 | return 1; |
| 1147 | } |
| 1148 | |
| 1149 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1150 | return 1; |
| 1151 | } |
| 1152 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1153 | si->appctx.ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1154 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1155 | return 1; |
| 1156 | } |
| 1157 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1158 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1159 | if (strcmp(args[2], "frontend") == 0) { |
| 1160 | struct proxy *px; |
| 1161 | struct listener *l; |
| 1162 | int v; |
| 1163 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1164 | px = expect_frontend_admin(s, si, args[3]); |
| 1165 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1166 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1167 | |
| 1168 | if (!*args[4]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1169 | si->appctx.ctx.cli.msg = "Integer value expected.\n"; |
| 1170 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1171 | return 1; |
| 1172 | } |
| 1173 | |
| 1174 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1175 | if (v < 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1176 | si->appctx.ctx.cli.msg = "Value out of range.\n"; |
| 1177 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1178 | return 1; |
| 1179 | } |
| 1180 | |
| 1181 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1182 | * its listeners. The blocked ones will be dequeued. |
| 1183 | */ |
| 1184 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1185 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1186 | l->maxconn = v; |
| 1187 | if (l->state == LI_FULL) |
| 1188 | resume_listener(l); |
| 1189 | } |
| 1190 | |
| 1191 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1192 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1193 | |
| 1194 | return 1; |
| 1195 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1196 | else if (strcmp(args[2], "global") == 0) { |
| 1197 | int v; |
| 1198 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1199 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1200 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 1201 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1202 | return 1; |
| 1203 | } |
| 1204 | |
| 1205 | if (!*args[3]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1206 | si->appctx.ctx.cli.msg = "Expects an integer value.\n"; |
| 1207 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1208 | return 1; |
| 1209 | } |
| 1210 | |
| 1211 | v = atoi(args[3]); |
| 1212 | if (v > global.hardmaxconn) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1213 | si->appctx.ctx.cli.msg = "Value out of range.\n"; |
| 1214 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1215 | return 1; |
| 1216 | } |
| 1217 | |
| 1218 | /* check for unlimited values */ |
| 1219 | if (v <= 0) |
| 1220 | v = global.hardmaxconn; |
| 1221 | |
| 1222 | global.maxconn = v; |
| 1223 | |
| 1224 | /* Dequeues all of the listeners waiting for a resource */ |
| 1225 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1226 | dequeue_all_listeners(&global_listener_queue); |
| 1227 | |
| 1228 | return 1; |
| 1229 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1230 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1231 | si->appctx.ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
| 1232 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1233 | return 1; |
| 1234 | } |
| 1235 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1236 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1237 | if (strcmp(args[2], "connections") == 0) { |
| 1238 | if (strcmp(args[3], "global") == 0) { |
| 1239 | int v; |
| 1240 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1241 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1242 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 1243 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1244 | return 1; |
| 1245 | } |
| 1246 | |
| 1247 | if (!*args[4]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1248 | si->appctx.ctx.cli.msg = "Expects an integer value.\n"; |
| 1249 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1250 | return 1; |
| 1251 | } |
| 1252 | |
| 1253 | v = atoi(args[4]); |
| 1254 | if (v < 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1255 | si->appctx.ctx.cli.msg = "Value out of range.\n"; |
| 1256 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1257 | return 1; |
| 1258 | } |
| 1259 | |
| 1260 | global.cps_lim = v; |
| 1261 | |
| 1262 | /* Dequeues all of the listeners waiting for a resource */ |
| 1263 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1264 | dequeue_all_listeners(&global_listener_queue); |
| 1265 | |
| 1266 | return 1; |
| 1267 | } |
| 1268 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1269 | si->appctx.ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1270 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1271 | return 1; |
| 1272 | } |
| 1273 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1274 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1275 | if (strcmp(args[3], "global") == 0) { |
| 1276 | int v; |
| 1277 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1278 | if (!*args[4]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1279 | si->appctx.ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1280 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1281 | return 1; |
| 1282 | } |
| 1283 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1284 | v = atoi(args[4]); |
| 1285 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1286 | } |
| 1287 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1288 | si->appctx.ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1289 | si->appctx.st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1290 | return 1; |
| 1291 | } |
| 1292 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1293 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1294 | si->appctx.ctx.cli.msg = "'set rate-limit' supports 'connections' and 'http-compression'.\n"; |
| 1295 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1296 | return 1; |
| 1297 | } |
| 1298 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1299 | else if (strcmp(args[1], "table") == 0) { |
| 1300 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1301 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1302 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1303 | return 0; |
| 1304 | } |
| 1305 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1306 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1307 | if (strcmp(args[1], "agent") == 0) { |
| 1308 | struct server *sv; |
| 1309 | |
| 1310 | sv = expect_server_admin(s, si, args[2]); |
| 1311 | if (!sv) |
| 1312 | return 1; |
| 1313 | |
| 1314 | sv->agent.state &= ~CHK_STATE_DISABLED; |
| 1315 | |
| 1316 | return 1; |
| 1317 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1318 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1319 | struct server *sv; |
| 1320 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1321 | sv = expect_server_admin(s, si, args[2]); |
| 1322 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1323 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1324 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1325 | if (sv->state & SRV_MAINTAIN) { |
| 1326 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1327 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1328 | /* If this server tracks the status of another one, |
| 1329 | * we must restore the good status. |
| 1330 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1331 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1332 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1333 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1334 | } else { |
| 1335 | sv->state &= ~SRV_MAINTAIN; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1336 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1337 | } |
| 1338 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1339 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1340 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1341 | } |
| 1342 | } |
| 1343 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1344 | return 1; |
| 1345 | } |
| 1346 | else if (strcmp(args[1], "frontend") == 0) { |
| 1347 | struct proxy *px; |
| 1348 | |
| 1349 | px = expect_frontend_admin(s, si, args[2]); |
| 1350 | if (!px) |
| 1351 | return 1; |
| 1352 | |
| 1353 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1354 | si->appctx.ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1355 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1356 | return 1; |
| 1357 | } |
| 1358 | |
| 1359 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1360 | si->appctx.ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1361 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1362 | return 1; |
| 1363 | } |
| 1364 | |
| 1365 | if (!resume_proxy(px)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1366 | si->appctx.ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1367 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1368 | return 1; |
| 1369 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1370 | return 1; |
| 1371 | } |
| 1372 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1373 | si->appctx.ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1374 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1375 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1379 | if (strcmp(args[1], "agent") == 0) { |
| 1380 | struct server *sv; |
| 1381 | |
| 1382 | sv = expect_server_admin(s, si, args[2]); |
| 1383 | if (!sv) |
| 1384 | return 1; |
| 1385 | |
| 1386 | sv->agent.state |= CHK_STATE_DISABLED; |
| 1387 | |
| 1388 | return 1; |
| 1389 | } |
| 1390 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1391 | struct server *sv; |
| 1392 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1393 | sv = expect_server_admin(s, si, args[2]); |
| 1394 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1395 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1396 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1397 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1398 | /* Not already in maintenance, we can change the server state */ |
| 1399 | sv->state |= SRV_MAINTAIN; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1400 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1401 | } |
| 1402 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1403 | return 1; |
| 1404 | } |
| 1405 | else if (strcmp(args[1], "frontend") == 0) { |
| 1406 | struct proxy *px; |
| 1407 | |
| 1408 | px = expect_frontend_admin(s, si, args[2]); |
| 1409 | if (!px) |
| 1410 | return 1; |
| 1411 | |
| 1412 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1413 | si->appctx.ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1414 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1415 | return 1; |
| 1416 | } |
| 1417 | |
| 1418 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1419 | si->appctx.ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1420 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1421 | return 1; |
| 1422 | } |
| 1423 | |
| 1424 | if (!pause_proxy(px)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1425 | si->appctx.ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1426 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1427 | return 1; |
| 1428 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1429 | return 1; |
| 1430 | } |
| 1431 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1432 | si->appctx.ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1433 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1434 | return 1; |
| 1435 | } |
| 1436 | } |
| 1437 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1438 | if (strcmp(args[1], "frontend") == 0) { |
| 1439 | struct proxy *px; |
| 1440 | |
| 1441 | px = expect_frontend_admin(s, si, args[2]); |
| 1442 | if (!px) |
| 1443 | return 1; |
| 1444 | |
| 1445 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1446 | si->appctx.ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1447 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1448 | return 1; |
| 1449 | } |
| 1450 | |
| 1451 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1452 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1453 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1454 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1455 | stop_proxy(px); |
| 1456 | return 1; |
| 1457 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1458 | else if (strcmp(args[1], "session") == 0) { |
| 1459 | struct session *sess, *ptr; |
| 1460 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1461 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1462 | si->appctx.ctx.cli.msg = stats_permission_denied_msg; |
| 1463 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1464 | return 1; |
| 1465 | } |
| 1466 | |
| 1467 | if (!*args[2]) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1468 | si->appctx.ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1469 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1470 | return 1; |
| 1471 | } |
| 1472 | |
| 1473 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1474 | |
| 1475 | /* first, look for the requested session in the session table */ |
| 1476 | list_for_each_entry(sess, &sessions, list) { |
| 1477 | if (sess == ptr) |
| 1478 | break; |
| 1479 | } |
| 1480 | |
| 1481 | /* do we have the session ? */ |
| 1482 | if (sess != ptr) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1483 | si->appctx.ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1484 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1485 | return 1; |
| 1486 | } |
| 1487 | |
| 1488 | session_shutdown(sess, SN_ERR_KILLED); |
| 1489 | return 1; |
| 1490 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1491 | else if (strcmp(args[1], "sessions") == 0) { |
| 1492 | if (strcmp(args[2], "server") == 0) { |
| 1493 | struct server *sv; |
| 1494 | struct session *sess, *sess_bck; |
| 1495 | |
| 1496 | sv = expect_server_admin(s, si, args[3]); |
| 1497 | if (!sv) |
| 1498 | return 1; |
| 1499 | |
| 1500 | /* kill all the session that are on this server */ |
| 1501 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1502 | if (sess->srv_conn == sv) |
| 1503 | session_shutdown(sess, SN_ERR_KILLED); |
| 1504 | |
| 1505 | return 1; |
| 1506 | } |
| 1507 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1508 | si->appctx.ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1509 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1510 | return 1; |
| 1511 | } |
| 1512 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1513 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1514 | si->appctx.ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 1515 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1516 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1520 | return 0; |
| 1521 | } |
| 1522 | return 1; |
| 1523 | } |
| 1524 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1525 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1526 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 1527 | * state machine handling requests and various responses. We read a request, |
| 1528 | * then we process it and send the response, and we possibly display a prompt. |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1529 | * Then we can read again. The state is stored in si->appctx.st0 and is one of the |
| 1530 | * 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] | 1531 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1532 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 1533 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1534 | { |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1535 | struct channel *req = si->ob; |
| 1536 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1537 | int reql; |
| 1538 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1539 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1540 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 1541 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1542 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1543 | while (1) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1544 | if (si->appctx.st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1545 | /* Stats output not initialized yet */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1546 | memset(&si->appctx.ctx.stats, 0, sizeof(si->appctx.ctx.stats)); |
| 1547 | si->appctx.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1548 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1549 | else if (si->appctx.st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1550 | /* Let's close for real now. We just close the request |
| 1551 | * side, the conditions below will complete if needed. |
| 1552 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1553 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1554 | break; |
| 1555 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1556 | else if (si->appctx.st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1557 | /* ensure we have some output room left in the event we |
| 1558 | * would want to return some info right after parsing. |
| 1559 | */ |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1560 | if (buffer_almost_full(si->ib->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1561 | break; |
| 1562 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1563 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1564 | if (reql <= 0) { /* closed or EOL not found */ |
| 1565 | if (reql == 0) |
| 1566 | break; |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1567 | si->appctx.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1568 | continue; |
| 1569 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1570 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1571 | /* seek for a possible semi-colon. If we find one, we |
| 1572 | * replace it with an LF and skip only this part. |
| 1573 | */ |
| 1574 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1575 | if (trash.str[len] == ';') { |
| 1576 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1577 | reql = len + 1; |
| 1578 | break; |
| 1579 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1580 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1581 | /* now it is time to check that we have a full line, |
| 1582 | * remove the trailing \n and possibly \r, then cut the |
| 1583 | * line. |
| 1584 | */ |
| 1585 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1586 | if (trash.str[len] != '\n') { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1587 | si->appctx.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1588 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1589 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1590 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1591 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1592 | len--; |
| 1593 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1594 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1595 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1596 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1597 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1598 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1599 | si->appctx.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1600 | continue; |
| 1601 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1602 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1603 | si->appctx.st1 = !si->appctx.st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1604 | else if (strcmp(trash.str, "help") == 0 || |
| 1605 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1606 | si->appctx.ctx.cli.msg = stats_sock_usage_msg; |
| 1607 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1608 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1609 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1610 | * another STAT_CLI_O_* into si->appctx.st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1611 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1612 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1613 | else if (!si->appctx.st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1614 | /* if prompt is disabled, print help on empty lines, |
| 1615 | * so that the user at least knows how to enable |
| 1616 | * prompt and find help. |
| 1617 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1618 | si->appctx.ctx.cli.msg = stats_sock_usage_msg; |
| 1619 | si->appctx.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1623 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1624 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1625 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1626 | 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] | 1627 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1628 | si->appctx.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1629 | continue; |
| 1630 | } |
| 1631 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1632 | switch (si->appctx.st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1633 | case STAT_CLI_PRINT: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1634 | if (bi_putstr(si->ib, si->appctx.ctx.cli.msg) != -1) |
| 1635 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1636 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1637 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1638 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1639 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1640 | break; |
| 1641 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1642 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1643 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1644 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1645 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1646 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1647 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1648 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1649 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1650 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1651 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1652 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1653 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1654 | case STAT_CLI_O_CLR: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1655 | if (stats_table_request(si, si->appctx.st0)) |
| 1656 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1657 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1658 | default: /* abnormal state */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1659 | si->appctx.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1660 | break; |
| 1661 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1662 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1663 | /* 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] | 1664 | if (si->appctx.st0 == STAT_CLI_PROMPT) { |
| 1665 | if (bi_putstr(si->ib, si->appctx.st1 ? "\n> " : "\n") != -1) |
| 1666 | si->appctx.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1667 | } |
| 1668 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1669 | /* 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] | 1670 | if (si->appctx.st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1671 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1672 | |
| 1673 | /* Now we close the output if one of the writers did so, |
| 1674 | * or if we're not in interactive mode and the request |
| 1675 | * buffer is empty. This still allows pipelined requests |
| 1676 | * to be sent in non-interactive mode. |
| 1677 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1678 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!si->appctx.st1 && !req->buf->o)) { |
| 1679 | si->appctx.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1680 | continue; |
| 1681 | } |
| 1682 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1683 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1684 | si->appctx.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1685 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1686 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1687 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1688 | 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] | 1689 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 1690 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1691 | /* 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] | 1692 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 1693 | * we forward the close to the request side so that it flows upstream to |
| 1694 | * the client. |
| 1695 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1696 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1697 | } |
| 1698 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1699 | 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] | 1700 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 1701 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 1702 | /* We have no more processing to do, and nothing more to send, and |
| 1703 | * the client side has closed. So we'll forward this state downstream |
| 1704 | * on the response buffer. |
| 1705 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1706 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1707 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1711 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1712 | |
| 1713 | /* we don't want to expire timeouts while we're processing requests */ |
| 1714 | si->ib->rex = TICK_ETERNITY; |
| 1715 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1716 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1717 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1718 | 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] | 1719 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1720 | 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] | 1721 | |
| 1722 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 1723 | /* check that we have released everything then unregister */ |
| 1724 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1725 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1726 | } |
| 1727 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1728 | /* This function dumps information onto the stream interface's read buffer. |
| 1729 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 1730 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1731 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1732 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1733 | { |
| 1734 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 1735 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1736 | chunk_printf(&trash, |
| 1737 | "Name: " PRODUCT_NAME "\n" |
| 1738 | "Version: " HAPROXY_VERSION "\n" |
| 1739 | "Release_date: " HAPROXY_DATE "\n" |
| 1740 | "Nbproc: %d\n" |
| 1741 | "Process_num: %d\n" |
| 1742 | "Pid: %d\n" |
| 1743 | "Uptime: %dd %dh%02dm%02ds\n" |
| 1744 | "Uptime_sec: %d\n" |
| 1745 | "Memmax_MB: %d\n" |
| 1746 | "Ulimit-n: %d\n" |
| 1747 | "Maxsock: %d\n" |
| 1748 | "Maxconn: %d\n" |
| 1749 | "Hard_maxconn: %d\n" |
| 1750 | "Maxpipes: %d\n" |
| 1751 | "CurrConns: %d\n" |
| 1752 | "PipesUsed: %d\n" |
| 1753 | "PipesFree: %d\n" |
| 1754 | "ConnRate: %d\n" |
| 1755 | "ConnRateLimit: %d\n" |
| 1756 | "MaxConnRate: %d\n" |
| 1757 | "CompressBpsIn: %u\n" |
| 1758 | "CompressBpsOut: %u\n" |
| 1759 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1760 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1761 | "ZlibMemUsage: %ld\n" |
| 1762 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1763 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1764 | "Tasks: %d\n" |
| 1765 | "Run_queue: %d\n" |
| 1766 | "Idle_pct: %d\n" |
| 1767 | "node: %s\n" |
| 1768 | "description: %s\n" |
| 1769 | "", |
| 1770 | global.nbproc, |
| 1771 | relative_pid, |
| 1772 | pid, |
| 1773 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 1774 | up, |
| 1775 | global.rlimit_memmax, |
| 1776 | global.rlimit_nofile, |
| 1777 | global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes, |
| 1778 | actconn, pipes_used, pipes_free, |
| 1779 | read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max, |
| 1780 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 1781 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1782 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1783 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1784 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1785 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 1786 | global.node, global.desc ? global.desc : "" |
| 1787 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1788 | |
| 1789 | if (bi_putchk(si->ib, &trash) == -1) |
| 1790 | return 0; |
| 1791 | |
| 1792 | return 1; |
| 1793 | } |
| 1794 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1795 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 1796 | * the state from stream interface <si>. The caller is responsible for clearing |
| 1797 | * 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] | 1798 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1799 | 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] | 1800 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1801 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1802 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1803 | if (!(px->cap & PR_CAP_FE)) |
| 1804 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1805 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1806 | 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] | 1807 | return 0; |
| 1808 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1809 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1810 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1811 | /* name, queue */ |
| 1812 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1813 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 1814 | 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] | 1815 | /* Column sub-heading for Enable or Disable server */ |
| 1816 | chunk_appendf(&trash, "<td></td>"); |
| 1817 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1818 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1819 | chunk_appendf(&trash, |
| 1820 | "<td class=ac>" |
| 1821 | "<a name=\"%s/Frontend\"></a>" |
| 1822 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 1823 | "<td colspan=3></td>" |
| 1824 | "", |
| 1825 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1826 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1827 | chunk_appendf(&trash, |
| 1828 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1829 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1830 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 1831 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 1832 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1833 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 1834 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 1835 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1836 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1837 | if (px->mode == PR_MODE_HTTP) |
| 1838 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1839 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1840 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1841 | |
| 1842 | chunk_appendf(&trash, |
| 1843 | "</table></div></u></td>" |
| 1844 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1845 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1846 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 1847 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 1848 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1849 | U2H(px->fe_counters.sps_max), |
| 1850 | U2H(px->fe_counters.cps_max), |
| 1851 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1852 | |
| 1853 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1854 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1855 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1856 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1857 | |
| 1858 | chunk_appendf(&trash, |
| 1859 | "</table></div></u></td>" |
| 1860 | /* sessions rate : limit */ |
| 1861 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1862 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1863 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1864 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1865 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1866 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1867 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1868 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 1869 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1870 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1871 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 1872 | U2H(px->fe_counters.cum_sess), |
| 1873 | U2H(px->fe_counters.cum_conn), |
| 1874 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1875 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1876 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1877 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1878 | chunk_appendf(&trash, |
| 1879 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 1880 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 1881 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 1882 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1883 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 1884 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 1885 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 1886 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 1887 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 1888 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1889 | U2H(px->fe_counters.p.http.cum_req), |
| 1890 | U2H(px->fe_counters.p.http.rsp[1]), |
| 1891 | U2H(px->fe_counters.p.http.rsp[2]), |
| 1892 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1893 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1894 | (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] | 1895 | U2H(px->fe_counters.p.http.rsp[3]), |
| 1896 | U2H(px->fe_counters.p.http.rsp[4]), |
| 1897 | U2H(px->fe_counters.p.http.rsp[5]), |
| 1898 | U2H(px->fe_counters.p.http.rsp[0]), |
| 1899 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1900 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1901 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1902 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1903 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1904 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1905 | "<td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1906 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1907 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1908 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1909 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1910 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1911 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1912 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1913 | "<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] | 1914 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1915 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1916 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 1917 | px->fe_counters.comp_in ? |
| 1918 | (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] | 1919 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1920 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1921 | chunk_appendf(&trash, |
| 1922 | /* denied: req, resp */ |
| 1923 | "<td>%s</td><td>%s</td>" |
| 1924 | /* errors : request, connect, response */ |
| 1925 | "<td>%s</td><td></td><td></td>" |
| 1926 | /* warnings: retries, redispatches */ |
| 1927 | "<td></td><td></td>" |
| 1928 | /* server status : reflect frontend status */ |
| 1929 | "<td class=ac>%s</td>" |
| 1930 | /* rest of server: nothing */ |
| 1931 | "<td class=ac colspan=8></td></tr>" |
| 1932 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1933 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 1934 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1935 | px->state == PR_STREADY ? "OPEN" : |
| 1936 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1937 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1938 | else { /* CSV mode */ |
| 1939 | chunk_appendf(&trash, |
| 1940 | /* pxid, name, queue cur, queue max, */ |
| 1941 | "%s,FRONTEND,,," |
| 1942 | /* sessions : current, max, limit, total */ |
| 1943 | "%d,%d,%d,%lld," |
| 1944 | /* bytes : in, out */ |
| 1945 | "%lld,%lld," |
| 1946 | /* denied: req, resp */ |
| 1947 | "%lld,%lld," |
| 1948 | /* errors : request, connect, response */ |
| 1949 | "%lld,,," |
| 1950 | /* warnings: retries, redispatches */ |
| 1951 | ",," |
| 1952 | /* server status : reflect frontend status */ |
| 1953 | "%s," |
| 1954 | /* rest of server: nothing */ |
| 1955 | ",,,,,,,," |
| 1956 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 1957 | "%d,%d,0,,,,%d," |
| 1958 | /* rate, rate_lim, rate_max */ |
| 1959 | "%u,%u,%u," |
| 1960 | /* check_status, check_code, check_duration */ |
| 1961 | ",,,", |
| 1962 | px->id, |
| 1963 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 1964 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 1965 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 1966 | px->fe_counters.failed_req, |
| 1967 | px->state == PR_STREADY ? "OPEN" : |
| 1968 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 1969 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 1970 | read_freq_ctr(&px->fe_sess_per_sec), |
| 1971 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1972 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1973 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1974 | if (px->mode == PR_MODE_HTTP) { |
| 1975 | for (i=1; i<6; i++) |
| 1976 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 1977 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 1978 | } |
| 1979 | else |
| 1980 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1981 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1982 | /* failed health analyses */ |
| 1983 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1984 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1985 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 1986 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 1987 | read_freq_ctr(&px->fe_req_per_sec), |
| 1988 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 1989 | |
| 1990 | /* errors: cli_aborts, srv_aborts */ |
| 1991 | chunk_appendf(&trash, ",,"); |
| 1992 | |
| 1993 | /* compression: in, out, bypassed */ |
| 1994 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 1995 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 1996 | |
| 1997 | /* compression: comp_rsp */ |
| 1998 | chunk_appendf(&trash, "%lld,", |
| 1999 | px->fe_counters.p.http.comp_rsp); |
| 2000 | |
| 2001 | /* finish with EOL */ |
| 2002 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2003 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2004 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2005 | } |
| 2006 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2007 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2008 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2009 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2010 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2011 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2012 | 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] | 2013 | { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2014 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2015 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2016 | 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] | 2017 | /* Column sub-heading for Enable or Disable server */ |
| 2018 | chunk_appendf(&trash, "<td></td>"); |
| 2019 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2020 | chunk_appendf(&trash, |
| 2021 | /* frontend name, listener name */ |
| 2022 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2023 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2024 | "", |
| 2025 | px->id, l->name, |
| 2026 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2027 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2028 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2029 | if (flags & ST_SHLGNDS) { |
| 2030 | char str[INET6_ADDRSTRLEN]; |
| 2031 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2032 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2033 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2034 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2035 | port = get_host_port(&l->addr); |
| 2036 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2037 | case AF_INET: |
| 2038 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2039 | break; |
| 2040 | case AF_INET6: |
| 2041 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2042 | break; |
| 2043 | case AF_UNIX: |
| 2044 | chunk_appendf(&trash, "unix, "); |
| 2045 | break; |
| 2046 | case -1: |
| 2047 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2048 | break; |
| 2049 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2050 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2051 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2052 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2053 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2054 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2055 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2056 | /* queue */ |
| 2057 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2058 | /* sessions rate: current, max, limit */ |
| 2059 | "<td colspan=3> </td>" |
| 2060 | /* sessions: current, max, limit, total, lbtot */ |
| 2061 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2062 | "<td>%s</td><td> </td>" |
| 2063 | /* bytes: in, out */ |
| 2064 | "<td>%s</td><td>%s</td>" |
| 2065 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2066 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2067 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2068 | 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] | 2069 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2070 | chunk_appendf(&trash, |
| 2071 | /* denied: req, resp */ |
| 2072 | "<td>%s</td><td>%s</td>" |
| 2073 | /* errors: request, connect, response */ |
| 2074 | "<td>%s</td><td></td><td></td>" |
| 2075 | /* warnings: retries, redispatches */ |
| 2076 | "<td></td><td></td>" |
| 2077 | /* server status: reflect listener status */ |
| 2078 | "<td class=ac>%s</td>" |
| 2079 | /* rest of server: nothing */ |
| 2080 | "<td class=ac colspan=8></td></tr>" |
| 2081 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2082 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2083 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2084 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2085 | } |
| 2086 | else { /* CSV mode */ |
| 2087 | chunk_appendf(&trash, |
| 2088 | /* pxid, name, queue cur, queue max, */ |
| 2089 | "%s,%s,,," |
| 2090 | /* sessions: current, max, limit, total */ |
| 2091 | "%d,%d,%d,%lld," |
| 2092 | /* bytes: in, out */ |
| 2093 | "%lld,%lld," |
| 2094 | /* denied: req, resp */ |
| 2095 | "%lld,%lld," |
| 2096 | /* errors: request, connect, response */ |
| 2097 | "%lld,,," |
| 2098 | /* warnings: retries, redispatches */ |
| 2099 | ",," |
| 2100 | /* server status: reflect listener status */ |
| 2101 | "%s," |
| 2102 | /* rest of server: nothing */ |
| 2103 | ",,,,,,,," |
| 2104 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2105 | "%d,%d,%d,,,,%d," |
| 2106 | /* rate, rate_lim, rate_max */ |
| 2107 | ",,," |
| 2108 | /* check_status, check_code, check_duration */ |
| 2109 | ",,," |
| 2110 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2111 | ",,,,,," |
| 2112 | /* failed health analyses */ |
| 2113 | "," |
| 2114 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2115 | ",,," |
| 2116 | /* errors: cli_aborts, srv_aborts */ |
| 2117 | ",," |
| 2118 | /* compression: in, out, bypassed, comp_rsp */ |
| 2119 | ",,,," |
| 2120 | "\n", |
| 2121 | px->id, l->name, |
| 2122 | l->nbconn, l->counters->conn_max, |
| 2123 | l->maxconn, l->counters->cum_conn, |
| 2124 | l->counters->bytes_in, l->counters->bytes_out, |
| 2125 | l->counters->denied_req, l->counters->denied_resp, |
| 2126 | l->counters->failed_req, |
| 2127 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2128 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2129 | } |
| 2130 | return 1; |
| 2131 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2132 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2133 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2134 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2135 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2136 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2137 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2138 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2139 | */ |
| 2140 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2141 | { |
| 2142 | struct server *ref = sv->track ? sv->track : sv; |
| 2143 | char str[INET6_ADDRSTRLEN]; |
| 2144 | struct chunk src; |
| 2145 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2146 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2147 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2148 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2149 | "DOWN", |
| 2150 | "DN %d/%d ↑", |
| 2151 | "UP %d/%d ↓", |
| 2152 | "UP", |
| 2153 | "NOLB %d/%d ↓", |
| 2154 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2155 | "DRAIN %d/%d ↓", |
| 2156 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2157 | "<i>no check</i>" |
| 2158 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2159 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2160 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2161 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2162 | else |
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 | "<tr class=\"%s%d\">", |
| 2165 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2166 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2167 | 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] | 2168 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2169 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2170 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2171 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2172 | chunk_appendf(&trash, |
| 2173 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2174 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2175 | "", |
| 2176 | px->id, sv->id, |
| 2177 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2178 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2179 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2180 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2181 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2182 | |
| 2183 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2184 | case AF_INET: |
| 2185 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2186 | break; |
| 2187 | case AF_INET6: |
| 2188 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2189 | break; |
| 2190 | case AF_UNIX: |
| 2191 | chunk_appendf(&trash, "unix, "); |
| 2192 | break; |
| 2193 | case -1: |
| 2194 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2195 | break; |
| 2196 | default: /* address family not supported */ |
| 2197 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2198 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2199 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2200 | /* id */ |
| 2201 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2202 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2203 | /* cookie */ |
| 2204 | if (sv->cookie) { |
| 2205 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2206 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2207 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2208 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2209 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2210 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2211 | } |
| 2212 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2213 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2214 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2215 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2216 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2217 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2218 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2219 | /* sessions rate : current, max, limit */ |
| 2220 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2221 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2222 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2223 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2224 | 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] | 2225 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2226 | |
| 2227 | chunk_appendf(&trash, |
| 2228 | /* sessions: current, max, limit, total */ |
| 2229 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2230 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2231 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2232 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2233 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2234 | U2H(sv->counters.cum_sess), |
| 2235 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2236 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2237 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2238 | if (px->mode == PR_MODE_HTTP) { |
| 2239 | unsigned long long tot; |
| 2240 | for (tot = i = 0; i < 6; i++) |
| 2241 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2242 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2243 | chunk_appendf(&trash, |
| 2244 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2245 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2246 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2247 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2248 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2249 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2250 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2251 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2252 | U2H(tot), |
| 2253 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2254 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2255 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2256 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2257 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2258 | 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] | 2259 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2260 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2261 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2262 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2263 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2264 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2265 | U2H(sv->counters.cum_lbconn)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2266 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2267 | chunk_appendf(&trash, |
| 2268 | /* bytes : in, out */ |
| 2269 | "<td>%s</td><td>%s</td>" |
| 2270 | /* denied: req, resp */ |
| 2271 | "<td></td><td>%s</td>" |
| 2272 | /* errors : request, connect */ |
| 2273 | "<td></td><td>%s</td>" |
| 2274 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2275 | "<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] | 2276 | /* warnings: retries, redispatches */ |
| 2277 | "<td>%lld</td><td>%lld</td>" |
| 2278 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2279 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2280 | U2H(sv->counters.failed_secu), |
| 2281 | U2H(sv->counters.failed_conns), |
| 2282 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2283 | sv->counters.cli_aborts, |
| 2284 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2285 | sv->counters.retries, sv->counters.redispatches); |
| 2286 | |
| 2287 | /* status, lest check */ |
| 2288 | chunk_appendf(&trash, "<td class=ac>"); |
| 2289 | |
| 2290 | if (sv->state & SRV_MAINTAIN) { |
| 2291 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2292 | chunk_appendf(&trash, "MAINT"); |
| 2293 | } |
| 2294 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2295 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2296 | chunk_appendf(&trash, "MAINT(via)"); |
| 2297 | } |
| 2298 | else if (ref->state & SRV_CHECKED) { |
| 2299 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2300 | chunk_appendf(&trash, |
| 2301 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2302 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2303 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2304 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2305 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2306 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2307 | chunk_appendf(&trash, |
| 2308 | "</td><td class=ac><u> %s%s", |
Simon Horman | cd5d7b6 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 2309 | (sv->check.state & CHK_STATE_RUNNING) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2310 | get_check_status_info(sv->check.status)); |
| 2311 | |
| 2312 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2313 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2314 | |
| 2315 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2316 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2317 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2318 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2319 | get_check_status_description(sv->check.status)); |
| 2320 | if (*sv->check.desc) { |
| 2321 | chunk_appendf(&trash, ": "); |
| 2322 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2323 | chunk_htmlencode(&trash, &src); |
| 2324 | } |
| 2325 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2326 | } |
| 2327 | else |
| 2328 | chunk_appendf(&trash, "</td><td>"); |
| 2329 | |
| 2330 | chunk_appendf(&trash, |
| 2331 | /* weight */ |
| 2332 | "</td><td class=ac>%d</td>" |
| 2333 | /* act, bck */ |
| 2334 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2335 | "", |
| 2336 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2337 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2338 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2339 | |
| 2340 | /* check failures: unique, fatal, down time */ |
| 2341 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2342 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2343 | |
| 2344 | if (ref->observe) |
| 2345 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2346 | |
| 2347 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2348 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2349 | "<td>%lld</td><td>%s</td>" |
| 2350 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2351 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2352 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2353 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2354 | else if (sv != ref) { |
| 2355 | if (sv->state & SRV_MAINTAIN) |
| 2356 | chunk_appendf(&trash, |
| 2357 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2358 | ref->proxy->id, ref->id); |
| 2359 | else |
| 2360 | chunk_appendf(&trash, |
| 2361 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2362 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2363 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2364 | else |
| 2365 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2366 | |
| 2367 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2368 | if (sv->state & SRV_WARMINGUP) |
| 2369 | 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] | 2370 | else |
| 2371 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2372 | } |
| 2373 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2374 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2375 | "DOWN,", |
| 2376 | "DOWN %d/%d,", |
| 2377 | "UP %d/%d,", |
| 2378 | "UP,", |
| 2379 | "NOLB %d/%d,", |
| 2380 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2381 | "DRAIN %d/%d,", |
| 2382 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2383 | "no check," |
| 2384 | }; |
| 2385 | |
| 2386 | chunk_appendf(&trash, |
| 2387 | /* pxid, name */ |
| 2388 | "%s,%s," |
| 2389 | /* queue : current, max */ |
| 2390 | "%d,%d," |
| 2391 | /* sessions : current, max, limit, total */ |
| 2392 | "%d,%d,%s,%lld," |
| 2393 | /* bytes : in, out */ |
| 2394 | "%lld,%lld," |
| 2395 | /* denied: req, resp */ |
| 2396 | ",%lld," |
| 2397 | /* errors : request, connect, response */ |
| 2398 | ",%lld,%lld," |
| 2399 | /* warnings: retries, redispatches */ |
| 2400 | "%lld,%lld," |
| 2401 | "", |
| 2402 | px->id, sv->id, |
| 2403 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2404 | 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] | 2405 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2406 | sv->counters.failed_secu, |
| 2407 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2408 | sv->counters.retries, sv->counters.redispatches); |
| 2409 | |
| 2410 | /* status */ |
| 2411 | if (sv->state & SRV_MAINTAIN) |
| 2412 | chunk_appendf(&trash, "MAINT,"); |
| 2413 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2414 | chunk_appendf(&trash, "MAINT(via),"); |
| 2415 | else |
| 2416 | chunk_appendf(&trash, |
| 2417 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2418 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2419 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2420 | |
| 2421 | chunk_appendf(&trash, |
| 2422 | /* weight, active, backup */ |
| 2423 | "%d,%d,%d," |
| 2424 | "", |
| 2425 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2426 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2427 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2428 | |
| 2429 | /* check failures: unique, fatal; last change, total downtime */ |
| 2430 | if (sv->state & SRV_CHECKED) |
| 2431 | chunk_appendf(&trash, |
| 2432 | "%lld,%lld,%d,%d,", |
| 2433 | sv->counters.failed_checks, sv->counters.down_trans, |
| 2434 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 2435 | else |
| 2436 | chunk_appendf(&trash, ",,,,"); |
| 2437 | |
| 2438 | /* queue limit, pid, iid, sid, */ |
| 2439 | chunk_appendf(&trash, |
| 2440 | "%s," |
| 2441 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2442 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2443 | relative_pid, px->uuid, sv->puid); |
| 2444 | |
| 2445 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2446 | if (sv->state & SRV_WARMINGUP) |
| 2447 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2448 | |
| 2449 | /* sessions: lbtot */ |
| 2450 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 2451 | |
| 2452 | /* tracked */ |
| 2453 | if (sv->track) |
| 2454 | chunk_appendf(&trash, "%s/%s,", |
| 2455 | sv->track->proxy->id, sv->track->id); |
| 2456 | else |
| 2457 | chunk_appendf(&trash, ","); |
| 2458 | |
| 2459 | /* type */ |
| 2460 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 2461 | |
| 2462 | /* rate */ |
| 2463 | chunk_appendf(&trash, "%u,,%u,", |
| 2464 | read_freq_ctr(&sv->sess_per_sec), |
| 2465 | sv->counters.sps_max); |
| 2466 | |
| 2467 | if (sv->state & SRV_CHECKED) { |
| 2468 | /* check_status */ |
| 2469 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 2470 | |
| 2471 | /* check_code */ |
| 2472 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2473 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 2474 | else |
| 2475 | chunk_appendf(&trash, ","); |
| 2476 | |
| 2477 | /* check_duration */ |
| 2478 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 2479 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 2480 | else |
| 2481 | chunk_appendf(&trash, ","); |
| 2482 | |
| 2483 | } |
| 2484 | else |
| 2485 | chunk_appendf(&trash, ",,,"); |
| 2486 | |
| 2487 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2488 | if (px->mode == PR_MODE_HTTP) { |
| 2489 | for (i=1; i<6; i++) |
| 2490 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 2491 | |
| 2492 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 2493 | } |
| 2494 | else |
| 2495 | chunk_appendf(&trash, ",,,,,,"); |
| 2496 | |
| 2497 | /* failed health analyses */ |
| 2498 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 2499 | |
| 2500 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2501 | chunk_appendf(&trash, ",,,"); |
| 2502 | |
| 2503 | /* errors: cli_aborts, srv_aborts */ |
| 2504 | chunk_appendf(&trash, "%lld,%lld,", |
| 2505 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 2506 | |
| 2507 | /* compression: in, out, bypassed, comp_rsp */ |
| 2508 | chunk_appendf(&trash, ",,,,"); |
| 2509 | |
| 2510 | /* finish with EOL */ |
| 2511 | chunk_appendf(&trash, "\n"); |
| 2512 | } |
| 2513 | return 1; |
| 2514 | } |
| 2515 | |
| 2516 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 2517 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 2518 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 2519 | */ |
| 2520 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 2521 | { |
| 2522 | struct chunk src; |
| 2523 | int i; |
| 2524 | |
| 2525 | if (!(px->cap & PR_CAP_BE)) |
| 2526 | return 0; |
| 2527 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2528 | 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] | 2529 | return 0; |
| 2530 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2531 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2532 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2533 | if (px->srv && (si->appctx.ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2534 | /* Column sub-heading for Enable or Disable server */ |
| 2535 | chunk_appendf(&trash, "<td></td>"); |
| 2536 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2537 | chunk_appendf(&trash, |
| 2538 | "<td class=ac>" |
| 2539 | /* name */ |
| 2540 | "%s<a name=\"%s/Backend\"></a>" |
| 2541 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 2542 | "", |
| 2543 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2544 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2545 | |
| 2546 | if (flags & ST_SHLGNDS) { |
| 2547 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2548 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2549 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 2550 | |
| 2551 | /* cookie */ |
| 2552 | if (px->cookie_name) { |
| 2553 | chunk_appendf(&trash, ", cookie: '"); |
| 2554 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 2555 | chunk_htmlencode(&trash, &src); |
| 2556 | chunk_appendf(&trash, "'"); |
| 2557 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2558 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2562 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2563 | /* queue : current, max */ |
| 2564 | "<td>%s</td><td>%s</td><td></td>" |
| 2565 | /* sessions rate : current, max, limit */ |
| 2566 | "<td>%s</td><td>%s</td><td></td>" |
| 2567 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2568 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2569 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 2570 | 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] | 2571 | |
| 2572 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2573 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2574 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2575 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2576 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2577 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2578 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 2579 | U2H(px->be_counters.cum_conn), |
| 2580 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2581 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2582 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2583 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2584 | chunk_appendf(&trash, |
| 2585 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2586 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2587 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2588 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2589 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2590 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2591 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2592 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2593 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2594 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2595 | U2H(px->be_counters.p.http.cum_req), |
| 2596 | U2H(px->be_counters.p.http.rsp[1]), |
| 2597 | U2H(px->be_counters.p.http.rsp[2]), |
| 2598 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2599 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2600 | (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] | 2601 | U2H(px->be_counters.p.http.rsp[3]), |
| 2602 | U2H(px->be_counters.p.http.rsp[4]), |
| 2603 | U2H(px->be_counters.p.http.rsp[5]), |
| 2604 | U2H(px->be_counters.p.http.rsp[0]), |
| 2605 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2609 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2610 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2611 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2612 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2613 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2614 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2615 | U2H(px->be_counters.cum_lbconn), |
| 2616 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2617 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2618 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2619 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2620 | "<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] | 2621 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2622 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2623 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 2624 | px->be_counters.comp_in ? |
| 2625 | (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] | 2626 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 2627 | |
| 2628 | chunk_appendf(&trash, |
| 2629 | /* denied: req, resp */ |
| 2630 | "<td>%s</td><td>%s</td>" |
| 2631 | /* errors : request, connect */ |
| 2632 | "<td></td><td>%s</td>" |
| 2633 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2634 | "<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] | 2635 | /* warnings: retries, redispatches */ |
| 2636 | "<td>%lld</td><td>%lld</td>" |
| 2637 | /* backend status: reflect backend status (up/down): we display UP |
| 2638 | * if the backend has known working servers or if it has no server at |
| 2639 | * all (eg: for stats). Then we display the total weight, number of |
| 2640 | * active and backups. */ |
| 2641 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 2642 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 2643 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2644 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 2645 | U2H(px->be_counters.failed_conns), |
| 2646 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2647 | px->be_counters.cli_aborts, |
| 2648 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2649 | px->be_counters.retries, px->be_counters.redispatches, |
| 2650 | human_time(now.tv_sec - px->last_change, 1), |
| 2651 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 2652 | "<font color=\"red\"><b>DOWN</b></font>", |
| 2653 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2654 | px->srv_act, px->srv_bck); |
| 2655 | |
| 2656 | chunk_appendf(&trash, |
| 2657 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 2658 | "<td class=ac> </td><td>%d</td>" |
| 2659 | "<td>%s</td>" |
| 2660 | "<td></td>" |
| 2661 | "</tr>", |
| 2662 | px->down_trans, |
| 2663 | px->srv?human_time(be_downtime(px), 1):" "); |
| 2664 | } |
| 2665 | else { /* CSV mode */ |
| 2666 | chunk_appendf(&trash, |
| 2667 | /* pxid, name */ |
| 2668 | "%s,BACKEND," |
| 2669 | /* queue : current, max */ |
| 2670 | "%d,%d," |
| 2671 | /* sessions : current, max, limit, total */ |
| 2672 | "%d,%d,%d,%lld," |
| 2673 | /* bytes : in, out */ |
| 2674 | "%lld,%lld," |
| 2675 | /* denied: req, resp */ |
| 2676 | "%lld,%lld," |
| 2677 | /* errors : request, connect, response */ |
| 2678 | ",%lld,%lld," |
| 2679 | /* warnings: retries, redispatches */ |
| 2680 | "%lld,%lld," |
| 2681 | /* backend status: reflect backend status (up/down): we display UP |
| 2682 | * if the backend has known working servers or if it has no server at |
| 2683 | * all (eg: for stats). Then we display the total weight, number of |
| 2684 | * active and backups. */ |
| 2685 | "%s," |
| 2686 | "%d,%d,%d," |
| 2687 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 2688 | ",%d,%d,%d,," |
| 2689 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2690 | "%d,%d,0,,%lld,,%d," |
| 2691 | /* rate, rate_lim, rate_max, */ |
| 2692 | "%u,,%u," |
| 2693 | /* check_status, check_code, check_duration */ |
| 2694 | ",,,", |
| 2695 | px->id, |
| 2696 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 2697 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 2698 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 2699 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 2700 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 2701 | px->be_counters.retries, px->be_counters.redispatches, |
| 2702 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 2703 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2704 | px->srv_act, px->srv_bck, |
| 2705 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 2706 | px->srv?be_downtime(px):0, |
| 2707 | relative_pid, px->uuid, |
| 2708 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 2709 | read_freq_ctr(&px->be_sess_per_sec), |
| 2710 | px->be_counters.sps_max); |
| 2711 | |
| 2712 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2713 | if (px->mode == PR_MODE_HTTP) { |
| 2714 | for (i=1; i<6; i++) |
| 2715 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 2716 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 2717 | } |
| 2718 | else |
| 2719 | chunk_appendf(&trash, ",,,,,,"); |
| 2720 | |
| 2721 | /* failed health analyses */ |
| 2722 | chunk_appendf(&trash, ","); |
| 2723 | |
| 2724 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2725 | chunk_appendf(&trash, ",,,"); |
| 2726 | |
| 2727 | /* errors: cli_aborts, srv_aborts */ |
| 2728 | chunk_appendf(&trash, "%lld,%lld,", |
| 2729 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 2730 | |
| 2731 | /* compression: in, out, bypassed */ |
| 2732 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2733 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 2734 | |
| 2735 | /* compression: comp_rsp */ |
| 2736 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 2737 | |
| 2738 | /* finish with EOL */ |
| 2739 | chunk_appendf(&trash, "\n"); |
| 2740 | } |
| 2741 | return 1; |
| 2742 | } |
| 2743 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2744 | /* 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] | 2745 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2746 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2747 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2748 | 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] | 2749 | { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2750 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 2751 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2752 | 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] | 2753 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2754 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2755 | /* 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] | 2756 | scope_txt[0] = 0; |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2757 | if (si->appctx.ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2758 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2759 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + si->appctx.ctx.stats.scope_str, si->appctx.ctx.stats.scope_len); |
| 2760 | 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] | 2761 | } |
| 2762 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2763 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2764 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 2765 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2766 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2767 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2768 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | /* print a new table */ |
| 2772 | chunk_appendf(&trash, |
| 2773 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2774 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2775 | "<th class=\"pxname\" width=\"10%%\">"); |
| 2776 | |
| 2777 | chunk_appendf(&trash, |
| 2778 | "<a name=\"%s\"></a>%s" |
| 2779 | "<a class=px href=\"#%s\">%s</a>", |
| 2780 | px->id, |
| 2781 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 2782 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2783 | |
| 2784 | if (uri->flags & ST_SHLGNDS) { |
| 2785 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2786 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2787 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 2788 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2789 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2793 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2794 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 2795 | "</tr>\n" |
| 2796 | "</table>\n" |
| 2797 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2798 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2799 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 2800 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 2801 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2802 | 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] | 2803 | /* Column heading for Enable or Disable server */ |
| 2804 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2805 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2806 | |
| 2807 | chunk_appendf(&trash, |
| 2808 | "<th rowspan=2></th>" |
| 2809 | "<th colspan=3>Queue</th>" |
| 2810 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
| 2811 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 2812 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 2813 | "<th colspan=9>Server</th>" |
| 2814 | "</tr>\n" |
| 2815 | "<tr class=\"titre\">" |
| 2816 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 2817 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 2818 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>" |
| 2819 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 2820 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 2821 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 2822 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 2823 | "<th>Thrtle</th>\n" |
| 2824 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2825 | } |
| 2826 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2827 | /* 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] | 2828 | * 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] | 2829 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2830 | 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] | 2831 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2832 | chunk_appendf(&trash, "</table>"); |
| 2833 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2834 | 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] | 2835 | /* close the form used to enable/disable this proxy servers */ |
| 2836 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2837 | "Choose the action to perform on the checked servers : " |
| 2838 | "<select name=action>" |
| 2839 | "<option value=\"\"></option>" |
| 2840 | "<option value=\"disable\">Disable</option>" |
| 2841 | "<option value=\"enable\">Enable</option>" |
| 2842 | "<option value=\"stop\">Soft Stop</option>" |
| 2843 | "<option value=\"start\">Soft Start</option>" |
| 2844 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 2845 | "</select>" |
| 2846 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 2847 | " <input type=\"submit\" value=\"Apply\">" |
| 2848 | "</form>", |
| 2849 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2853 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2854 | |
| 2855 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2856 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 2857 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 2858 | * buffer space, or non-zero if everything completed. This function is used |
| 2859 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 2860 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2861 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2862 | 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] | 2863 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 2864 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2865 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2866 | 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] | 2867 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2868 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2869 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2870 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2871 | switch (si->appctx.ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2872 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2873 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2874 | if (uri && uri->scope) { |
| 2875 | /* we have a limited scope, we have to check the proxy name */ |
| 2876 | struct stat_scope *scope; |
| 2877 | int len; |
| 2878 | |
| 2879 | len = strlen(px->id); |
| 2880 | scope = uri->scope; |
| 2881 | |
| 2882 | while (scope) { |
| 2883 | /* match exact proxy name */ |
| 2884 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 2885 | break; |
| 2886 | |
| 2887 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 2888 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2889 | break; |
| 2890 | scope = scope->next; |
| 2891 | } |
| 2892 | |
| 2893 | /* proxy name not found : don't dump anything */ |
| 2894 | if (scope == NULL) |
| 2895 | return 1; |
| 2896 | } |
| 2897 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2898 | /* if the user has requested a limited output and the proxy |
| 2899 | * name does not match, skip it. |
| 2900 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2901 | if (si->appctx.ctx.stats.scope_len && |
| 2902 | 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] | 2903 | return 1; |
| 2904 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2905 | if ((si->appctx.ctx.stats.flags & STAT_BOUND) && |
| 2906 | (si->appctx.ctx.stats.iid != -1) && |
| 2907 | (px->uuid != si->appctx.ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2908 | return 1; |
| 2909 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2910 | si->appctx.ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2911 | /* fall through */ |
| 2912 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2913 | case STAT_PX_ST_TH: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2914 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2915 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2916 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2917 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2918 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2919 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2920 | si->appctx.ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2921 | /* fall through */ |
| 2922 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2923 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2924 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2925 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2926 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2927 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2928 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2929 | si->appctx.ctx.stats.l = px->conf.listeners.n; |
| 2930 | si->appctx.ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2931 | /* fall through */ |
| 2932 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2933 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2934 | /* stats.l has been initialized above */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2935 | 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] | 2936 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2937 | return 0; |
| 2938 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2939 | 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] | 2940 | if (!l->counters) |
| 2941 | continue; |
| 2942 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2943 | if (si->appctx.ctx.stats.flags & STAT_BOUND) { |
| 2944 | if (!(si->appctx.ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2945 | break; |
| 2946 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2947 | 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] | 2948 | continue; |
| 2949 | } |
| 2950 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2951 | /* print the frontend */ |
| 2952 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 2953 | if (bi_putchk(rep, &trash) == -1) |
| 2954 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2955 | } |
| 2956 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2957 | si->appctx.ctx.stats.sv = px->srv; /* may be NULL */ |
| 2958 | si->appctx.ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2959 | /* fall through */ |
| 2960 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2961 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2962 | /* stats.sv has been initialized above */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2963 | 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] | 2964 | 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] | 2965 | |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2966 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2967 | return 0; |
| 2968 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2969 | sv = si->appctx.ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2970 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2971 | if (si->appctx.ctx.stats.flags & STAT_BOUND) { |
| 2972 | if (!(si->appctx.ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2973 | break; |
| 2974 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 2975 | 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] | 2976 | continue; |
| 2977 | } |
| 2978 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2979 | if (sv->track) |
| 2980 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2981 | else |
| 2982 | svs = sv; |
| 2983 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2984 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2985 | if (!(svs->state & SRV_CHECKED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2986 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2987 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2988 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2989 | sv_state = 3; /* UP */ |
| 2990 | else |
| 2991 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2992 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 2993 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2994 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 2995 | else if (svs->state & SRV_GOINGDOWN) |
| 2996 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2997 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2998 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 2999 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3000 | sv_state = 1; /* going up */ |
| 3001 | else |
| 3002 | sv_state = 0; /* DOWN */ |
| 3003 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3004 | 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] | 3005 | /* do not report servers which are DOWN */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3006 | si->appctx.ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3007 | continue; |
| 3008 | } |
| 3009 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3010 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3011 | if (bi_putchk(rep, &trash) == -1) |
| 3012 | return 0; |
| 3013 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3014 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3015 | si->appctx.ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3016 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3017 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3018 | case STAT_PX_ST_BE: |
| 3019 | /* print the backend */ |
| 3020 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3021 | if (bi_putchk(rep, &trash) == -1) |
| 3022 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3023 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3024 | si->appctx.ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3025 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3026 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3027 | case STAT_PX_ST_END: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3028 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3029 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3030 | if (bi_putchk(rep, &trash) == -1) |
| 3031 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3032 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3033 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3034 | si->appctx.ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3035 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3036 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3037 | case STAT_PX_ST_FIN: |
| 3038 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3039 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3040 | default: |
| 3041 | /* unknown state, we should put an abort() here ! */ |
| 3042 | return 1; |
| 3043 | } |
| 3044 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3045 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3046 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3047 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3048 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3049 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3050 | { |
| 3051 | /* WARNING! This must fit in the first buffer !!! */ |
| 3052 | chunk_appendf(&trash, |
| 3053 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3054 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3055 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3056 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3057 | "<style type=\"text/css\"><!--\n" |
| 3058 | "body {" |
| 3059 | " font-family: arial, helvetica, sans-serif;" |
| 3060 | " font-size: 12px;" |
| 3061 | " font-weight: normal;" |
| 3062 | " color: black;" |
| 3063 | " background: white;" |
| 3064 | "}\n" |
| 3065 | "th,td {" |
| 3066 | " font-size: 10px;" |
| 3067 | "}\n" |
| 3068 | "h1 {" |
| 3069 | " font-size: x-large;" |
| 3070 | " margin-bottom: 0.5em;" |
| 3071 | "}\n" |
| 3072 | "h2 {" |
| 3073 | " font-family: helvetica, arial;" |
| 3074 | " font-size: x-large;" |
| 3075 | " font-weight: bold;" |
| 3076 | " font-style: italic;" |
| 3077 | " color: #6020a0;" |
| 3078 | " margin-top: 0em;" |
| 3079 | " margin-bottom: 0em;" |
| 3080 | "}\n" |
| 3081 | "h3 {" |
| 3082 | " font-family: helvetica, arial;" |
| 3083 | " font-size: 16px;" |
| 3084 | " font-weight: bold;" |
| 3085 | " color: #b00040;" |
| 3086 | " background: #e8e8d0;" |
| 3087 | " margin-top: 0em;" |
| 3088 | " margin-bottom: 0em;" |
| 3089 | "}\n" |
| 3090 | "li {" |
| 3091 | " margin-top: 0.25em;" |
| 3092 | " margin-right: 2em;" |
| 3093 | "}\n" |
| 3094 | ".hr {margin-top: 0.25em;" |
| 3095 | " border-color: black;" |
| 3096 | " border-bottom-style: solid;" |
| 3097 | "}\n" |
| 3098 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3099 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3100 | ".frontend {background: #e8e8d0;}\n" |
| 3101 | ".socket {background: #d0d0d0;}\n" |
| 3102 | ".backend {background: #e8e8d0;}\n" |
| 3103 | ".active0 {background: #ff9090;}\n" |
| 3104 | ".active1 {background: #ffd020;}\n" |
| 3105 | ".active2 {background: #ffffa0;}\n" |
| 3106 | ".active3 {background: #c0ffc0;}\n" |
| 3107 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3108 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3109 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3110 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3111 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3112 | ".backup0 {background: #ff9090;}\n" |
| 3113 | ".backup1 {background: #ff80ff;}\n" |
| 3114 | ".backup2 {background: #c060ff;}\n" |
| 3115 | ".backup3 {background: #b0d0ff;}\n" |
| 3116 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3117 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3118 | ".backup6 {background: #c060ff;}\n" |
| 3119 | ".backup7 {background: #cc9900;}\n" |
| 3120 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3121 | ".maintain {background: #c07820;}\n" |
| 3122 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3123 | "\n" |
| 3124 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3125 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3126 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3127 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3128 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3129 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3130 | "\n" |
| 3131 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3132 | "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" |
| 3133 | "table.tbl td.ac { text-align: center;}\n" |
| 3134 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3135 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3136 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3137 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3138 | "\n" |
| 3139 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3140 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3141 | "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] | 3142 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3143 | "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" |
| 3144 | "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] | 3145 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3146 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3147 | " display:block;\n" |
| 3148 | " visibility:hidden;\n" |
| 3149 | " z-index:2147483647;\n" |
| 3150 | " position:absolute;\n" |
| 3151 | " padding:2px 4px 3px;\n" |
| 3152 | " background:#f0f060; color:#000000;\n" |
| 3153 | " border:1px solid #7040c0;\n" |
| 3154 | " white-space:nowrap;\n" |
| 3155 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3156 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3157 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3158 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3159 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3160 | "-->\n" |
| 3161 | "</style></head>\n", |
| 3162 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3163 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3164 | ); |
| 3165 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3166 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3167 | /* 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] | 3168 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3169 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3170 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3171 | 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] | 3172 | { |
| 3173 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3174 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3175 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3176 | /* WARNING! this has to fit the first packet too. |
| 3177 | * We are around 3.5 kB, add adding entries will |
| 3178 | * become tricky if we want to support 4kB buffers ! |
| 3179 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3180 | chunk_appendf(&trash, |
| 3181 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3182 | PRODUCT_NAME "%s</a></h1>\n" |
| 3183 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3184 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3185 | "<h3>> General process information</h3>\n" |
| 3186 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3187 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3188 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3189 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3190 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3191 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3192 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3193 | "</td><td align=\"center\" nowrap>\n" |
| 3194 | "<table class=\"lgd\"><tr>\n" |
| 3195 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3196 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3197 | "</tr><tr>\n" |
| 3198 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3199 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3200 | "</tr><tr>\n" |
| 3201 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3202 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3203 | "</tr><tr>\n" |
| 3204 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3205 | "</tr><tr>\n" |
| 3206 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3207 | "</tr><tr>\n" |
| 3208 | "<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] | 3209 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3210 | "<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] | 3211 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3212 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3213 | "</td>" |
| 3214 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3215 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3216 | "", |
| 3217 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3218 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3219 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3220 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3221 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3222 | pid, relative_pid, global.nbproc, |
| 3223 | up / 86400, (up % 86400) / 3600, |
| 3224 | (up % 3600) / 60, (up % 60), |
| 3225 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3226 | global.rlimit_memmax ? " MB" : "", |
| 3227 | global.rlimit_nofile, |
| 3228 | global.maxsock, global.maxconn, global.maxpipes, |
| 3229 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3230 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3231 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3232 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3233 | /* scope_txt = search query, si->appctx.ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3234 | memcpy(scope_txt, bo_ptr(si->ob->buf) + si->appctx.ctx.stats.scope_str, si->appctx.ctx.stats.scope_len); |
| 3235 | scope_txt[si->appctx.ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3236 | |
| 3237 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3238 | "<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] | 3239 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3240 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3241 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3242 | (si->appctx.ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3243 | STAT_SCOPE_TXT_MAXLEN); |
| 3244 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3245 | /* 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] | 3246 | scope_txt[0] = 0; |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3247 | if (si->appctx.ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3248 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3249 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + si->appctx.ctx.stats.scope_str, si->appctx.ctx.stats.scope_len); |
| 3250 | 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] | 3251 | } |
| 3252 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3253 | if (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3254 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3255 | "<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] | 3256 | uri->uri_prefix, |
| 3257 | "", |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3258 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3259 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3260 | else |
| 3261 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3262 | "<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] | 3263 | uri->uri_prefix, |
| 3264 | ";up", |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3265 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3266 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3267 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3268 | if (uri->refresh > 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3269 | if (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3270 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3271 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3272 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3273 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3274 | "", |
| 3275 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3276 | else |
| 3277 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3278 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3279 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3280 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3281 | ";norefresh", |
| 3282 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3283 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3284 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3285 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3286 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3287 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3288 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3289 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3290 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3291 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3292 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3293 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3294 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3295 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3296 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3297 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3298 | chunk_appendf(&trash, |
| 3299 | "</ul></td>" |
| 3300 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3301 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3302 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3303 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3304 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3305 | "</ul>" |
| 3306 | "</td>" |
| 3307 | "</tr></table>\n" |
| 3308 | "" |
| 3309 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3310 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3311 | if (si->appctx.ctx.stats.st_code) { |
| 3312 | switch (si->appctx.ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3313 | case STAT_STATUS_DONE: |
| 3314 | chunk_appendf(&trash, |
| 3315 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3316 | "<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] | 3317 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3318 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3319 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3320 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3321 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3322 | break; |
| 3323 | case STAT_STATUS_NONE: |
| 3324 | chunk_appendf(&trash, |
| 3325 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3326 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3327 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3328 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3329 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3330 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3331 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3332 | break; |
| 3333 | case STAT_STATUS_PART: |
| 3334 | chunk_appendf(&trash, |
| 3335 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3336 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3337 | "Action partially processed.<br>" |
| 3338 | "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] | 3339 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3340 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3341 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3342 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3343 | break; |
| 3344 | case STAT_STATUS_ERRP: |
| 3345 | chunk_appendf(&trash, |
| 3346 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3347 | "<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] | 3348 | "Action not processed because of invalid parameters." |
| 3349 | "<ul>" |
| 3350 | "<li>The action is maybe unknown.</li>" |
| 3351 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3352 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3353 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3354 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3355 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3356 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3357 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3358 | break; |
| 3359 | case STAT_STATUS_EXCD: |
| 3360 | chunk_appendf(&trash, |
| 3361 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3362 | "<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] | 3363 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3364 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3365 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3366 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3367 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3368 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3369 | break; |
| 3370 | case STAT_STATUS_DENY: |
| 3371 | chunk_appendf(&trash, |
| 3372 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3373 | "<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] | 3374 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3375 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3376 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3377 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3378 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3379 | break; |
| 3380 | default: |
| 3381 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3382 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3383 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3384 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3385 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3386 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3387 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3388 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3389 | } |
| 3390 | chunk_appendf(&trash, "<p>\n"); |
| 3391 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3392 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3393 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3394 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3395 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3396 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3397 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3398 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3399 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3400 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3401 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3402 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3403 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3404 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3405 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3406 | * and the session must be closed, or -1 in case of any error. This function is |
| 3407 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3408 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3409 | 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] | 3410 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3411 | struct channel *rep = si->ib; |
| 3412 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3413 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3414 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3415 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3416 | switch (si->appctx.st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3417 | case STAT_ST_INIT: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3418 | si->appctx.st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3419 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3420 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3421 | case STAT_ST_HEAD: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3422 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3423 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3424 | else |
| 3425 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3426 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3427 | if (bi_putchk(rep, &trash) == -1) |
| 3428 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3429 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3430 | si->appctx.st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3431 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3432 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3433 | case STAT_ST_INFO: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3434 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3435 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3436 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3437 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3438 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3439 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3440 | si->appctx.ctx.stats.px = proxy; |
| 3441 | si->appctx.ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3442 | si->appctx.st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3443 | /* fall through */ |
| 3444 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3445 | case STAT_ST_LIST: |
| 3446 | /* dump proxies */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3447 | while (si->appctx.ctx.stats.px) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3448 | if (buffer_almost_full(rep->buf)) |
| 3449 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3450 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3451 | px = si->appctx.ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3452 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 3453 | 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] | 3454 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3455 | return 0; |
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.ctx.stats.px = px->next; |
| 3458 | si->appctx.ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3459 | } |
| 3460 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3461 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3462 | si->appctx.st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3463 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3464 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3465 | case STAT_ST_END: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3466 | if (si->appctx.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3467 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3468 | if (bi_putchk(rep, &trash) == -1) |
| 3469 | return 0; |
| 3470 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3471 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3472 | si->appctx.st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3473 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 3474 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3475 | case STAT_ST_FIN: |
| 3476 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3477 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3478 | default: |
| 3479 | /* unknown state ! */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3480 | si->appctx.st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3481 | return -1; |
| 3482 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3483 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3484 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3485 | /* We reached the stats page through a POST request. |
| 3486 | * Parse the posted data and enable/disable servers if necessary. |
| 3487 | * Returns 1 if request was parsed or zero if it needs more data. |
| 3488 | */ |
| 3489 | static int stats_process_http_post(struct stream_interface *si) |
| 3490 | { |
| 3491 | struct session *s = session_from_task(si->owner); |
| 3492 | |
| 3493 | struct proxy *px = NULL; |
| 3494 | struct server *sv = NULL; |
| 3495 | |
| 3496 | char key[LINESIZE]; |
| 3497 | int action = ST_ADM_ACTION_NONE; |
| 3498 | int reprocess = 0; |
| 3499 | |
| 3500 | int total_servers = 0; |
| 3501 | int altered_servers = 0; |
| 3502 | |
| 3503 | char *first_param, *cur_param, *next_param, *end_params; |
| 3504 | char *st_cur_param = NULL; |
| 3505 | char *st_next_param = NULL; |
| 3506 | |
| 3507 | struct chunk *temp; |
| 3508 | int reql; |
| 3509 | |
| 3510 | temp = get_trash_chunk(); |
| 3511 | if (temp->size < s->txn.req.body_len) { |
| 3512 | /* too large request */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3513 | si->appctx.ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3514 | goto out; |
| 3515 | } |
| 3516 | |
| 3517 | reql = bo_getblk(si->ob, temp->str, s->txn.req.body_len, s->txn.req.eoh + 2); |
| 3518 | if (reql <= 0) { |
| 3519 | /* we need more data */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3520 | si->appctx.ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3521 | return 0; |
| 3522 | } |
| 3523 | |
| 3524 | first_param = temp->str; |
| 3525 | end_params = temp->str + reql; |
| 3526 | cur_param = next_param = end_params; |
| 3527 | *end_params = '\0'; |
| 3528 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3529 | si->appctx.ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3530 | |
| 3531 | /* |
| 3532 | * Parse the parameters in reverse order to only store the last value. |
| 3533 | * From the html form, the backend and the action are at the end. |
| 3534 | */ |
| 3535 | while (cur_param > first_param) { |
| 3536 | char *value; |
| 3537 | int poffset, plen; |
| 3538 | |
| 3539 | cur_param--; |
| 3540 | |
| 3541 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 3542 | reprocess_servers: |
| 3543 | /* Parse the key */ |
| 3544 | poffset = (cur_param != first_param ? 1 : 0); |
| 3545 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 3546 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 3547 | strncpy(key, cur_param + poffset, plen); |
| 3548 | key[plen - 1] = '\0'; |
| 3549 | } else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3550 | si->appctx.ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3551 | goto out; |
| 3552 | } |
| 3553 | |
| 3554 | /* Parse the value */ |
| 3555 | value = key; |
| 3556 | while (*value != '\0' && *value != '=') { |
| 3557 | value++; |
| 3558 | } |
| 3559 | if (*value == '=') { |
| 3560 | /* Ok, a value is found, we can mark the end of the key */ |
| 3561 | *value++ = '\0'; |
| 3562 | } |
| 3563 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 3564 | break; |
| 3565 | |
| 3566 | /* Now we can check the key to see what to do */ |
| 3567 | if (!px && (strcmp(key, "b") == 0)) { |
| 3568 | if ((px = findproxy(value, PR_CAP_BE)) == NULL) { |
| 3569 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3570 | si->appctx.ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3571 | goto out; |
| 3572 | } |
| 3573 | } |
| 3574 | else if (!action && (strcmp(key, "action") == 0)) { |
| 3575 | if (strcmp(value, "disable") == 0) { |
| 3576 | action = ST_ADM_ACTION_DISABLE; |
| 3577 | } |
| 3578 | else if (strcmp(value, "enable") == 0) { |
| 3579 | action = ST_ADM_ACTION_ENABLE; |
| 3580 | } |
| 3581 | else if (strcmp(value, "stop") == 0) { |
| 3582 | action = ST_ADM_ACTION_STOP; |
| 3583 | } |
| 3584 | else if (strcmp(value, "start") == 0) { |
| 3585 | action = ST_ADM_ACTION_START; |
| 3586 | } |
| 3587 | else if (strcmp(value, "shutdown") == 0) { |
| 3588 | action = ST_ADM_ACTION_SHUTDOWN; |
| 3589 | } |
| 3590 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3591 | si->appctx.ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3592 | goto out; |
| 3593 | } |
| 3594 | } |
| 3595 | else if (strcmp(key, "s") == 0) { |
| 3596 | if (!(px && action)) { |
| 3597 | /* |
| 3598 | * Indicates that we'll need to reprocess the parameters |
| 3599 | * as soon as backend and action are known |
| 3600 | */ |
| 3601 | if (!reprocess) { |
| 3602 | st_cur_param = cur_param; |
| 3603 | st_next_param = next_param; |
| 3604 | } |
| 3605 | reprocess = 1; |
| 3606 | } |
| 3607 | else if ((sv = findserver(px, value)) != NULL) { |
| 3608 | switch (action) { |
| 3609 | case ST_ADM_ACTION_DISABLE: |
| 3610 | if ((px->state != PR_STSTOPPED) && !(sv->state & SRV_MAINTAIN)) { |
| 3611 | /* Not already in maintenance, we can change the server state */ |
| 3612 | sv->state |= SRV_MAINTAIN; |
| 3613 | set_server_down(&sv->check); |
| 3614 | altered_servers++; |
| 3615 | total_servers++; |
| 3616 | } |
| 3617 | break; |
| 3618 | case ST_ADM_ACTION_ENABLE: |
| 3619 | if ((px->state != PR_STSTOPPED) && (sv->state & SRV_MAINTAIN)) { |
| 3620 | /* Already in maintenance, we can change the server state */ |
| 3621 | set_server_up(&sv->check); |
| 3622 | sv->check.health = sv->check.rise; /* up, but will fall down at first failure */ |
| 3623 | altered_servers++; |
| 3624 | total_servers++; |
| 3625 | } |
| 3626 | break; |
| 3627 | case ST_ADM_ACTION_STOP: |
| 3628 | case ST_ADM_ACTION_START: |
| 3629 | if (action == ST_ADM_ACTION_START) |
| 3630 | sv->uweight = sv->iweight; |
| 3631 | else |
| 3632 | sv->uweight = 0; |
| 3633 | |
| 3634 | server_recalc_eweight(sv); |
| 3635 | set_server_drain_state(sv); |
| 3636 | |
| 3637 | altered_servers++; |
| 3638 | total_servers++; |
| 3639 | break; |
| 3640 | case ST_ADM_ACTION_SHUTDOWN: |
| 3641 | if (px->state != PR_STSTOPPED) { |
| 3642 | struct session *sess, *sess_bck; |
| 3643 | |
| 3644 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 3645 | if (sess->srv_conn == sv) |
| 3646 | session_shutdown(sess, SN_ERR_KILLED); |
| 3647 | |
| 3648 | altered_servers++; |
| 3649 | total_servers++; |
| 3650 | } |
| 3651 | break; |
| 3652 | } |
| 3653 | } else { |
| 3654 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 3655 | total_servers++; |
| 3656 | } |
| 3657 | } |
| 3658 | if (reprocess && px && action) { |
| 3659 | /* Now, we know the backend and the action chosen by the user. |
| 3660 | * We can safely restart from the first server parameter |
| 3661 | * to reprocess them |
| 3662 | */ |
| 3663 | cur_param = st_cur_param; |
| 3664 | next_param = st_next_param; |
| 3665 | reprocess = 0; |
| 3666 | goto reprocess_servers; |
| 3667 | } |
| 3668 | |
| 3669 | next_param = cur_param; |
| 3670 | } |
| 3671 | } |
| 3672 | |
| 3673 | if (total_servers == 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3674 | si->appctx.ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3675 | } |
| 3676 | else if (altered_servers == 0) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3677 | si->appctx.ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3678 | } |
| 3679 | else if (altered_servers == total_servers) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3680 | si->appctx.ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3681 | } |
| 3682 | else { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3683 | si->appctx.ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3684 | } |
| 3685 | out: |
| 3686 | return 1; |
| 3687 | } |
| 3688 | |
| 3689 | |
| 3690 | static int stats_send_http_headers(struct stream_interface *si) |
| 3691 | { |
| 3692 | struct session *s = session_from_task(si->owner); |
| 3693 | struct uri_auth *uri = s->be->uri_auth; |
| 3694 | |
| 3695 | chunk_printf(&trash, |
| 3696 | "HTTP/1.0 200 OK\r\n" |
| 3697 | "Cache-Control: no-cache\r\n" |
| 3698 | "Connection: close\r\n" |
| 3699 | "Content-Type: %s\r\n", |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3700 | (si->appctx.ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3701 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3702 | if (uri->refresh > 0 && !(si->appctx.ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3703 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 3704 | uri->refresh); |
| 3705 | |
| 3706 | chunk_appendf(&trash, "\r\n"); |
| 3707 | |
| 3708 | s->txn.status = 200; |
| 3709 | s->logs.tv_request = now; |
| 3710 | |
| 3711 | if (bi_putchk(si->ib, &trash) == -1) |
| 3712 | return 0; |
| 3713 | |
| 3714 | return 1; |
| 3715 | } |
| 3716 | |
| 3717 | static int stats_send_http_redirect(struct stream_interface *si) |
| 3718 | { |
| 3719 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3720 | struct session *s = session_from_task(si->owner); |
| 3721 | struct uri_auth *uri = s->be->uri_auth; |
| 3722 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3723 | /* 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] | 3724 | scope_txt[0] = 0; |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3725 | if (si->appctx.ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3726 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3727 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + si->appctx.ctx.stats.scope_str, si->appctx.ctx.stats.scope_len); |
| 3728 | 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] | 3729 | } |
| 3730 | |
| 3731 | /* We don't want to land on the posted stats page because a refresh will |
| 3732 | * repost the data. We don't want this to happen on accident so we redirect |
| 3733 | * the browse to the stats page with a GET. |
| 3734 | */ |
| 3735 | chunk_printf(&trash, |
| 3736 | "HTTP/1.1 303 See Other\r\n" |
| 3737 | "Cache-Control: no-cache\r\n" |
| 3738 | "Content-Type: text/plain\r\n" |
| 3739 | "Connection: close\r\n" |
| 3740 | "Location: %s;st=%s%s%s%s\r\n" |
| 3741 | "\r\n", |
| 3742 | uri->uri_prefix, |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3743 | ((si->appctx.ctx.stats.st_code > STAT_STATUS_INIT) && |
| 3744 | (si->appctx.ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 3745 | stat_status_codes[si->appctx.ctx.stats.st_code]) ? |
| 3746 | stat_status_codes[si->appctx.ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3747 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3748 | (si->appctx.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3749 | (si->appctx.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3750 | scope_txt); |
| 3751 | |
| 3752 | s->txn.status = 303; |
| 3753 | s->logs.tv_request = now; |
| 3754 | |
| 3755 | if (bi_putchk(si->ib, &trash) == -1) |
| 3756 | return 0; |
| 3757 | |
| 3758 | return 1; |
| 3759 | } |
| 3760 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3761 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 3762 | * 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] | 3763 | * si->appctx.st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3764 | * automatically unregisters itself once transfer is complete. |
| 3765 | */ |
| 3766 | static void http_stats_io_handler(struct stream_interface *si) |
| 3767 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3768 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3769 | struct channel *req = si->ob; |
| 3770 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3771 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3772 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 3773 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3774 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3775 | /* check that the output is not closed */ |
| 3776 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3777 | si->appctx.st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3778 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3779 | /* all states are processed in sequence */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3780 | if (si->appctx.st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3781 | if (stats_send_http_headers(si)) { |
| 3782 | if (s->txn.meth == HTTP_METH_HEAD) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3783 | si->appctx.st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3784 | else |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3785 | si->appctx.st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3786 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3787 | } |
| 3788 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3789 | if (si->appctx.st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3790 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3791 | si->appctx.st0 = STAT_HTTP_DONE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3792 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3793 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3794 | if (si->appctx.st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3795 | if (stats_process_http_post(si)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3796 | si->appctx.st0 = STAT_HTTP_LAST; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3797 | else if (si->ob->flags & CF_SHUTR) |
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_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3802 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3803 | si->appctx.st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3804 | } |
| 3805 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3806 | if (si->appctx.st0 == STAT_HTTP_DONE) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 3807 | si_shutw(si); |
| 3808 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3809 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 3810 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3811 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3812 | if (si->appctx.st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 3813 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 3814 | si_shutr(si); |
| 3815 | res->flags |= CF_READ_NULL; |
| 3816 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3817 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3818 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3819 | /* update all other flags and resync with the other side */ |
| 3820 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3821 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3822 | /* we don't want to expire timeouts while we're processing requests */ |
| 3823 | si->ib->rex = TICK_ETERNITY; |
| 3824 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3825 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3826 | out: |
| 3827 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 3828 | /* check that we have released everything then unregister */ |
| 3829 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3830 | } |
| 3831 | } |
| 3832 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3833 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3834 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 3835 | { |
| 3836 | if (!conn->ctrl) |
| 3837 | return "NONE"; |
| 3838 | return conn->ctrl->name; |
| 3839 | } |
| 3840 | |
| 3841 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 3842 | { |
| 3843 | static char ptr[17]; |
| 3844 | |
| 3845 | if (!conn->xprt) |
| 3846 | return "NONE"; |
| 3847 | |
| 3848 | if (conn->xprt == &raw_sock) |
| 3849 | return "RAW"; |
| 3850 | |
| 3851 | #ifdef USE_OPENSSL |
| 3852 | if (conn->xprt == &ssl_sock) |
| 3853 | return "SSL"; |
| 3854 | #endif |
| 3855 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 3856 | return ptr; |
| 3857 | } |
| 3858 | |
| 3859 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 3860 | { |
| 3861 | static char ptr[17]; |
| 3862 | |
| 3863 | if (!conn->data) |
| 3864 | return "NONE"; |
| 3865 | |
| 3866 | if (conn->data == &sess_conn_cb) |
| 3867 | return "SESS"; |
| 3868 | |
| 3869 | if (conn->data == &si_conn_cb) |
| 3870 | return "STRM"; |
| 3871 | |
| 3872 | if (conn->data == &check_conn_cb) |
| 3873 | return "CHCK"; |
| 3874 | |
| 3875 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 3876 | return ptr; |
| 3877 | } |
| 3878 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 3879 | /* This function dumps a complete session state onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 3880 | * 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] | 3881 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 3882 | * 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] | 3883 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3884 | 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] | 3885 | { |
| 3886 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3887 | extern const char *monthname[12]; |
| 3888 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3889 | struct connection *conn; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3890 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3891 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3892 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3893 | 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] | 3894 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3895 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 3896 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3897 | return 0; |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3898 | si->appctx.ctx.sess.uid = 0; |
| 3899 | si->appctx.ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3900 | return 1; |
| 3901 | } |
| 3902 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3903 | switch (si->appctx.ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3904 | case 0: /* main status of the session */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 3905 | si->appctx.ctx.sess.uid = sess->uniq_id; |
| 3906 | si->appctx.ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3907 | /* fall through */ |
| 3908 | |
| 3909 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3910 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3911 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3912 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3913 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3914 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 3915 | 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] | 3916 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 3917 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3918 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3919 | conn = objt_conn(sess->si[0].end); |
| 3920 | switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3921 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3922 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3923 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3924 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3925 | break; |
| 3926 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3927 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3928 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3929 | default: |
| 3930 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3931 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3932 | break; |
| 3933 | } |
| 3934 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3935 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3936 | " 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] | 3937 | 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] | 3938 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3939 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3940 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3941 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 3942 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 3943 | sess->listener ? sess->listener->luid : 0); |
| 3944 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3945 | if (conn) |
| 3946 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 3947 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3948 | switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3949 | case AF_INET: |
| 3950 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3951 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3952 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3953 | break; |
| 3954 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3955 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3956 | break; |
| 3957 | default: |
| 3958 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3959 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3960 | break; |
| 3961 | } |
| 3962 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3963 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3964 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3965 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3966 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3967 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 3968 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3969 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3970 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3971 | conn = objt_conn(sess->si[1].end); |
| 3972 | if (conn) |
| 3973 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 3974 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3975 | switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3976 | case AF_INET: |
| 3977 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3978 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3979 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3980 | break; |
| 3981 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3982 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3983 | break; |
| 3984 | default: |
| 3985 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3986 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3987 | break; |
| 3988 | } |
| 3989 | |
| 3990 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3991 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3992 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 3993 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 3994 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3995 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3996 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3997 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 3998 | if (conn) |
| 3999 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4000 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4001 | switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4002 | case AF_INET: |
| 4003 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4004 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4005 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4006 | break; |
| 4007 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4008 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4009 | break; |
| 4010 | default: |
| 4011 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4012 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 4013 | break; |
| 4014 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4015 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4016 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4017 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4018 | sess->task, |
| 4019 | sess->task->state, |
| 4020 | sess->task->nice, sess->task->calls, |
| 4021 | sess->task->expire ? |
| 4022 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 4023 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 4024 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4025 | task_in_rq(sess->task) ? ", running" : ""); |
| 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 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4029 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 4030 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4031 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4032 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 4033 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 4034 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 4035 | |
| 4036 | chunk_appendf(&trash, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4037 | " 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] | 4038 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4039 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4040 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4041 | obj_type_name(sess->si[0].end), |
| 4042 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4043 | sess->si[0].conn, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4044 | sess->si[0].exp ? |
| 4045 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 4046 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 4047 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4048 | sess->si[0].err_type); |
| 4049 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4050 | chunk_appendf(&trash, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4051 | " 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] | 4052 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 4053 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4054 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4055 | obj_type_name(sess->si[1].end), |
| 4056 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4057 | sess->si[1].conn, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4058 | sess->si[1].exp ? |
| 4059 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 4060 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 4061 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 4062 | sess->si[1].err_type); |
| 4063 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4064 | conn = objt_conn(sess->si[0].end); |
| 4065 | if (conn) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4066 | chunk_appendf(&trash, |
| 4067 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4068 | conn, |
| 4069 | get_conn_ctrl_name(conn), |
| 4070 | get_conn_xprt_name(conn), |
| 4071 | get_conn_data_name(conn), |
| 4072 | obj_type_name(conn->target), |
| 4073 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4074 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4075 | chunk_appendf(&trash, |
| 4076 | " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4077 | conn->flags, |
| 4078 | conn->t.sock.fd, |
| 4079 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_e : 0, |
| 4080 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_p : 0, |
| 4081 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4082 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 4083 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4084 | conn = objt_conn(sess->si[1].end); |
| 4085 | if (conn) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4086 | chunk_appendf(&trash, |
| 4087 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4088 | conn, |
| 4089 | get_conn_ctrl_name(conn), |
| 4090 | get_conn_xprt_name(conn), |
| 4091 | get_conn_data_name(conn), |
| 4092 | obj_type_name(conn->target), |
| 4093 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4094 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4095 | chunk_appendf(&trash, |
| 4096 | " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4097 | conn->flags, |
| 4098 | conn->t.sock.fd, |
| 4099 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_e : 0, |
| 4100 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_p : 0, |
| 4101 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 4102 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4103 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4104 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4105 | " 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] | 4106 | " an_exp=%s", |
| 4107 | sess->req, |
| 4108 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4109 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4110 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4111 | sess->req->analyse_exp ? |
| 4112 | human_time(TICKS_TO_MS(sess->req->analyse_exp - 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 | " rex=%s", |
| 4117 | sess->req->rex ? |
| 4118 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 4119 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4120 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4121 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4122 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4123 | " 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] | 4124 | sess->req->wex ? |
| 4125 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 4126 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4127 | sess->req->buf, |
| 4128 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4129 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4130 | sess->txn.req.next, sess->req->buf->i, |
| 4131 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4132 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4133 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4134 | " 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] | 4135 | " an_exp=%s", |
| 4136 | sess->rep, |
| 4137 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4138 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4139 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4140 | sess->rep->analyse_exp ? |
| 4141 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - 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 | " rex=%s", |
| 4146 | sess->rep->rex ? |
| 4147 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 4148 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 4149 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4150 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4151 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4152 | " 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] | 4153 | sess->rep->wex ? |
| 4154 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 4155 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4156 | sess->rep->buf, |
| 4157 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4158 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 4159 | sess->txn.rsp.next, sess->rep->buf->i, |
| 4160 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4161 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4162 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4163 | return 0; |
| 4164 | |
| 4165 | /* use other states to dump the contents */ |
| 4166 | } |
| 4167 | /* end of dump */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4168 | si->appctx.ctx.sess.uid = 0; |
| 4169 | si->appctx.ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4170 | return 1; |
| 4171 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4172 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4173 | /* This function dumps all sessions' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4174 | * 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] | 4175 | * to be called again, otherwise non-zero. It is designed to be called |
| 4176 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4177 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4178 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4179 | { |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4180 | struct connection *conn; |
| 4181 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4182 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4183 | /* If we're forced to shut down, we might have to remove our |
| 4184 | * reference to the last session being dumped. |
| 4185 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4186 | if (si->appctx.st2 == STAT_ST_LIST) { |
| 4187 | if (!LIST_ISEMPTY(&si->appctx.ctx.sess.bref.users)) { |
| 4188 | LIST_DEL(&si->appctx.ctx.sess.bref.users); |
| 4189 | LIST_INIT(&si->appctx.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4190 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4191 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4192 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4193 | } |
| 4194 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4195 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4196 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4197 | switch (si->appctx.st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4198 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4199 | /* the function had not been called yet, let's prepare the |
| 4200 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4201 | * pointer to the first in the global list. When a target |
| 4202 | * session is being destroyed, it is responsible for updating |
| 4203 | * this pointer. We know we have reached the end when this |
| 4204 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4205 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4206 | LIST_INIT(&si->appctx.ctx.sess.bref.users); |
| 4207 | si->appctx.ctx.sess.bref.ref = sessions.n; |
| 4208 | si->appctx.st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4209 | /* fall through */ |
| 4210 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4211 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4212 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4213 | if (!LIST_ISEMPTY(&si->appctx.ctx.sess.bref.users)) { |
| 4214 | LIST_DEL(&si->appctx.ctx.sess.bref.users); |
| 4215 | LIST_INIT(&si->appctx.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | /* and start from where we stopped */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4219 | while (si->appctx.ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 4220 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4221 | struct session *curr_sess; |
| 4222 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4223 | 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] | 4224 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4225 | if (si->appctx.ctx.sess.target) { |
| 4226 | 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] | 4227 | goto next_sess; |
| 4228 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4229 | LIST_ADDQ(&curr_sess->back_refs, &si->appctx.ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4230 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4231 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4232 | return 0; |
| 4233 | |
| 4234 | /* session dump complete */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4235 | LIST_DEL(&si->appctx.ctx.sess.bref.users); |
| 4236 | LIST_INIT(&si->appctx.ctx.sess.bref.users); |
| 4237 | if (si->appctx.ctx.sess.target != (void *)-1) { |
| 4238 | si->appctx.ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4239 | break; |
| 4240 | } |
| 4241 | else |
| 4242 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4243 | } |
| 4244 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4245 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4246 | "%p: proto=%s", |
| 4247 | curr_sess, |
| 4248 | curr_sess->listener->proto->name); |
| 4249 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4250 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4251 | conn = objt_conn(curr_sess->si[0].end); |
| 4252 | switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 4253 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4254 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4255 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4256 | " src=%s:%d fe=%s be=%s srv=%s", |
| 4257 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4258 | get_host_port(&conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4259 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4260 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4261 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4262 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4263 | break; |
| 4264 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4265 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4266 | " src=unix:%d fe=%s be=%s srv=%s", |
| 4267 | curr_sess->listener->luid, |
| 4268 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 4269 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4270 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 4271 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4272 | break; |
| 4273 | } |
| 4274 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4275 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 4276 | " ts=%02x age=%s calls=%d", |
| 4277 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 4278 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 4279 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4280 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4281 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 4282 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4283 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4284 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4285 | curr_sess->req->analysers, |
| 4286 | curr_sess->req->rex ? |
| 4287 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 4288 | TICKS_TO_MS(1000)) : ""); |
| 4289 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4290 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4291 | ",wx=%s", |
| 4292 | curr_sess->req->wex ? |
| 4293 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 4294 | TICKS_TO_MS(1000)) : ""); |
| 4295 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4296 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4297 | ",ax=%s]", |
| 4298 | curr_sess->req->analyse_exp ? |
| 4299 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 4300 | TICKS_TO_MS(1000)) : ""); |
| 4301 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4302 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 4303 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4304 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 4305 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4306 | curr_sess->rep->analysers, |
| 4307 | curr_sess->rep->rex ? |
| 4308 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 4309 | TICKS_TO_MS(1000)) : ""); |
| 4310 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4311 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4312 | ",wx=%s", |
| 4313 | curr_sess->rep->wex ? |
| 4314 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 4315 | TICKS_TO_MS(1000)) : ""); |
| 4316 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4317 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4318 | ",ax=%s]", |
| 4319 | curr_sess->rep->analyse_exp ? |
| 4320 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 4321 | TICKS_TO_MS(1000)) : ""); |
| 4322 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4323 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4324 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4325 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 4326 | curr_sess->si[0].state, |
| 4327 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4328 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4329 | curr_sess->si[0].exp ? |
| 4330 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 4331 | TICKS_TO_MS(1000)) : ""); |
| 4332 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4333 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4334 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4335 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 4336 | curr_sess->si[1].state, |
| 4337 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 4338 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4339 | curr_sess->si[1].exp ? |
| 4340 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 4341 | TICKS_TO_MS(1000)) : ""); |
| 4342 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4343 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4344 | " exp=%s", |
| 4345 | curr_sess->task->expire ? |
| 4346 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 4347 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 4348 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4349 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4350 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4351 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4352 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4353 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4354 | /* let's try again later from this session. We add ourselves into |
| 4355 | * this session's users so that it can remove us upon termination. |
| 4356 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4357 | LIST_ADDQ(&curr_sess->back_refs, &si->appctx.ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4358 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4359 | } |
| 4360 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4361 | next_sess: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4362 | si->appctx.ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4363 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4364 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4365 | 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] | 4366 | /* specified session not found */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4367 | if (si->appctx.ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4368 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4369 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4370 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4371 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4372 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4373 | return 0; |
| 4374 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4375 | si->appctx.ctx.sess.target = NULL; |
| 4376 | si->appctx.ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4377 | return 1; |
| 4378 | } |
| 4379 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4380 | si->appctx.st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4381 | /* fall through */ |
| 4382 | |
| 4383 | default: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4384 | si->appctx.st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4385 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4386 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 4387 | } |
| 4388 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4389 | /* This is called when the stream interface is closed. For instance, upon an |
| 4390 | * external abort, we won't call the i/o handler anymore so we may need to |
| 4391 | * remove back references to the session currently being dumped. |
| 4392 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 4393 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4394 | { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4395 | if (si->appctx.st0 == STAT_CLI_O_SESS && si->appctx.st2 == STAT_ST_LIST) { |
| 4396 | if (!LIST_ISEMPTY(&si->appctx.ctx.sess.bref.users)) |
| 4397 | LIST_DEL(&si->appctx.ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4398 | } |
| 4399 | } |
| 4400 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4401 | /* This function is used to either dump tables states (when action is set |
| 4402 | * 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] | 4403 | * It returns 0 if the output buffer is full and it needs to be called |
| 4404 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4405 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4406 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4407 | { |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4408 | struct session *s = session_from_task(si->owner); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4409 | struct ebmb_node *eb; |
| 4410 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4411 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4412 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4413 | |
| 4414 | /* |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4415 | * We have 3 possible states in si->appctx.st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4416 | * - STAT_ST_INIT : the first call |
| 4417 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4418 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4419 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4420 | * and the entry pointer points to the next entry to be dumped, |
| 4421 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4422 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4423 | * data though. |
| 4424 | */ |
| 4425 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4426 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4427 | /* 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] | 4428 | if (si->appctx.st2 == STAT_ST_LIST) { |
| 4429 | si->appctx.ctx.table.entry->ref_cnt--; |
| 4430 | 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] | 4431 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4432 | return 1; |
| 4433 | } |
| 4434 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4435 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4436 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4437 | while (si->appctx.st2 != STAT_ST_FIN) { |
| 4438 | switch (si->appctx.st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4439 | case STAT_ST_INIT: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4440 | si->appctx.ctx.table.proxy = si->appctx.ctx.table.target; |
| 4441 | if (!si->appctx.ctx.table.proxy) |
| 4442 | si->appctx.ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4443 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4444 | si->appctx.ctx.table.entry = NULL; |
| 4445 | si->appctx.st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4446 | break; |
| 4447 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4448 | case STAT_ST_INFO: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4449 | if (!si->appctx.ctx.table.proxy || |
| 4450 | (si->appctx.ctx.table.target && |
| 4451 | si->appctx.ctx.table.proxy != si->appctx.ctx.table.target)) { |
| 4452 | si->appctx.st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4453 | break; |
| 4454 | } |
| 4455 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4456 | if (si->appctx.ctx.table.proxy->table.size) { |
| 4457 | if (show && !stats_dump_table_head_to_buffer(&trash, si, si->appctx.ctx.table.proxy, |
| 4458 | si->appctx.ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4459 | return 0; |
| 4460 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4461 | if (si->appctx.ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 4462 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4463 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4464 | eb = ebmb_first(&si->appctx.ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4465 | if (eb) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4466 | si->appctx.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 4467 | si->appctx.ctx.table.entry->ref_cnt++; |
| 4468 | si->appctx.st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4469 | break; |
| 4470 | } |
| 4471 | } |
| 4472 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4473 | si->appctx.ctx.table.proxy = si->appctx.ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4474 | break; |
| 4475 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4476 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4477 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4478 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4479 | if (si->appctx.ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4480 | /* we're filtering on some data contents */ |
| 4481 | void *ptr; |
| 4482 | long long data; |
| 4483 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4484 | dt = si->appctx.ctx.table.data_type; |
| 4485 | ptr = stktable_data_ptr(&si->appctx.ctx.table.proxy->table, |
| 4486 | si->appctx.ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4487 | dt); |
| 4488 | |
| 4489 | data = 0; |
| 4490 | switch (stktable_data_types[dt].std_type) { |
| 4491 | case STD_T_SINT: |
| 4492 | data = stktable_data_cast(ptr, std_t_sint); |
| 4493 | break; |
| 4494 | case STD_T_UINT: |
| 4495 | data = stktable_data_cast(ptr, std_t_uint); |
| 4496 | break; |
| 4497 | case STD_T_ULL: |
| 4498 | data = stktable_data_cast(ptr, std_t_ull); |
| 4499 | break; |
| 4500 | case STD_T_FRQP: |
| 4501 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4502 | si->appctx.ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4503 | break; |
| 4504 | } |
| 4505 | |
| 4506 | /* 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] | 4507 | if ((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_GT || |
| 4510 | si->appctx.ctx.table.data_op == STD_OP_GE)) || |
| 4511 | (data == si->appctx.ctx.table.value && |
| 4512 | (si->appctx.ctx.table.data_op == STD_OP_NE || |
| 4513 | si->appctx.ctx.table.data_op == STD_OP_GT || |
| 4514 | si->appctx.ctx.table.data_op == STD_OP_LT)) || |
| 4515 | (data > si->appctx.ctx.table.value && |
| 4516 | (si->appctx.ctx.table.data_op == STD_OP_EQ || |
| 4517 | si->appctx.ctx.table.data_op == STD_OP_LT || |
| 4518 | si->appctx.ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4519 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4520 | } |
| 4521 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4522 | if (show && !skip_entry && |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4523 | !stats_dump_table_entry_to_buffer(&trash, si, si->appctx.ctx.table.proxy, |
| 4524 | si->appctx.ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 4525 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4526 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4527 | si->appctx.ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4528 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4529 | eb = ebmb_next(&si->appctx.ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4530 | if (eb) { |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4531 | struct stksess *old = si->appctx.ctx.table.entry; |
| 4532 | si->appctx.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 4533 | if (show) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4534 | stksess_kill_if_expired(&si->appctx.ctx.table.proxy->table, old); |
| 4535 | else if (!skip_entry && !si->appctx.ctx.table.entry->ref_cnt) |
| 4536 | stksess_kill(&si->appctx.ctx.table.proxy->table, old); |
| 4537 | si->appctx.ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4538 | break; |
| 4539 | } |
| 4540 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4541 | |
| 4542 | if (show) |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4543 | stksess_kill_if_expired(&si->appctx.ctx.table.proxy->table, si->appctx.ctx.table.entry); |
| 4544 | else if (!skip_entry && !si->appctx.ctx.table.entry->ref_cnt) |
| 4545 | 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] | 4546 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4547 | si->appctx.ctx.table.proxy = si->appctx.ctx.table.proxy->next; |
| 4548 | si->appctx.st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4549 | break; |
| 4550 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4551 | case STAT_ST_END: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4552 | si->appctx.st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4553 | break; |
| 4554 | } |
| 4555 | } |
| 4556 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4557 | } |
| 4558 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4559 | /* 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] | 4560 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 4561 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 4562 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 4563 | * lines are respected within the limit of 70 output chars. Lines that are |
| 4564 | * continuation of a previous truncated line begin with "+" instead of " " |
| 4565 | * after the offset. The new pointer is returned. |
| 4566 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4567 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 4568 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4569 | { |
| 4570 | int end; |
| 4571 | unsigned char c; |
| 4572 | |
| 4573 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4574 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4575 | return ptr; |
| 4576 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 4577 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4578 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4579 | while (ptr < len && ptr < bsize) { |
| 4580 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4581 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4582 | if (out->len > end - 2) |
| 4583 | break; |
| 4584 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4585 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4586 | if (out->len > end - 3) |
| 4587 | break; |
| 4588 | out->str[out->len++] = '\\'; |
| 4589 | switch (c) { |
| 4590 | case '\t': c = 't'; break; |
| 4591 | case '\n': c = 'n'; break; |
| 4592 | case '\r': c = 'r'; break; |
| 4593 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4594 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4595 | } |
| 4596 | out->str[out->len++] = c; |
| 4597 | } else { |
| 4598 | if (out->len > end - 5) |
| 4599 | break; |
| 4600 | out->str[out->len++] = '\\'; |
| 4601 | out->str[out->len++] = 'x'; |
| 4602 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 4603 | out->str[out->len++] = hextab[c & 0xF]; |
| 4604 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4605 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4606 | /* we had a line break, let's return now */ |
| 4607 | out->str[out->len++] = '\n'; |
| 4608 | *line = ptr; |
| 4609 | return ptr; |
| 4610 | } |
| 4611 | } |
| 4612 | /* we have an incomplete line, we return it as-is */ |
| 4613 | out->str[out->len++] = '\n'; |
| 4614 | return ptr; |
| 4615 | } |
| 4616 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4617 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4618 | * 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] | 4619 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4620 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4621 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4622 | { |
| 4623 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4624 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4625 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4626 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4627 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4628 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4629 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4630 | if (!si->appctx.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4631 | /* the function had not been called yet, let's prepare the |
| 4632 | * buffer for a response. |
| 4633 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4634 | struct tm tm; |
| 4635 | |
| 4636 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4637 | 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] | 4638 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4639 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 4640 | error_snapshot_id); |
| 4641 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4642 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4643 | /* Socket buffer full. Let's try again later from the same point */ |
| 4644 | return 0; |
| 4645 | } |
| 4646 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4647 | si->appctx.ctx.errors.px = proxy; |
| 4648 | si->appctx.ctx.errors.buf = 0; |
| 4649 | si->appctx.ctx.errors.bol = 0; |
| 4650 | si->appctx.ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4651 | } |
| 4652 | |
| 4653 | /* we have two inner loops here, one for the proxy, the other one for |
| 4654 | * the buffer. |
| 4655 | */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4656 | while (si->appctx.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4657 | struct error_snapshot *es; |
| 4658 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4659 | if (si->appctx.ctx.errors.buf == 0) |
| 4660 | es = &si->appctx.ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4661 | else |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4662 | es = &si->appctx.ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4663 | |
| 4664 | if (!es->when.tv_sec) |
| 4665 | goto next; |
| 4666 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4667 | if (si->appctx.ctx.errors.iid >= 0 && |
| 4668 | si->appctx.ctx.errors.px->uuid != si->appctx.ctx.errors.iid && |
| 4669 | es->oe->uuid != si->appctx.ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4670 | goto next; |
| 4671 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4672 | if (si->appctx.ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4673 | /* just print headers now */ |
| 4674 | |
| 4675 | char pn[INET6_ADDRSTRLEN]; |
| 4676 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4677 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4678 | |
| 4679 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4680 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4681 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4682 | 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] | 4683 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4684 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 4685 | case AF_INET: |
| 4686 | case AF_INET6: |
| 4687 | port = get_host_port(&es->src); |
| 4688 | break; |
| 4689 | default: |
| 4690 | port = 0; |
| 4691 | } |
| 4692 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4693 | switch (si->appctx.ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4694 | case 0: |
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 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4697 | " backend %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->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 4700 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4701 | break; |
| 4702 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4703 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4704 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4705 | " frontend %s (#%d)", |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4706 | si->appctx.ctx.errors.px->id, si->appctx.ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4707 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4708 | break; |
| 4709 | } |
| 4710 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4711 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4712 | ", server %s (#%d), event #%u\n" |
| 4713 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 4714 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 4715 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 4716 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 4717 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 4718 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 4719 | es->ev_id, |
| 4720 | pn, port, es->sid, es->s_flags, |
| 4721 | es->state, es->m_flags, es->t_flags, |
| 4722 | es->m_clen, es->m_blen, |
| 4723 | es->b_flags, es->b_out, es->b_tot, |
| 4724 | es->len, es->b_wrap, es->pos); |
| 4725 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4726 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4727 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4728 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4729 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4730 | si->appctx.ctx.errors.ptr = 0; |
| 4731 | si->appctx.ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4732 | } |
| 4733 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4734 | if (si->appctx.ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4735 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4736 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4737 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4738 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4739 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4740 | goto next; |
| 4741 | } |
| 4742 | |
| 4743 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4744 | 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] | 4745 | int newptr; |
| 4746 | int newline; |
| 4747 | |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4748 | newline = si->appctx.ctx.errors.bol; |
| 4749 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, si->appctx.ctx.errors.ptr); |
| 4750 | if (newptr == si->appctx.ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4751 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4752 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4753 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4754 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4755 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4756 | } |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4757 | si->appctx.ctx.errors.ptr = newptr; |
| 4758 | si->appctx.ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4759 | }; |
| 4760 | next: |
Willy Tarreau | 9b6c2c7 | 2013-11-24 09:38:33 +0100 | [diff] [blame] | 4761 | si->appctx.ctx.errors.bol = 0; |
| 4762 | si->appctx.ctx.errors.ptr = -1; |
| 4763 | si->appctx.ctx.errors.buf++; |
| 4764 | if (si->appctx.ctx.errors.buf > 1) { |
| 4765 | si->appctx.ctx.errors.buf = 0; |
| 4766 | si->appctx.ctx.errors.px = si->appctx.ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4767 | } |
| 4768 | } |
| 4769 | |
| 4770 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4771 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4772 | } |
| 4773 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4774 | /* parse the "level" argument on the bind lines */ |
| 4775 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 4776 | { |
| 4777 | if (!*args[cur_arg + 1]) { |
| 4778 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 4779 | return ERR_ALERT | ERR_FATAL; |
| 4780 | } |
| 4781 | |
| 4782 | if (!strcmp(args[cur_arg+1], "user")) |
| 4783 | conf->level = ACCESS_LVL_USER; |
| 4784 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 4785 | conf->level = ACCESS_LVL_OPER; |
| 4786 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 4787 | conf->level = ACCESS_LVL_ADMIN; |
| 4788 | else { |
| 4789 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 4790 | args[cur_arg], args[cur_arg+1]); |
| 4791 | return ERR_ALERT | ERR_FATAL; |
| 4792 | } |
| 4793 | |
| 4794 | return 0; |
| 4795 | } |
| 4796 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4797 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4798 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4799 | .name = "<STATS>", /* used for logging */ |
| 4800 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 4801 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4802 | }; |
| 4803 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4804 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4805 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4806 | .name = "<CLI>", /* used for logging */ |
| 4807 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4808 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4809 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4810 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 4811 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4812 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 4813 | { 0, NULL, NULL }, |
| 4814 | }}; |
| 4815 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4816 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 4817 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 4818 | { NULL, NULL, 0 }, |
| 4819 | }}; |
| 4820 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4821 | __attribute__((constructor)) |
| 4822 | static void __dumpstats_module_init(void) |
| 4823 | { |
| 4824 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4825 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4826 | } |
| 4827 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4828 | /* |
| 4829 | * Local variables: |
| 4830 | * c-indent-level: 8 |
| 4831 | * c-basic-offset: 8 |
| 4832 | * End: |
| 4833 | */ |