Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 2 | * Functions dedicated to statistics output and the stats socket |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 27 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 28 | #include <common/compat.h> |
| 29 | #include <common/config.h> |
| 30 | #include <common/debug.h> |
| 31 | #include <common/memory.h> |
| 32 | #include <common/mini-clist.h> |
| 33 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 34 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 35 | #include <common/time.h> |
| 36 | #include <common/uri_auth.h> |
| 37 | #include <common/version.h> |
| 38 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | |
| 41 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 42 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 43 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 44 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 45 | #include <proto/dumpstats.h> |
| 46 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 47 | #include <proto/freq_ctr.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 48 | #include <proto/log.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 49 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 50 | #include <proto/listener.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 51 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 52 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 53 | #include <proto/proxy.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 54 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 55 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 56 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 57 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 58 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 59 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 60 | #ifdef USE_OPENSSL |
| 61 | #include <proto/ssl_sock.h> |
| 62 | #endif |
| 63 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 64 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 65 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 66 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 67 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 68 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 69 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 70 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 71 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 72 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 73 | * cli_io_handler() |
| 74 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 75 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 76 | * -> stats_dump_info_to_buffer() // "show info" |
| 77 | * -> stats_dump_stat_to_buffer() // "show stat" |
| 78 | * -> stats_dump_csv_header() |
| 79 | * -> stats_dump_proxy_to_buffer() |
| 80 | * -> stats_dump_fe_stats() |
| 81 | * -> stats_dump_li_stats() |
| 82 | * -> stats_dump_sv_stats() |
| 83 | * -> stats_dump_be_stats() |
| 84 | * |
| 85 | * http_stats_io_handler() |
| 86 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 87 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 88 | * -> stats_dump_html_head() // emits the HTML headers |
| 89 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 90 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 91 | * -> stats_dump_html_px_hdr() |
| 92 | * -> stats_dump_fe_stats() |
| 93 | * -> stats_dump_li_stats() |
| 94 | * -> stats_dump_sv_stats() |
| 95 | * -> stats_dump_be_stats() |
| 96 | * -> stats_dump_html_px_end() |
| 97 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 98 | */ |
| 99 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 100 | static struct si_applet cli_applet; |
| 101 | |
| 102 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 103 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 104 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 105 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 106 | " help : this message\n" |
| 107 | " prompt : toggle interactive mode with prompt\n" |
| 108 | " quit : disconnect\n" |
| 109 | " show info : report information about the running process\n" |
| 110 | " show stat : report counters for each proxy and server\n" |
| 111 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 112 | " show sess [id] : report the list of current sessions or dump this session\n" |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 113 | " show table [id]: report table usage stats or dump this table's contents\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 114 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 115 | " set weight : change a server's weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 116 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 117 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 118 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 119 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 120 | " disable : put a server or frontend in maintenance mode\n" |
| 121 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 122 | " shutdown : kill a session or a frontend (eg:to release listening ports)\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 123 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 124 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 125 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 126 | "Permission denied\n" |
| 127 | ""; |
| 128 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 129 | /* data transmission states for the stats responses */ |
| 130 | enum { |
| 131 | STAT_ST_INIT = 0, |
| 132 | STAT_ST_HEAD, |
| 133 | STAT_ST_INFO, |
| 134 | STAT_ST_LIST, |
| 135 | STAT_ST_END, |
| 136 | STAT_ST_FIN, |
| 137 | }; |
| 138 | |
| 139 | /* data transmission states for the stats responses inside a proxy */ |
| 140 | enum { |
| 141 | STAT_PX_ST_INIT = 0, |
| 142 | STAT_PX_ST_TH, |
| 143 | STAT_PX_ST_FE, |
| 144 | STAT_PX_ST_LI, |
| 145 | STAT_PX_ST_SV, |
| 146 | STAT_PX_ST_BE, |
| 147 | STAT_PX_ST_END, |
| 148 | STAT_PX_ST_FIN, |
| 149 | }; |
| 150 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 151 | extern const char *stat_status_codes[]; |
| 152 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 153 | /* This function is called from the session-level accept() in order to instanciate |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 154 | * a new stats socket. It returns a positive value upon success, 0 if the connection |
| 155 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 156 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 157 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 158 | { |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 159 | /* we have a dedicated I/O handler for the stats */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 160 | stream_int_register_handler(&s->si[1], &cli_applet); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 161 | s->target = s->si[1].conn->target; // for logging only |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 162 | s->si[1].conn->xprt_ctx = s; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 163 | s->si[1].applet.st1 = 0; |
| 164 | s->si[1].applet.st0 = STAT_CLI_INIT; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 165 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 166 | tv_zero(&s->logs.tv_request); |
| 167 | s->logs.t_queue = 0; |
| 168 | s->logs.t_connect = 0; |
| 169 | s->logs.t_data = 0; |
| 170 | s->logs.t_close = 0; |
| 171 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 172 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 173 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 174 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 175 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 176 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 177 | if (s->listener->timeout) { |
| 178 | s->req->rto = *s->listener->timeout; |
| 179 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 180 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 181 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 182 | } |
| 183 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 184 | /* allocate a new stats frontend named <name>, and return it |
| 185 | * (or NULL in case of lack of memory). |
| 186 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 187 | 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] | 188 | { |
| 189 | struct proxy *fe; |
| 190 | |
| 191 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 192 | if (!fe) |
| 193 | return NULL; |
| 194 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 195 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 196 | fe->next = proxy; |
| 197 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 198 | fe->last_change = now.tv_sec; |
| 199 | fe->id = strdup("GLOBAL"); |
| 200 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 201 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 202 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 203 | fe->conf.file = strdup(file); |
| 204 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 205 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 206 | |
| 207 | /* the stats frontend is the only one able to assign ID #0 */ |
| 208 | fe->conf.id.key = fe->uuid = 0; |
| 209 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 210 | return fe; |
| 211 | } |
| 212 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 213 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 214 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 215 | * error message into the <err> buffer which will be preallocated. The trailing |
| 216 | * '\n' must not be written. The function must be called with <args> pointing to |
| 217 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 218 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 219 | 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] | 220 | struct proxy *defpx, const char *file, int line, |
| 221 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 222 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 223 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 224 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 225 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 226 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 227 | int cur_arg; |
| 228 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 229 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 230 | 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] | 231 | return -1; |
| 232 | } |
| 233 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 234 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 235 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 236 | 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] | 237 | return -1; |
| 238 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 239 | } |
| 240 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 241 | 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] | 242 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 243 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 244 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 245 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 246 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 247 | return -1; |
| 248 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 249 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 250 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 251 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 252 | static int bind_dumped; |
| 253 | struct bind_kw *kw; |
| 254 | |
| 255 | kw = bind_find_kw(args[cur_arg]); |
| 256 | if (kw) { |
| 257 | if (!kw->parse) { |
| 258 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 259 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 260 | return -1; |
| 261 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 262 | |
| 263 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 264 | if (err && *err) |
| 265 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 266 | else |
| 267 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 268 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 269 | return -1; |
| 270 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 271 | |
| 272 | cur_arg += 1 + kw->skip; |
| 273 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 274 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 275 | |
| 276 | if (!bind_dumped) { |
| 277 | bind_dump_kws(err); |
| 278 | indent_msg(err, 4); |
| 279 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 280 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 281 | |
| 282 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 283 | args[0], args[1], args[cur_arg], |
| 284 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 285 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 286 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 287 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 288 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 289 | l->maxconn = global.stats_fe->maxconn; |
| 290 | l->backlog = global.stats_fe->backlog; |
| 291 | l->timeout = &global.stats_fe->timeout.client; |
| 292 | l->accept = session_accept; |
| 293 | l->handler = process_session; |
| 294 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 295 | l->nice = -64; /* we want to boost priority for local stats */ |
| 296 | global.maxsock += l->maxconn; |
| 297 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 298 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 299 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 300 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 301 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 302 | |
| 303 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 304 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 305 | return -1; |
| 306 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 307 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 308 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 309 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 310 | return -1; |
| 311 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 312 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 313 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 314 | 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] | 315 | return -1; |
| 316 | } |
| 317 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 318 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 319 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 320 | else if (!strcmp(args[1], "maxconn")) { |
| 321 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 322 | |
| 323 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 324 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 325 | return -1; |
| 326 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 327 | |
| 328 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 329 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 330 | 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] | 331 | return -1; |
| 332 | } |
| 333 | } |
| 334 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 335 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 336 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 337 | int cur_arg = 2; |
| 338 | unsigned int set = 0; |
| 339 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 340 | if (!global.stats_fe) { |
| 341 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 342 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 343 | return -1; |
| 344 | } |
| 345 | } |
| 346 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 347 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 348 | unsigned int low, high; |
| 349 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 350 | if (strcmp(args[cur_arg], "all") == 0) { |
| 351 | set = 0; |
| 352 | break; |
| 353 | } |
| 354 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 355 | set |= 0x55555555; |
| 356 | } |
| 357 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 358 | set |= 0xAAAAAAAA; |
| 359 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 360 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 361 | char *dash = strchr(args[cur_arg], '-'); |
| 362 | |
| 363 | low = high = str2uic(args[cur_arg]); |
| 364 | if (dash) |
| 365 | high = str2uic(dash + 1); |
| 366 | |
| 367 | if (high < low) { |
| 368 | unsigned int swap = low; |
| 369 | low = high; |
| 370 | high = swap; |
| 371 | } |
| 372 | |
| 373 | if (low < 1 || high > 32) { |
| 374 | memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n", |
| 375 | args[0], args[1]); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 376 | return -1; |
| 377 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 378 | |
| 379 | while (low <= high) |
| 380 | set |= 1 << (low++ - 1); |
| 381 | } |
| 382 | else { |
| 383 | memprintf(err, |
| 384 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 385 | args[0], args[1]); |
| 386 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 387 | } |
| 388 | cur_arg++; |
| 389 | } |
| 390 | global.stats_fe->bind_proc = set; |
| 391 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 392 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 393 | 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] | 394 | return -1; |
| 395 | } |
| 396 | return 0; |
| 397 | } |
| 398 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 399 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 400 | * for clearing it if needed. |
| 401 | */ |
| 402 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 403 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 404 | chunk_appendf(&trash, |
| 405 | "# pxname,svname," |
| 406 | "qcur,qmax," |
| 407 | "scur,smax,slim,stot," |
| 408 | "bin,bout," |
| 409 | "dreq,dresp," |
| 410 | "ereq,econ,eresp," |
| 411 | "wretr,wredis," |
| 412 | "status,weight,act,bck," |
| 413 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 414 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 415 | "rate,rate_lim,rate_max," |
| 416 | "check_status,check_code,check_duration," |
| 417 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 418 | "req_rate,req_rate_max,req_tot," |
| 419 | "cli_abrt,srv_abrt," |
| 420 | "comp_in,comp_out,comp_byp,comp_rsp," |
| 421 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 422 | } |
| 423 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 424 | /* print a string of text buffer to <out>. The format is : |
| 425 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 426 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 427 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 428 | */ |
| 429 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 430 | { |
| 431 | unsigned char c; |
| 432 | int ptr = 0; |
| 433 | |
| 434 | while (buf[ptr] && ptr < bsize) { |
| 435 | c = buf[ptr]; |
| 436 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 437 | if (out->len > out->size - 1) |
| 438 | break; |
| 439 | out->str[out->len++] = c; |
| 440 | } |
| 441 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 442 | if (out->len > out->size - 2) |
| 443 | break; |
| 444 | out->str[out->len++] = '\\'; |
| 445 | switch (c) { |
| 446 | case ' ': c = ' '; break; |
| 447 | case '\t': c = 't'; break; |
| 448 | case '\n': c = 'n'; break; |
| 449 | case '\r': c = 'r'; break; |
| 450 | case '\e': c = 'e'; break; |
| 451 | case '\\': c = '\\'; break; |
| 452 | } |
| 453 | out->str[out->len++] = c; |
| 454 | } |
| 455 | else { |
| 456 | if (out->len > out->size - 4) |
| 457 | break; |
| 458 | out->str[out->len++] = '\\'; |
| 459 | out->str[out->len++] = 'x'; |
| 460 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 461 | out->str[out->len++] = hextab[c & 0xF]; |
| 462 | } |
| 463 | ptr++; |
| 464 | } |
| 465 | |
| 466 | return ptr; |
| 467 | } |
| 468 | |
| 469 | /* print a buffer in hexa. |
| 470 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 471 | */ |
| 472 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 473 | { |
| 474 | unsigned char c; |
| 475 | int ptr = 0; |
| 476 | |
| 477 | while (ptr < bsize) { |
| 478 | c = buf[ptr]; |
| 479 | |
| 480 | if (out->len > out->size - 2) |
| 481 | break; |
| 482 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 483 | out->str[out->len++] = hextab[c & 0xF]; |
| 484 | |
| 485 | ptr++; |
| 486 | } |
| 487 | return ptr; |
| 488 | } |
| 489 | |
| 490 | /* Dump the status of a table to a stream interface's |
| 491 | * read buffer. It returns 0 if the output buffer is full |
| 492 | * and needs to be called again, otherwise non-zero. |
| 493 | */ |
| 494 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 495 | struct proxy *proxy, struct proxy *target) |
| 496 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 497 | struct session *s = si->conn->xprt_ctx; |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 498 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 499 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 500 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 501 | |
| 502 | /* any other information should be dumped here */ |
| 503 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 504 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 505 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 506 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 507 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 508 | return 0; |
| 509 | |
| 510 | return 1; |
| 511 | } |
| 512 | |
| 513 | /* Dump the a table entry to a stream interface's |
| 514 | * read buffer. It returns 0 if the output buffer is full |
| 515 | * and needs to be called again, otherwise non-zero. |
| 516 | */ |
| 517 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 518 | struct proxy *proxy, struct stksess *entry) |
| 519 | { |
| 520 | int dt; |
| 521 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 522 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 523 | |
| 524 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 525 | char addr[INET_ADDRSTRLEN]; |
| 526 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 527 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 528 | } |
| 529 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 530 | char addr[INET6_ADDRSTRLEN]; |
| 531 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 532 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 533 | } |
| 534 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 535 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 536 | } |
| 537 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 538 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 539 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 540 | } |
| 541 | else { |
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_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 544 | } |
| 545 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 546 | 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] | 547 | |
| 548 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 549 | void *ptr; |
| 550 | |
| 551 | if (proxy->table.data_ofs[dt] == 0) |
| 552 | continue; |
| 553 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 554 | 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] | 555 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 556 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 557 | |
| 558 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 559 | switch (stktable_data_types[dt].std_type) { |
| 560 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 561 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 562 | break; |
| 563 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 564 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 565 | break; |
| 566 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 567 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 568 | break; |
| 569 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 570 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 571 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 572 | proxy->table.data_arg[dt].u)); |
| 573 | break; |
| 574 | } |
| 575 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 576 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 577 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 578 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 579 | return 0; |
| 580 | |
| 581 | return 1; |
| 582 | } |
| 583 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 584 | 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] | 585 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 586 | struct session *s = si->conn->xprt_ctx; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 587 | struct proxy *px = si->applet.ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 588 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 589 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 590 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 591 | long long value; |
| 592 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 593 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 594 | void *ptr; |
| 595 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 596 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 597 | si->applet.st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 598 | |
| 599 | if (!*args[4]) { |
| 600 | si->applet.ctx.cli.msg = "Key value expected\n"; |
| 601 | si->applet.st0 = STAT_CLI_PRINT; |
| 602 | return; |
| 603 | } |
| 604 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 605 | switch (px->table.type) { |
| 606 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 607 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 608 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 609 | break; |
| 610 | case STKTABLE_TYPE_IPV6: |
| 611 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 612 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 613 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 614 | case STKTABLE_TYPE_INTEGER: |
| 615 | { |
| 616 | char *endptr; |
| 617 | unsigned long val; |
| 618 | errno = 0; |
| 619 | val = strtoul(args[4], &endptr, 10); |
| 620 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 621 | (errno != 0 && val == 0) || endptr == args[4] || |
| 622 | val > 0xffffffff) { |
| 623 | si->applet.ctx.cli.msg = "Invalid key\n"; |
| 624 | si->applet.st0 = STAT_CLI_PRINT; |
| 625 | return; |
| 626 | } |
| 627 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 628 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 629 | break; |
| 630 | } |
| 631 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 632 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 633 | static_table_key->key = args[4]; |
| 634 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 635 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 636 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 637 | switch (action) { |
| 638 | case STAT_CLI_O_TAB: |
| 639 | si->applet.ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n"; |
| 640 | break; |
| 641 | case STAT_CLI_O_CLR: |
| 642 | si->applet.ctx.cli.msg = "Removing keys from ip tables of type other than ip, ipv6, string and integer is not supported\n"; |
| 643 | break; |
| 644 | default: |
| 645 | si->applet.ctx.cli.msg = "Unknown action\n"; |
| 646 | break; |
| 647 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 648 | si->applet.st0 = STAT_CLI_PRINT; |
| 649 | return; |
| 650 | } |
| 651 | |
| 652 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 653 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 654 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 655 | si->applet.st0 = STAT_CLI_PRINT; |
| 656 | return; |
| 657 | } |
| 658 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 659 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 660 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 661 | switch (action) { |
| 662 | case STAT_CLI_O_TAB: |
| 663 | if (!ts) |
| 664 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 665 | chunk_reset(&trash); |
| 666 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 667 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 668 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 669 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 670 | |
| 671 | case STAT_CLI_O_CLR: |
| 672 | if (!ts) |
| 673 | return; |
| 674 | if (ts->ref_cnt) { |
| 675 | /* don't delete an entry which is currently referenced */ |
| 676 | si->applet.ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 677 | si->applet.st0 = STAT_CLI_PRINT; |
| 678 | return; |
| 679 | } |
| 680 | stksess_kill(&px->table, ts); |
| 681 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 682 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 683 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 684 | if (ts) |
| 685 | stktable_touch(&px->table, ts, 1); |
| 686 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 687 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 688 | if (!ts) { |
| 689 | /* don't delete an entry which is currently referenced */ |
| 690 | si->applet.ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 691 | si->applet.st0 = STAT_CLI_PRINT; |
| 692 | return; |
| 693 | } |
| 694 | stktable_store(&px->table, ts, 1); |
| 695 | } |
| 696 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 697 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 698 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
| 699 | si->applet.ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 700 | si->applet.st0 = STAT_CLI_PRINT; |
| 701 | return; |
| 702 | } |
| 703 | |
| 704 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 705 | if (data_type < 0) { |
| 706 | si->applet.ctx.cli.msg = "Unknown data type\n"; |
| 707 | si->applet.st0 = STAT_CLI_PRINT; |
| 708 | return; |
| 709 | } |
| 710 | |
| 711 | if (!px->table.data_ofs[data_type]) { |
| 712 | si->applet.ctx.cli.msg = "Data type not stored in this table\n"; |
| 713 | si->applet.st0 = STAT_CLI_PRINT; |
| 714 | return; |
| 715 | } |
| 716 | |
| 717 | if (!*args[cur_arg+1] || strl2llrc(args[cur_arg+1], strlen(args[cur_arg+1]), &value) != 0) { |
| 718 | si->applet.ctx.cli.msg = "Require a valid integer value to store\n"; |
| 719 | si->applet.st0 = STAT_CLI_PRINT; |
| 720 | return; |
| 721 | } |
| 722 | |
| 723 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 724 | |
| 725 | switch (stktable_data_types[data_type].std_type) { |
| 726 | case STD_T_SINT: |
| 727 | stktable_data_cast(ptr, std_t_sint) = value; |
| 728 | break; |
| 729 | case STD_T_UINT: |
| 730 | stktable_data_cast(ptr, std_t_uint) = value; |
| 731 | break; |
| 732 | case STD_T_ULL: |
| 733 | stktable_data_cast(ptr, std_t_ull) = value; |
| 734 | break; |
| 735 | case STD_T_FRQP: |
| 736 | /* We set both the current and previous values. That way |
| 737 | * the reported frequency is stable during all the period |
| 738 | * then slowly fades out. This allows external tools to |
| 739 | * push measures without having to update them too often. |
| 740 | */ |
| 741 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 742 | frqp->curr_tick = now_ms; |
| 743 | frqp->prev_ctr = 0; |
| 744 | frqp->curr_ctr = value; |
| 745 | break; |
| 746 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 747 | } |
| 748 | break; |
| 749 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 750 | default: |
| 751 | si->applet.ctx.cli.msg = "Unknown action\n"; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 752 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 753 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 754 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 755 | } |
| 756 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 757 | 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] | 758 | { |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 759 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
| 760 | si->applet.ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 761 | si->applet.st0 = STAT_CLI_PRINT; |
| 762 | return; |
| 763 | } |
| 764 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 765 | /* condition on stored data value */ |
| 766 | si->applet.ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 767 | if (si->applet.ctx.table.data_type < 0) { |
| 768 | si->applet.ctx.cli.msg = "Unknown data type\n"; |
| 769 | si->applet.st0 = STAT_CLI_PRINT; |
| 770 | return; |
| 771 | } |
| 772 | |
| 773 | if (!((struct proxy *)si->applet.ctx.table.target)->table.data_ofs[si->applet.ctx.table.data_type]) { |
| 774 | si->applet.ctx.cli.msg = "Data type not stored in this table\n"; |
| 775 | si->applet.st0 = STAT_CLI_PRINT; |
| 776 | return; |
| 777 | } |
| 778 | |
| 779 | si->applet.ctx.table.data_op = get_std_op(args[4]); |
| 780 | if (si->applet.ctx.table.data_op < 0) { |
| 781 | si->applet.ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 782 | si->applet.st0 = STAT_CLI_PRINT; |
| 783 | return; |
| 784 | } |
| 785 | |
| 786 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &si->applet.ctx.table.value) != 0) { |
| 787 | si->applet.ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 788 | si->applet.st0 = STAT_CLI_PRINT; |
| 789 | return; |
| 790 | } |
| 791 | } |
| 792 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 793 | 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] | 794 | { |
| 795 | si->applet.ctx.table.data_type = -1; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 796 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | e17a8d0 | 2011-08-24 08:23:34 +0200 | [diff] [blame] | 797 | si->applet.ctx.table.target = NULL; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 798 | si->applet.ctx.table.proxy = NULL; |
| 799 | si->applet.ctx.table.entry = NULL; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 800 | si->applet.st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 801 | |
| 802 | if (*args[2]) { |
| 803 | si->applet.ctx.table.target = find_stktable(args[2]); |
| 804 | if (!si->applet.ctx.table.target) { |
| 805 | si->applet.ctx.cli.msg = "No such table\n"; |
| 806 | si->applet.st0 = STAT_CLI_PRINT; |
| 807 | return; |
| 808 | } |
| 809 | } |
| 810 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 811 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 812 | goto err_args; |
| 813 | return; |
| 814 | } |
| 815 | |
| 816 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 817 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 818 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 819 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 820 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 821 | goto err_args; |
| 822 | |
| 823 | return; |
| 824 | |
| 825 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 826 | switch (action) { |
| 827 | case STAT_CLI_O_TAB: |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 828 | si->applet.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] | 829 | break; |
| 830 | case STAT_CLI_O_CLR: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 831 | si->applet.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] | 832 | break; |
| 833 | default: |
| 834 | si->applet.ctx.cli.msg = "Unknown action\n"; |
| 835 | break; |
| 836 | } |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 837 | si->applet.st0 = STAT_CLI_PRINT; |
| 838 | } |
| 839 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 840 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 841 | * adequate error messages and returns NULL. This function also expects the session |
| 842 | * level to be admin. |
| 843 | */ |
| 844 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 845 | { |
| 846 | struct proxy *px; |
| 847 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 848 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 849 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 850 | si->applet.st0 = STAT_CLI_PRINT; |
| 851 | return NULL; |
| 852 | } |
| 853 | |
| 854 | if (!*arg) { |
| 855 | si->applet.ctx.cli.msg = "A frontend name is expected.\n"; |
| 856 | si->applet.st0 = STAT_CLI_PRINT; |
| 857 | return NULL; |
| 858 | } |
| 859 | |
| 860 | px = findproxy(arg, PR_CAP_FE); |
| 861 | if (!px) { |
| 862 | si->applet.ctx.cli.msg = "No such frontend.\n"; |
| 863 | si->applet.st0 = STAT_CLI_PRINT; |
| 864 | return NULL; |
| 865 | } |
| 866 | return px; |
| 867 | } |
| 868 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 869 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 870 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 871 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 872 | * the <arg> is modified to remove the '/'. |
| 873 | */ |
| 874 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 875 | { |
| 876 | struct proxy *px; |
| 877 | struct server *sv; |
| 878 | char *line; |
| 879 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 880 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 881 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 882 | si->applet.st0 = STAT_CLI_PRINT; |
| 883 | return NULL; |
| 884 | } |
| 885 | |
| 886 | /* split "backend/server" and make <line> point to server */ |
| 887 | for (line = arg; *line; line++) |
| 888 | if (*line == '/') { |
| 889 | *line++ = '\0'; |
| 890 | break; |
| 891 | } |
| 892 | |
| 893 | if (!*line || !*arg) { |
| 894 | si->applet.ctx.cli.msg = "Require 'backend/server'.\n"; |
| 895 | si->applet.st0 = STAT_CLI_PRINT; |
| 896 | return NULL; |
| 897 | } |
| 898 | |
| 899 | if (!get_backend_server(arg, line, &px, &sv)) { |
| 900 | si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 901 | si->applet.st0 = STAT_CLI_PRINT; |
| 902 | return NULL; |
| 903 | } |
| 904 | |
| 905 | if (px->state == PR_STSTOPPED) { |
| 906 | si->applet.ctx.cli.msg = "Proxy is disabled.\n"; |
| 907 | si->applet.st0 = STAT_CLI_PRINT; |
| 908 | return NULL; |
| 909 | } |
| 910 | |
| 911 | return sv; |
| 912 | } |
| 913 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 914 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 915 | * called from an applet running in a stream interface. The function returns 1 |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 916 | * if the request was understood, otherwise zero. It sets si->applet.st0 to a value |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 917 | * designating the function which will have to process the request, which can |
| 918 | * 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] | 919 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 920 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 921 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 922 | struct session *s = si->conn->xprt_ctx; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 923 | char *args[MAX_STATS_ARGS + 1]; |
| 924 | int arg; |
| 925 | |
| 926 | while (isspace((unsigned char)*line)) |
| 927 | line++; |
| 928 | |
| 929 | arg = 0; |
| 930 | args[arg] = line; |
| 931 | |
| 932 | while (*line && arg < MAX_STATS_ARGS) { |
| 933 | if (isspace((unsigned char)*line)) { |
| 934 | *line++ = '\0'; |
| 935 | |
| 936 | while (isspace((unsigned char)*line)) |
| 937 | line++; |
| 938 | |
| 939 | args[++arg] = line; |
| 940 | continue; |
| 941 | } |
| 942 | |
| 943 | line++; |
| 944 | } |
| 945 | |
| 946 | while (++arg <= MAX_STATS_ARGS) |
| 947 | args[arg] = line; |
| 948 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 949 | si->applet.ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 950 | if (strcmp(args[0], "show") == 0) { |
| 951 | if (strcmp(args[1], "stat") == 0) { |
| 952 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 953 | si->applet.ctx.stats.flags |= STAT_BOUND; |
| 954 | si->applet.ctx.stats.iid = atoi(args[2]); |
| 955 | si->applet.ctx.stats.type = atoi(args[3]); |
| 956 | si->applet.ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 957 | } |
| 958 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 959 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 960 | si->applet.st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 961 | } |
| 962 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 963 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 964 | si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 965 | } |
| 966 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 967 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 968 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 969 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 970 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 971 | return 1; |
| 972 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 973 | if (*args[2] && strcmp(args[2], "all") == 0) |
| 974 | si->applet.ctx.sess.target = (void *)-1; |
| 975 | else if (*args[2]) |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 976 | si->applet.ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 977 | else |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 978 | si->applet.ctx.sess.target = NULL; |
| 979 | si->applet.ctx.sess.section = 0; /* start with session status */ |
| 980 | si->applet.ctx.sess.pos = 0; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 981 | si->applet.st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 982 | } |
| 983 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 984 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 985 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 986 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 987 | return 1; |
| 988 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 989 | if (*args[2]) |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 990 | si->applet.ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 991 | else |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 992 | si->applet.ctx.errors.iid = -1; |
| 993 | si->applet.ctx.errors.px = NULL; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 994 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 995 | si->applet.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 996 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 997 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 998 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 999 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1000 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1001 | return 0; |
| 1002 | } |
| 1003 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1004 | else if (strcmp(args[0], "clear") == 0) { |
| 1005 | if (strcmp(args[1], "counters") == 0) { |
| 1006 | struct proxy *px; |
| 1007 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1008 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1009 | int clrall = 0; |
| 1010 | |
| 1011 | if (strcmp(args[2], "all") == 0) |
| 1012 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1013 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1014 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1015 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1016 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1017 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1018 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1019 | return 1; |
| 1020 | } |
| 1021 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1022 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1023 | if (clrall) { |
| 1024 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1025 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1026 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1027 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1028 | px->be_counters.conn_max = 0; |
| 1029 | px->be_counters.p.http.rps_max = 0; |
| 1030 | px->be_counters.sps_max = 0; |
| 1031 | px->be_counters.cps_max = 0; |
| 1032 | px->be_counters.nbpend_max = 0; |
| 1033 | |
| 1034 | px->fe_counters.conn_max = 0; |
| 1035 | px->fe_counters.p.http.rps_max = 0; |
| 1036 | px->fe_counters.sps_max = 0; |
| 1037 | px->fe_counters.cps_max = 0; |
| 1038 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1039 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1040 | |
| 1041 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1042 | if (clrall) |
| 1043 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1044 | else { |
| 1045 | sv->counters.cur_sess_max = 0; |
| 1046 | sv->counters.nbpend_max = 0; |
| 1047 | sv->counters.sps_max = 0; |
| 1048 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1049 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1050 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1051 | if (li->counters) { |
| 1052 | if (clrall) |
| 1053 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1054 | else |
| 1055 | li->counters->conn_max = 0; |
| 1056 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1057 | } |
| 1058 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1059 | global.cps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1060 | return 1; |
| 1061 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1062 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1063 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1064 | /* end of processing */ |
| 1065 | return 1; |
| 1066 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1067 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1068 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1069 | return 0; |
| 1070 | } |
| 1071 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1072 | else if (strcmp(args[0], "get") == 0) { |
| 1073 | if (strcmp(args[1], "weight") == 0) { |
| 1074 | struct proxy *px; |
| 1075 | struct server *sv; |
| 1076 | |
| 1077 | /* split "backend/server" and make <line> point to server */ |
| 1078 | for (line = args[2]; *line; line++) |
| 1079 | if (*line == '/') { |
| 1080 | *line++ = '\0'; |
| 1081 | break; |
| 1082 | } |
| 1083 | |
| 1084 | if (!*line) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1085 | si->applet.ctx.cli.msg = "Require 'backend/server'.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1086 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1087 | return 1; |
| 1088 | } |
| 1089 | |
| 1090 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1091 | si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1092 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1093 | return 1; |
| 1094 | } |
| 1095 | |
| 1096 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1097 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1098 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1099 | return 1; |
| 1100 | } |
| 1101 | else { /* not "get weight" */ |
| 1102 | return 0; |
| 1103 | } |
| 1104 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1105 | else if (strcmp(args[0], "set") == 0) { |
| 1106 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1107 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1108 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1109 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1110 | sv = expect_server_admin(s, si, args[2]); |
| 1111 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1112 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1113 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1114 | warning = server_parse_weight_change_request(sv, args[3]); |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 1115 | /* |
| 1116 | * The user-weight may now be zero and thus |
| 1117 | * the server considered to be draining. |
| 1118 | * Update the server's drain state as necessary. |
| 1119 | */ |
| 1120 | set_server_drain_state(sv); |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1121 | if (warning) { |
| 1122 | si->applet.ctx.cli.msg = warning; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1123 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1124 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1125 | return 1; |
| 1126 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1127 | else if (strcmp(args[1], "timeout") == 0) { |
| 1128 | if (strcmp(args[2], "cli") == 0) { |
| 1129 | unsigned timeout; |
| 1130 | const char *res; |
| 1131 | |
| 1132 | if (!*args[3]) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1133 | si->applet.ctx.cli.msg = "Expects an integer value.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1134 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1135 | return 1; |
| 1136 | } |
| 1137 | |
| 1138 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1139 | if (res || timeout < 1) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1140 | si->applet.ctx.cli.msg = "Invalid timeout value.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1141 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1142 | return 1; |
| 1143 | } |
| 1144 | |
| 1145 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1146 | return 1; |
| 1147 | } |
| 1148 | else { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1149 | si->applet.ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1150 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1151 | return 1; |
| 1152 | } |
| 1153 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1154 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1155 | if (strcmp(args[2], "frontend") == 0) { |
| 1156 | struct proxy *px; |
| 1157 | struct listener *l; |
| 1158 | int v; |
| 1159 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1160 | px = expect_frontend_admin(s, si, args[3]); |
| 1161 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1162 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1163 | |
| 1164 | if (!*args[4]) { |
| 1165 | si->applet.ctx.cli.msg = "Integer value expected.\n"; |
| 1166 | si->applet.st0 = STAT_CLI_PRINT; |
| 1167 | return 1; |
| 1168 | } |
| 1169 | |
| 1170 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1171 | if (v < 0) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1172 | si->applet.ctx.cli.msg = "Value out of range.\n"; |
| 1173 | si->applet.st0 = STAT_CLI_PRINT; |
| 1174 | return 1; |
| 1175 | } |
| 1176 | |
| 1177 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1178 | * its listeners. The blocked ones will be dequeued. |
| 1179 | */ |
| 1180 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1181 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1182 | l->maxconn = v; |
| 1183 | if (l->state == LI_FULL) |
| 1184 | resume_listener(l); |
| 1185 | } |
| 1186 | |
| 1187 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1188 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1189 | |
| 1190 | return 1; |
| 1191 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1192 | else if (strcmp(args[2], "global") == 0) { |
| 1193 | int v; |
| 1194 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1195 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1196 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 1197 | si->applet.st0 = STAT_CLI_PRINT; |
| 1198 | return 1; |
| 1199 | } |
| 1200 | |
| 1201 | if (!*args[3]) { |
| 1202 | si->applet.ctx.cli.msg = "Expects an integer value.\n"; |
| 1203 | si->applet.st0 = STAT_CLI_PRINT; |
| 1204 | return 1; |
| 1205 | } |
| 1206 | |
| 1207 | v = atoi(args[3]); |
| 1208 | if (v > global.hardmaxconn) { |
| 1209 | si->applet.ctx.cli.msg = "Value out of range.\n"; |
| 1210 | si->applet.st0 = STAT_CLI_PRINT; |
| 1211 | return 1; |
| 1212 | } |
| 1213 | |
| 1214 | /* check for unlimited values */ |
| 1215 | if (v <= 0) |
| 1216 | v = global.hardmaxconn; |
| 1217 | |
| 1218 | global.maxconn = v; |
| 1219 | |
| 1220 | /* Dequeues all of the listeners waiting for a resource */ |
| 1221 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1222 | dequeue_all_listeners(&global_listener_queue); |
| 1223 | |
| 1224 | return 1; |
| 1225 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1226 | else { |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1227 | si->applet.ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n"; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1228 | si->applet.st0 = STAT_CLI_PRINT; |
| 1229 | return 1; |
| 1230 | } |
| 1231 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1232 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1233 | if (strcmp(args[2], "connections") == 0) { |
| 1234 | if (strcmp(args[3], "global") == 0) { |
| 1235 | int v; |
| 1236 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1237 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1238 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 1239 | si->applet.st0 = STAT_CLI_PRINT; |
| 1240 | return 1; |
| 1241 | } |
| 1242 | |
| 1243 | if (!*args[4]) { |
| 1244 | si->applet.ctx.cli.msg = "Expects an integer value.\n"; |
| 1245 | si->applet.st0 = STAT_CLI_PRINT; |
| 1246 | return 1; |
| 1247 | } |
| 1248 | |
| 1249 | v = atoi(args[4]); |
| 1250 | if (v < 0) { |
| 1251 | si->applet.ctx.cli.msg = "Value out of range.\n"; |
| 1252 | si->applet.st0 = STAT_CLI_PRINT; |
| 1253 | return 1; |
| 1254 | } |
| 1255 | |
| 1256 | global.cps_lim = v; |
| 1257 | |
| 1258 | /* Dequeues all of the listeners waiting for a resource */ |
| 1259 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1260 | dequeue_all_listeners(&global_listener_queue); |
| 1261 | |
| 1262 | return 1; |
| 1263 | } |
| 1264 | else { |
| 1265 | si->applet.ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1266 | si->applet.st0 = STAT_CLI_PRINT; |
| 1267 | return 1; |
| 1268 | } |
| 1269 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1270 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1271 | if (strcmp(args[3], "global") == 0) { |
| 1272 | int v; |
| 1273 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1274 | if (!*args[4]) { |
| 1275 | si->applet.ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1276 | si->applet.st0 = STAT_CLI_PRINT; |
| 1277 | return 1; |
| 1278 | } |
| 1279 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1280 | v = atoi(args[4]); |
| 1281 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1282 | } |
| 1283 | else { |
| 1284 | si->applet.ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1285 | si->applet.st0 = STAT_CLI_PRINT; |
| 1286 | return 1; |
| 1287 | } |
| 1288 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1289 | else { |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1290 | si->applet.ctx.cli.msg = "'set rate-limit' supports 'connections' and 'http-compression'.\n"; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1291 | si->applet.st0 = STAT_CLI_PRINT; |
| 1292 | return 1; |
| 1293 | } |
| 1294 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1295 | else if (strcmp(args[1], "table") == 0) { |
| 1296 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1297 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1298 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1299 | return 0; |
| 1300 | } |
| 1301 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1302 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1303 | if (strcmp(args[1], "agent") == 0) { |
| 1304 | struct server *sv; |
| 1305 | |
| 1306 | sv = expect_server_admin(s, si, args[2]); |
| 1307 | if (!sv) |
| 1308 | return 1; |
| 1309 | |
| 1310 | sv->agent.state &= ~CHK_STATE_DISABLED; |
| 1311 | |
| 1312 | return 1; |
| 1313 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1314 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1315 | struct server *sv; |
| 1316 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1317 | sv = expect_server_admin(s, si, args[2]); |
| 1318 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1319 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1320 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1321 | if (sv->state & SRV_MAINTAIN) { |
| 1322 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1323 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1324 | /* If this server tracks the status of another one, |
| 1325 | * we must restore the good status. |
| 1326 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1327 | if (sv->track->state & SRV_RUNNING) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1328 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1329 | 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] | 1330 | } else { |
| 1331 | sv->state &= ~SRV_MAINTAIN; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1332 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1333 | } |
| 1334 | } else { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1335 | set_server_up(&sv->check); |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 1336 | 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] | 1337 | } |
| 1338 | } |
| 1339 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1340 | return 1; |
| 1341 | } |
| 1342 | else if (strcmp(args[1], "frontend") == 0) { |
| 1343 | struct proxy *px; |
| 1344 | |
| 1345 | px = expect_frontend_admin(s, si, args[2]); |
| 1346 | if (!px) |
| 1347 | return 1; |
| 1348 | |
| 1349 | if (px->state == PR_STSTOPPED) { |
| 1350 | si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1351 | si->applet.st0 = STAT_CLI_PRINT; |
| 1352 | return 1; |
| 1353 | } |
| 1354 | |
| 1355 | if (px->state != PR_STPAUSED) { |
| 1356 | si->applet.ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1357 | si->applet.st0 = STAT_CLI_PRINT; |
| 1358 | return 1; |
| 1359 | } |
| 1360 | |
| 1361 | if (!resume_proxy(px)) { |
| 1362 | si->applet.ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1363 | si->applet.st0 = STAT_CLI_PRINT; |
| 1364 | return 1; |
| 1365 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1366 | return 1; |
| 1367 | } |
| 1368 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1369 | si->applet.ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1370 | si->applet.st0 = STAT_CLI_PRINT; |
| 1371 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1372 | } |
| 1373 | } |
| 1374 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 1375 | if (strcmp(args[1], "agent") == 0) { |
| 1376 | struct server *sv; |
| 1377 | |
| 1378 | sv = expect_server_admin(s, si, args[2]); |
| 1379 | if (!sv) |
| 1380 | return 1; |
| 1381 | |
| 1382 | sv->agent.state |= CHK_STATE_DISABLED; |
| 1383 | |
| 1384 | return 1; |
| 1385 | } |
| 1386 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1387 | struct server *sv; |
| 1388 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1389 | sv = expect_server_admin(s, si, args[2]); |
| 1390 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1391 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1392 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1393 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1394 | /* Not already in maintenance, we can change the server state */ |
| 1395 | sv->state |= SRV_MAINTAIN; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 1396 | set_server_down(&sv->check); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1397 | } |
| 1398 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1399 | return 1; |
| 1400 | } |
| 1401 | else if (strcmp(args[1], "frontend") == 0) { |
| 1402 | struct proxy *px; |
| 1403 | |
| 1404 | px = expect_frontend_admin(s, si, args[2]); |
| 1405 | if (!px) |
| 1406 | return 1; |
| 1407 | |
| 1408 | if (px->state == PR_STSTOPPED) { |
| 1409 | si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1410 | si->applet.st0 = STAT_CLI_PRINT; |
| 1411 | return 1; |
| 1412 | } |
| 1413 | |
| 1414 | if (px->state == PR_STPAUSED) { |
| 1415 | si->applet.ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1416 | si->applet.st0 = STAT_CLI_PRINT; |
| 1417 | return 1; |
| 1418 | } |
| 1419 | |
| 1420 | if (!pause_proxy(px)) { |
| 1421 | si->applet.ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1422 | si->applet.st0 = STAT_CLI_PRINT; |
| 1423 | return 1; |
| 1424 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1425 | return 1; |
| 1426 | } |
| 1427 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1428 | si->applet.ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1429 | si->applet.st0 = STAT_CLI_PRINT; |
| 1430 | return 1; |
| 1431 | } |
| 1432 | } |
| 1433 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1434 | if (strcmp(args[1], "frontend") == 0) { |
| 1435 | struct proxy *px; |
| 1436 | |
| 1437 | px = expect_frontend_admin(s, si, args[2]); |
| 1438 | if (!px) |
| 1439 | return 1; |
| 1440 | |
| 1441 | if (px->state == PR_STSTOPPED) { |
| 1442 | si->applet.ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1443 | si->applet.st0 = STAT_CLI_PRINT; |
| 1444 | return 1; |
| 1445 | } |
| 1446 | |
| 1447 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1448 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1449 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1450 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1451 | stop_proxy(px); |
| 1452 | return 1; |
| 1453 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1454 | else if (strcmp(args[1], "session") == 0) { |
| 1455 | struct session *sess, *ptr; |
| 1456 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1457 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1458 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 1459 | si->applet.st0 = STAT_CLI_PRINT; |
| 1460 | return 1; |
| 1461 | } |
| 1462 | |
| 1463 | if (!*args[2]) { |
| 1464 | si->applet.ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1465 | si->applet.st0 = STAT_CLI_PRINT; |
| 1466 | return 1; |
| 1467 | } |
| 1468 | |
| 1469 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1470 | |
| 1471 | /* first, look for the requested session in the session table */ |
| 1472 | list_for_each_entry(sess, &sessions, list) { |
| 1473 | if (sess == ptr) |
| 1474 | break; |
| 1475 | } |
| 1476 | |
| 1477 | /* do we have the session ? */ |
| 1478 | if (sess != ptr) { |
| 1479 | si->applet.ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1480 | si->applet.st0 = STAT_CLI_PRINT; |
| 1481 | return 1; |
| 1482 | } |
| 1483 | |
| 1484 | session_shutdown(sess, SN_ERR_KILLED); |
| 1485 | return 1; |
| 1486 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1487 | else if (strcmp(args[1], "sessions") == 0) { |
| 1488 | if (strcmp(args[2], "server") == 0) { |
| 1489 | struct server *sv; |
| 1490 | struct session *sess, *sess_bck; |
| 1491 | |
| 1492 | sv = expect_server_admin(s, si, args[3]); |
| 1493 | if (!sv) |
| 1494 | return 1; |
| 1495 | |
| 1496 | /* kill all the session that are on this server */ |
| 1497 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1498 | if (sess->srv_conn == sv) |
| 1499 | session_shutdown(sess, SN_ERR_KILLED); |
| 1500 | |
| 1501 | return 1; |
| 1502 | } |
| 1503 | else { |
| 1504 | si->applet.ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1505 | si->applet.st0 = STAT_CLI_PRINT; |
| 1506 | return 1; |
| 1507 | } |
| 1508 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1509 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1510 | si->applet.ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1511 | si->applet.st0 = STAT_CLI_PRINT; |
| 1512 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1513 | } |
| 1514 | } |
| 1515 | 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] | 1516 | return 0; |
| 1517 | } |
| 1518 | return 1; |
| 1519 | } |
| 1520 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1521 | /* 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] | 1522 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 1523 | * state machine handling requests and various responses. We read a request, |
| 1524 | * then we process it and send the response, and we possibly display a prompt. |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1525 | * Then we can read again. The state is stored in si->applet.st0 and is one of the |
| 1526 | * STAT_CLI_* constants. si->applet.st1 is used to indicate whether prompt is enabled |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1527 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1528 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 1529 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1530 | { |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1531 | struct channel *req = si->ob; |
| 1532 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1533 | int reql; |
| 1534 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1535 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1536 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 1537 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1538 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1539 | while (1) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1540 | if (si->applet.st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1541 | /* Stats output not initialized yet */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1542 | memset(&si->applet.ctx.stats, 0, sizeof(si->applet.ctx.stats)); |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1543 | si->applet.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1544 | } |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1545 | else if (si->applet.st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1546 | /* Let's close for real now. We just close the request |
| 1547 | * side, the conditions below will complete if needed. |
| 1548 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1549 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1550 | break; |
| 1551 | } |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1552 | else if (si->applet.st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1553 | /* ensure we have some output room left in the event we |
| 1554 | * would want to return some info right after parsing. |
| 1555 | */ |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1556 | if (buffer_almost_full(si->ib->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1557 | break; |
| 1558 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1559 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1560 | if (reql <= 0) { /* closed or EOL not found */ |
| 1561 | if (reql == 0) |
| 1562 | break; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1563 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1564 | continue; |
| 1565 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1566 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1567 | /* seek for a possible semi-colon. If we find one, we |
| 1568 | * replace it with an LF and skip only this part. |
| 1569 | */ |
| 1570 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1571 | if (trash.str[len] == ';') { |
| 1572 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1573 | reql = len + 1; |
| 1574 | break; |
| 1575 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1576 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1577 | /* now it is time to check that we have a full line, |
| 1578 | * remove the trailing \n and possibly \r, then cut the |
| 1579 | * line. |
| 1580 | */ |
| 1581 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1582 | if (trash.str[len] != '\n') { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1583 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1584 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1585 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1586 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1587 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1588 | len--; |
| 1589 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1590 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1591 | |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1592 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1593 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1594 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1595 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1596 | continue; |
| 1597 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1598 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1599 | si->applet.st1 = !si->applet.st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1600 | else if (strcmp(trash.str, "help") == 0 || |
| 1601 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1602 | si->applet.ctx.cli.msg = stats_sock_usage_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1603 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1604 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1605 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1606 | * another STAT_CLI_O_* into si->applet.st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1607 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1608 | } |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1609 | else if (!si->applet.st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1610 | /* if prompt is disabled, print help on empty lines, |
| 1611 | * so that the user at least knows how to enable |
| 1612 | * prompt and find help. |
| 1613 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1614 | si->applet.ctx.cli.msg = stats_sock_usage_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1615 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1619 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1620 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1621 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1622 | 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] | 1623 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1624 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1625 | continue; |
| 1626 | } |
| 1627 | |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1628 | switch (si->applet.st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1629 | case STAT_CLI_PRINT: |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1630 | if (bi_putstr(si->ib, si->applet.ctx.cli.msg) != -1) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1631 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1632 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1633 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1634 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1635 | si->applet.st0 = STAT_CLI_PROMPT; |
| 1636 | break; |
| 1637 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1638 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1639 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1640 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1641 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1642 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1643 | si->applet.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_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1646 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1647 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1648 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1649 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1650 | case STAT_CLI_O_CLR: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1651 | if (stats_table_request(si, si->applet.st0)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1652 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1653 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1654 | default: /* abnormal state */ |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1655 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1656 | break; |
| 1657 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1658 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1659 | /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */ |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1660 | if (si->applet.st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1661 | if (bi_putstr(si->ib, si->applet.st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1662 | si->applet.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1663 | } |
| 1664 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1665 | /* If the output functions are still there, it means they require more room. */ |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1666 | if (si->applet.st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1667 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1668 | |
| 1669 | /* Now we close the output if one of the writers did so, |
| 1670 | * or if we're not in interactive mode and the request |
| 1671 | * buffer is empty. This still allows pipelined requests |
| 1672 | * to be sent in non-interactive mode. |
| 1673 | */ |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1674 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!si->applet.st1 && !req->buf->o)) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1675 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1676 | continue; |
| 1677 | } |
| 1678 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1679 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1680 | si->applet.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1681 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1682 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1683 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1684 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST) && (si->applet.st0 != STAT_CLI_GETREQ)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1685 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 1686 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1687 | /* 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] | 1688 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 1689 | * we forward the close to the request side so that it flows upstream to |
| 1690 | * the client. |
| 1691 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1692 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1693 | } |
| 1694 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1695 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && (si->applet.st0 < STAT_CLI_OUTPUT)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1696 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 1697 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 1698 | /* We have no more processing to do, and nothing more to send, and |
| 1699 | * the client side has closed. So we'll forward this state downstream |
| 1700 | * on the response buffer. |
| 1701 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1702 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1703 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1707 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1708 | |
| 1709 | /* we don't want to expire timeouts while we're processing requests */ |
| 1710 | si->ib->rex = TICK_ETERNITY; |
| 1711 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1712 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1713 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1714 | 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] | 1715 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1716 | 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] | 1717 | |
| 1718 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 1719 | /* check that we have released everything then unregister */ |
| 1720 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1721 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1722 | } |
| 1723 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1724 | /* This function dumps information onto the stream interface's read buffer. |
| 1725 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 1726 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1727 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1728 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1729 | { |
| 1730 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 1731 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1732 | chunk_printf(&trash, |
| 1733 | "Name: " PRODUCT_NAME "\n" |
| 1734 | "Version: " HAPROXY_VERSION "\n" |
| 1735 | "Release_date: " HAPROXY_DATE "\n" |
| 1736 | "Nbproc: %d\n" |
| 1737 | "Process_num: %d\n" |
| 1738 | "Pid: %d\n" |
| 1739 | "Uptime: %dd %dh%02dm%02ds\n" |
| 1740 | "Uptime_sec: %d\n" |
| 1741 | "Memmax_MB: %d\n" |
| 1742 | "Ulimit-n: %d\n" |
| 1743 | "Maxsock: %d\n" |
| 1744 | "Maxconn: %d\n" |
| 1745 | "Hard_maxconn: %d\n" |
| 1746 | "Maxpipes: %d\n" |
| 1747 | "CurrConns: %d\n" |
| 1748 | "PipesUsed: %d\n" |
| 1749 | "PipesFree: %d\n" |
| 1750 | "ConnRate: %d\n" |
| 1751 | "ConnRateLimit: %d\n" |
| 1752 | "MaxConnRate: %d\n" |
| 1753 | "CompressBpsIn: %u\n" |
| 1754 | "CompressBpsOut: %u\n" |
| 1755 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1756 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1757 | "ZlibMemUsage: %ld\n" |
| 1758 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1759 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1760 | "Tasks: %d\n" |
| 1761 | "Run_queue: %d\n" |
| 1762 | "Idle_pct: %d\n" |
| 1763 | "node: %s\n" |
| 1764 | "description: %s\n" |
| 1765 | "", |
| 1766 | global.nbproc, |
| 1767 | relative_pid, |
| 1768 | pid, |
| 1769 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 1770 | up, |
| 1771 | global.rlimit_memmax, |
| 1772 | global.rlimit_nofile, |
| 1773 | global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes, |
| 1774 | actconn, pipes_used, pipes_free, |
| 1775 | read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max, |
| 1776 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 1777 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1778 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1779 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1780 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1781 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 1782 | global.node, global.desc ? global.desc : "" |
| 1783 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1784 | |
| 1785 | if (bi_putchk(si->ib, &trash) == -1) |
| 1786 | return 0; |
| 1787 | |
| 1788 | return 1; |
| 1789 | } |
| 1790 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1791 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 1792 | * the state from stream interface <si>. The caller is responsible for clearing |
| 1793 | * 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] | 1794 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1795 | 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] | 1796 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1797 | int i; |
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 | if (!(px->cap & PR_CAP_FE)) |
| 1800 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1801 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1802 | if ((si->applet.ctx.stats.flags & STAT_BOUND) && !(si->applet.ctx.stats.type & (1 << STATS_TYPE_FE))) |
| 1803 | return 0; |
| 1804 | |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 1805 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1806 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1807 | /* name, queue */ |
| 1808 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1809 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1810 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 1811 | /* Column sub-heading for Enable or Disable server */ |
| 1812 | chunk_appendf(&trash, "<td></td>"); |
| 1813 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1814 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1815 | chunk_appendf(&trash, |
| 1816 | "<td class=ac>" |
| 1817 | "<a name=\"%s/Frontend\"></a>" |
| 1818 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 1819 | "<td colspan=3></td>" |
| 1820 | "", |
| 1821 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1822 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1823 | chunk_appendf(&trash, |
| 1824 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1825 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1826 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 1827 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 1828 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1829 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 1830 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 1831 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1832 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1833 | if (px->mode == PR_MODE_HTTP) |
| 1834 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1835 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1836 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1837 | |
| 1838 | chunk_appendf(&trash, |
| 1839 | "</table></div></u></td>" |
| 1840 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1841 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1842 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 1843 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 1844 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1845 | U2H(px->fe_counters.sps_max), |
| 1846 | U2H(px->fe_counters.cps_max), |
| 1847 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1848 | |
| 1849 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1850 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1851 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1852 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1853 | |
| 1854 | chunk_appendf(&trash, |
| 1855 | "</table></div></u></td>" |
| 1856 | /* sessions rate : limit */ |
| 1857 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1858 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1859 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1860 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1861 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1862 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1863 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1864 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 1865 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1866 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1867 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 1868 | U2H(px->fe_counters.cum_sess), |
| 1869 | U2H(px->fe_counters.cum_conn), |
| 1870 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1871 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1872 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1873 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1874 | chunk_appendf(&trash, |
| 1875 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 1876 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 1877 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 1878 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1879 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 1880 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 1881 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 1882 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 1883 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 1884 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1885 | U2H(px->fe_counters.p.http.cum_req), |
| 1886 | U2H(px->fe_counters.p.http.rsp[1]), |
| 1887 | U2H(px->fe_counters.p.http.rsp[2]), |
| 1888 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1889 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1890 | (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] | 1891 | U2H(px->fe_counters.p.http.rsp[3]), |
| 1892 | U2H(px->fe_counters.p.http.rsp[4]), |
| 1893 | U2H(px->fe_counters.p.http.rsp[5]), |
| 1894 | U2H(px->fe_counters.p.http.rsp[0]), |
| 1895 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1896 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1897 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1898 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1899 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1900 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1901 | "<td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1902 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1903 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1904 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1905 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1906 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1907 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1908 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 1909 | "<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] | 1910 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1911 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1912 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 1913 | px->fe_counters.comp_in ? |
| 1914 | (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] | 1915 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1916 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1917 | chunk_appendf(&trash, |
| 1918 | /* denied: req, resp */ |
| 1919 | "<td>%s</td><td>%s</td>" |
| 1920 | /* errors : request, connect, response */ |
| 1921 | "<td>%s</td><td></td><td></td>" |
| 1922 | /* warnings: retries, redispatches */ |
| 1923 | "<td></td><td></td>" |
| 1924 | /* server status : reflect frontend status */ |
| 1925 | "<td class=ac>%s</td>" |
| 1926 | /* rest of server: nothing */ |
| 1927 | "<td class=ac colspan=8></td></tr>" |
| 1928 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1929 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 1930 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1931 | px->state == PR_STREADY ? "OPEN" : |
| 1932 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1933 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1934 | else { /* CSV mode */ |
| 1935 | chunk_appendf(&trash, |
| 1936 | /* pxid, name, queue cur, queue max, */ |
| 1937 | "%s,FRONTEND,,," |
| 1938 | /* sessions : current, max, limit, total */ |
| 1939 | "%d,%d,%d,%lld," |
| 1940 | /* bytes : in, out */ |
| 1941 | "%lld,%lld," |
| 1942 | /* denied: req, resp */ |
| 1943 | "%lld,%lld," |
| 1944 | /* errors : request, connect, response */ |
| 1945 | "%lld,,," |
| 1946 | /* warnings: retries, redispatches */ |
| 1947 | ",," |
| 1948 | /* server status : reflect frontend status */ |
| 1949 | "%s," |
| 1950 | /* rest of server: nothing */ |
| 1951 | ",,,,,,,," |
| 1952 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 1953 | "%d,%d,0,,,,%d," |
| 1954 | /* rate, rate_lim, rate_max */ |
| 1955 | "%u,%u,%u," |
| 1956 | /* check_status, check_code, check_duration */ |
| 1957 | ",,,", |
| 1958 | px->id, |
| 1959 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 1960 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 1961 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 1962 | px->fe_counters.failed_req, |
| 1963 | px->state == PR_STREADY ? "OPEN" : |
| 1964 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 1965 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 1966 | read_freq_ctr(&px->fe_sess_per_sec), |
| 1967 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1968 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1969 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1970 | if (px->mode == PR_MODE_HTTP) { |
| 1971 | for (i=1; i<6; i++) |
| 1972 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 1973 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 1974 | } |
| 1975 | else |
| 1976 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1977 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1978 | /* failed health analyses */ |
| 1979 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1980 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1981 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 1982 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 1983 | read_freq_ctr(&px->fe_req_per_sec), |
| 1984 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 1985 | |
| 1986 | /* errors: cli_aborts, srv_aborts */ |
| 1987 | chunk_appendf(&trash, ",,"); |
| 1988 | |
| 1989 | /* compression: in, out, bypassed */ |
| 1990 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 1991 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 1992 | |
| 1993 | /* compression: comp_rsp */ |
| 1994 | chunk_appendf(&trash, "%lld,", |
| 1995 | px->fe_counters.p.http.comp_rsp); |
| 1996 | |
| 1997 | /* finish with EOL */ |
| 1998 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1999 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2000 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2001 | } |
| 2002 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2003 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 2004 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 2005 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 2006 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2007 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2008 | 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] | 2009 | { |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 2010 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2011 | chunk_appendf(&trash, "<tr class=socket>"); |
| 2012 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 2013 | /* Column sub-heading for Enable or Disable server */ |
| 2014 | chunk_appendf(&trash, "<td></td>"); |
| 2015 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2016 | chunk_appendf(&trash, |
| 2017 | /* frontend name, listener name */ |
| 2018 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 2019 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 2020 | "", |
| 2021 | px->id, l->name, |
| 2022 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2023 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2024 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2025 | if (flags & ST_SHLGNDS) { |
| 2026 | char str[INET6_ADDRSTRLEN]; |
| 2027 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2028 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2029 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2030 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2031 | port = get_host_port(&l->addr); |
| 2032 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2033 | case AF_INET: |
| 2034 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 2035 | break; |
| 2036 | case AF_INET6: |
| 2037 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 2038 | break; |
| 2039 | case AF_UNIX: |
| 2040 | chunk_appendf(&trash, "unix, "); |
| 2041 | break; |
| 2042 | case -1: |
| 2043 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2044 | break; |
| 2045 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2046 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2047 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2048 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 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 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2052 | /* queue */ |
| 2053 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2054 | /* sessions rate: current, max, limit */ |
| 2055 | "<td colspan=3> </td>" |
| 2056 | /* sessions: current, max, limit, total, lbtot */ |
| 2057 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2058 | "<td>%s</td><td> </td>" |
| 2059 | /* bytes: in, out */ |
| 2060 | "<td>%s</td><td>%s</td>" |
| 2061 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2062 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2063 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2064 | 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] | 2065 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2066 | chunk_appendf(&trash, |
| 2067 | /* denied: req, resp */ |
| 2068 | "<td>%s</td><td>%s</td>" |
| 2069 | /* errors: request, connect, response */ |
| 2070 | "<td>%s</td><td></td><td></td>" |
| 2071 | /* warnings: retries, redispatches */ |
| 2072 | "<td></td><td></td>" |
| 2073 | /* server status: reflect listener status */ |
| 2074 | "<td class=ac>%s</td>" |
| 2075 | /* rest of server: nothing */ |
| 2076 | "<td class=ac colspan=8></td></tr>" |
| 2077 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2078 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2079 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2080 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2081 | } |
| 2082 | else { /* CSV mode */ |
| 2083 | chunk_appendf(&trash, |
| 2084 | /* pxid, name, queue cur, queue max, */ |
| 2085 | "%s,%s,,," |
| 2086 | /* sessions: current, max, limit, total */ |
| 2087 | "%d,%d,%d,%lld," |
| 2088 | /* bytes: in, out */ |
| 2089 | "%lld,%lld," |
| 2090 | /* denied: req, resp */ |
| 2091 | "%lld,%lld," |
| 2092 | /* errors: request, connect, response */ |
| 2093 | "%lld,,," |
| 2094 | /* warnings: retries, redispatches */ |
| 2095 | ",," |
| 2096 | /* server status: reflect listener status */ |
| 2097 | "%s," |
| 2098 | /* rest of server: nothing */ |
| 2099 | ",,,,,,,," |
| 2100 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2101 | "%d,%d,%d,,,,%d," |
| 2102 | /* rate, rate_lim, rate_max */ |
| 2103 | ",,," |
| 2104 | /* check_status, check_code, check_duration */ |
| 2105 | ",,," |
| 2106 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2107 | ",,,,,," |
| 2108 | /* failed health analyses */ |
| 2109 | "," |
| 2110 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2111 | ",,," |
| 2112 | /* errors: cli_aborts, srv_aborts */ |
| 2113 | ",," |
| 2114 | /* compression: in, out, bypassed, comp_rsp */ |
| 2115 | ",,,," |
| 2116 | "\n", |
| 2117 | px->id, l->name, |
| 2118 | l->nbconn, l->counters->conn_max, |
| 2119 | l->maxconn, l->counters->cum_conn, |
| 2120 | l->counters->bytes_in, l->counters->bytes_out, |
| 2121 | l->counters->denied_req, l->counters->denied_resp, |
| 2122 | l->counters->failed_req, |
| 2123 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2124 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2125 | } |
| 2126 | return 1; |
| 2127 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2128 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2129 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2130 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2131 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2132 | * if it emits anything, zero otherwise. The <state> parameter can take the |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2133 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, |
| 2134 | * 6,7=DRAIN, 8=unchecked. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2135 | */ |
| 2136 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2137 | { |
| 2138 | struct server *ref = sv->track ? sv->track : sv; |
| 2139 | char str[INET6_ADDRSTRLEN]; |
| 2140 | struct chunk src; |
| 2141 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2142 | |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 2143 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2144 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2145 | "DOWN", |
| 2146 | "DN %d/%d ↑", |
| 2147 | "UP %d/%d ↓", |
| 2148 | "UP", |
| 2149 | "NOLB %d/%d ↓", |
| 2150 | "NOLB", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2151 | "DRAIN %d/%d ↓", |
| 2152 | "DRAIN", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2153 | "<i>no check</i>" |
| 2154 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2155 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2156 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2157 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2158 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2159 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2160 | "<tr class=\"%s%d\">", |
| 2161 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2162 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2163 | if ((px->cap & PR_CAP_BE) && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2164 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2165 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2166 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2167 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2168 | chunk_appendf(&trash, |
| 2169 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2170 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2171 | "", |
| 2172 | px->id, sv->id, |
| 2173 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2174 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2175 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2176 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2177 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2178 | |
| 2179 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2180 | case AF_INET: |
| 2181 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2182 | break; |
| 2183 | case AF_INET6: |
| 2184 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2185 | break; |
| 2186 | case AF_UNIX: |
| 2187 | chunk_appendf(&trash, "unix, "); |
| 2188 | break; |
| 2189 | case -1: |
| 2190 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2191 | break; |
| 2192 | default: /* address family not supported */ |
| 2193 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2194 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2195 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2196 | /* id */ |
| 2197 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2198 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2199 | /* cookie */ |
| 2200 | if (sv->cookie) { |
| 2201 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2202 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2203 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2204 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2205 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2206 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2207 | } |
| 2208 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2209 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2210 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2211 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2212 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2213 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2214 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2215 | /* sessions rate : current, max, limit */ |
| 2216 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2217 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2218 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2219 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2220 | 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] | 2221 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2222 | |
| 2223 | chunk_appendf(&trash, |
| 2224 | /* sessions: current, max, limit, total */ |
| 2225 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2226 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2227 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2228 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2229 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2230 | U2H(sv->counters.cum_sess), |
| 2231 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2232 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2233 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2234 | if (px->mode == PR_MODE_HTTP) { |
| 2235 | unsigned long long tot; |
| 2236 | for (tot = i = 0; i < 6; i++) |
| 2237 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2238 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2239 | chunk_appendf(&trash, |
| 2240 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2241 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2242 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2243 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2244 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2245 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2246 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2247 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2248 | U2H(tot), |
| 2249 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2250 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2251 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2252 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2253 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2254 | 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] | 2255 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2256 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2257 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2258 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2259 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2260 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2261 | U2H(sv->counters.cum_lbconn)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2262 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2263 | chunk_appendf(&trash, |
| 2264 | /* bytes : in, out */ |
| 2265 | "<td>%s</td><td>%s</td>" |
| 2266 | /* denied: req, resp */ |
| 2267 | "<td></td><td>%s</td>" |
| 2268 | /* errors : request, connect */ |
| 2269 | "<td></td><td>%s</td>" |
| 2270 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2271 | "<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] | 2272 | /* warnings: retries, redispatches */ |
| 2273 | "<td>%lld</td><td>%lld</td>" |
| 2274 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2275 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2276 | U2H(sv->counters.failed_secu), |
| 2277 | U2H(sv->counters.failed_conns), |
| 2278 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2279 | sv->counters.cli_aborts, |
| 2280 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2281 | sv->counters.retries, sv->counters.redispatches); |
| 2282 | |
| 2283 | /* status, lest check */ |
| 2284 | chunk_appendf(&trash, "<td class=ac>"); |
| 2285 | |
| 2286 | if (sv->state & SRV_MAINTAIN) { |
| 2287 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2288 | chunk_appendf(&trash, "MAINT"); |
| 2289 | } |
| 2290 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2291 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2292 | chunk_appendf(&trash, "MAINT(via)"); |
| 2293 | } |
| 2294 | else if (ref->state & SRV_CHECKED) { |
| 2295 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2296 | chunk_appendf(&trash, |
| 2297 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2298 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2299 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2300 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2301 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2302 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2303 | chunk_appendf(&trash, |
| 2304 | "</td><td class=ac><u> %s%s", |
Simon Horman | cd5d7b6 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 2305 | (sv->check.state & CHK_STATE_RUNNING) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2306 | get_check_status_info(sv->check.status)); |
| 2307 | |
| 2308 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2309 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2310 | |
| 2311 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2312 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2313 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2314 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2315 | get_check_status_description(sv->check.status)); |
| 2316 | if (*sv->check.desc) { |
| 2317 | chunk_appendf(&trash, ": "); |
| 2318 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2319 | chunk_htmlencode(&trash, &src); |
| 2320 | } |
| 2321 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2322 | } |
| 2323 | else |
| 2324 | chunk_appendf(&trash, "</td><td>"); |
| 2325 | |
| 2326 | chunk_appendf(&trash, |
| 2327 | /* weight */ |
| 2328 | "</td><td class=ac>%d</td>" |
| 2329 | /* act, bck */ |
| 2330 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2331 | "", |
| 2332 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2333 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2334 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2335 | |
| 2336 | /* check failures: unique, fatal, down time */ |
| 2337 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2338 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2339 | |
| 2340 | if (ref->observe) |
| 2341 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2342 | |
| 2343 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2344 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2345 | "<td>%lld</td><td>%s</td>" |
| 2346 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2347 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2348 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2349 | } |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 2350 | else if (sv != ref) { |
| 2351 | if (sv->state & SRV_MAINTAIN) |
| 2352 | chunk_appendf(&trash, |
| 2353 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\"><a></td>", |
| 2354 | ref->proxy->id, ref->id); |
| 2355 | else |
| 2356 | chunk_appendf(&trash, |
| 2357 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2358 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2359 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2360 | else |
| 2361 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2362 | |
| 2363 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2364 | if (sv->state & SRV_WARMINGUP) |
| 2365 | 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] | 2366 | else |
| 2367 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2368 | } |
| 2369 | else { /* CSV mode */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2370 | static char *srv_hlt_st[9] = { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2371 | "DOWN,", |
| 2372 | "DOWN %d/%d,", |
| 2373 | "UP %d/%d,", |
| 2374 | "UP,", |
| 2375 | "NOLB %d/%d,", |
| 2376 | "NOLB,", |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2377 | "DRAIN %d/%d,", |
| 2378 | "DRAIN,", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2379 | "no check," |
| 2380 | }; |
| 2381 | |
| 2382 | chunk_appendf(&trash, |
| 2383 | /* pxid, name */ |
| 2384 | "%s,%s," |
| 2385 | /* queue : current, max */ |
| 2386 | "%d,%d," |
| 2387 | /* sessions : current, max, limit, total */ |
| 2388 | "%d,%d,%s,%lld," |
| 2389 | /* bytes : in, out */ |
| 2390 | "%lld,%lld," |
| 2391 | /* denied: req, resp */ |
| 2392 | ",%lld," |
| 2393 | /* errors : request, connect, response */ |
| 2394 | ",%lld,%lld," |
| 2395 | /* warnings: retries, redispatches */ |
| 2396 | "%lld,%lld," |
| 2397 | "", |
| 2398 | px->id, sv->id, |
| 2399 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2400 | 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] | 2401 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2402 | sv->counters.failed_secu, |
| 2403 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2404 | sv->counters.retries, sv->counters.redispatches); |
| 2405 | |
| 2406 | /* status */ |
| 2407 | if (sv->state & SRV_MAINTAIN) |
| 2408 | chunk_appendf(&trash, "MAINT,"); |
| 2409 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2410 | chunk_appendf(&trash, "MAINT(via),"); |
| 2411 | else |
| 2412 | chunk_appendf(&trash, |
| 2413 | srv_hlt_st[state], |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2414 | (ref->state & SRV_RUNNING) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2415 | (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2416 | |
| 2417 | chunk_appendf(&trash, |
| 2418 | /* weight, active, backup */ |
| 2419 | "%d,%d,%d," |
| 2420 | "", |
| 2421 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2422 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2423 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2424 | |
| 2425 | /* check failures: unique, fatal; last change, total downtime */ |
| 2426 | if (sv->state & SRV_CHECKED) |
| 2427 | chunk_appendf(&trash, |
| 2428 | "%lld,%lld,%d,%d,", |
| 2429 | sv->counters.failed_checks, sv->counters.down_trans, |
| 2430 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 2431 | else |
| 2432 | chunk_appendf(&trash, ",,,,"); |
| 2433 | |
| 2434 | /* queue limit, pid, iid, sid, */ |
| 2435 | chunk_appendf(&trash, |
| 2436 | "%s," |
| 2437 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2438 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2439 | relative_pid, px->uuid, sv->puid); |
| 2440 | |
| 2441 | /* throttle */ |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 2442 | if (sv->state & SRV_WARMINGUP) |
| 2443 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2444 | |
| 2445 | /* sessions: lbtot */ |
| 2446 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 2447 | |
| 2448 | /* tracked */ |
| 2449 | if (sv->track) |
| 2450 | chunk_appendf(&trash, "%s/%s,", |
| 2451 | sv->track->proxy->id, sv->track->id); |
| 2452 | else |
| 2453 | chunk_appendf(&trash, ","); |
| 2454 | |
| 2455 | /* type */ |
| 2456 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 2457 | |
| 2458 | /* rate */ |
| 2459 | chunk_appendf(&trash, "%u,,%u,", |
| 2460 | read_freq_ctr(&sv->sess_per_sec), |
| 2461 | sv->counters.sps_max); |
| 2462 | |
| 2463 | if (sv->state & SRV_CHECKED) { |
| 2464 | /* check_status */ |
| 2465 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 2466 | |
| 2467 | /* check_code */ |
| 2468 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2469 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 2470 | else |
| 2471 | chunk_appendf(&trash, ","); |
| 2472 | |
| 2473 | /* check_duration */ |
| 2474 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 2475 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 2476 | else |
| 2477 | chunk_appendf(&trash, ","); |
| 2478 | |
| 2479 | } |
| 2480 | else |
| 2481 | chunk_appendf(&trash, ",,,"); |
| 2482 | |
| 2483 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2484 | if (px->mode == PR_MODE_HTTP) { |
| 2485 | for (i=1; i<6; i++) |
| 2486 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 2487 | |
| 2488 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 2489 | } |
| 2490 | else |
| 2491 | chunk_appendf(&trash, ",,,,,,"); |
| 2492 | |
| 2493 | /* failed health analyses */ |
| 2494 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 2495 | |
| 2496 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2497 | chunk_appendf(&trash, ",,,"); |
| 2498 | |
| 2499 | /* errors: cli_aborts, srv_aborts */ |
| 2500 | chunk_appendf(&trash, "%lld,%lld,", |
| 2501 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 2502 | |
| 2503 | /* compression: in, out, bypassed, comp_rsp */ |
| 2504 | chunk_appendf(&trash, ",,,,"); |
| 2505 | |
| 2506 | /* finish with EOL */ |
| 2507 | chunk_appendf(&trash, "\n"); |
| 2508 | } |
| 2509 | return 1; |
| 2510 | } |
| 2511 | |
| 2512 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 2513 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 2514 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 2515 | */ |
| 2516 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 2517 | { |
| 2518 | struct chunk src; |
| 2519 | int i; |
| 2520 | |
| 2521 | if (!(px->cap & PR_CAP_BE)) |
| 2522 | return 0; |
| 2523 | |
| 2524 | if ((si->applet.ctx.stats.flags & STAT_BOUND) && !(si->applet.ctx.stats.type & (1 << STATS_TYPE_BE))) |
| 2525 | return 0; |
| 2526 | |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 2527 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2528 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
| 2529 | if (px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 2530 | /* Column sub-heading for Enable or Disable server */ |
| 2531 | chunk_appendf(&trash, "<td></td>"); |
| 2532 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2533 | chunk_appendf(&trash, |
| 2534 | "<td class=ac>" |
| 2535 | /* name */ |
| 2536 | "%s<a name=\"%s/Backend\"></a>" |
| 2537 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 2538 | "", |
| 2539 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2540 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2541 | |
| 2542 | if (flags & ST_SHLGNDS) { |
| 2543 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2544 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2545 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 2546 | |
| 2547 | /* cookie */ |
| 2548 | if (px->cookie_name) { |
| 2549 | chunk_appendf(&trash, ", cookie: '"); |
| 2550 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 2551 | chunk_htmlencode(&trash, &src); |
| 2552 | chunk_appendf(&trash, "'"); |
| 2553 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2554 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2558 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2559 | /* queue : current, max */ |
| 2560 | "<td>%s</td><td>%s</td><td></td>" |
| 2561 | /* sessions rate : current, max, limit */ |
| 2562 | "<td>%s</td><td>%s</td><td></td>" |
| 2563 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2564 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2565 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 2566 | 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] | 2567 | |
| 2568 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2569 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2570 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2571 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2572 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2573 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2574 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 2575 | U2H(px->be_counters.cum_conn), |
| 2576 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2577 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2578 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2579 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2580 | chunk_appendf(&trash, |
| 2581 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2582 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2583 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2584 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2585 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2586 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2587 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2588 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2589 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2590 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2591 | U2H(px->be_counters.p.http.cum_req), |
| 2592 | U2H(px->be_counters.p.http.rsp[1]), |
| 2593 | U2H(px->be_counters.p.http.rsp[2]), |
| 2594 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2595 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2596 | (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] | 2597 | U2H(px->be_counters.p.http.rsp[3]), |
| 2598 | U2H(px->be_counters.p.http.rsp[4]), |
| 2599 | U2H(px->be_counters.p.http.rsp[5]), |
| 2600 | U2H(px->be_counters.p.http.rsp[0]), |
| 2601 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2605 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2606 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2607 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2608 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2609 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2610 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2611 | U2H(px->be_counters.cum_lbconn), |
| 2612 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2613 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2614 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2615 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2616 | "<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] | 2617 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2618 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2619 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 2620 | px->be_counters.comp_in ? |
| 2621 | (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] | 2622 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 2623 | |
| 2624 | chunk_appendf(&trash, |
| 2625 | /* denied: req, resp */ |
| 2626 | "<td>%s</td><td>%s</td>" |
| 2627 | /* errors : request, connect */ |
| 2628 | "<td></td><td>%s</td>" |
| 2629 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2630 | "<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] | 2631 | /* warnings: retries, redispatches */ |
| 2632 | "<td>%lld</td><td>%lld</td>" |
| 2633 | /* backend status: reflect backend status (up/down): we display UP |
| 2634 | * if the backend has known working servers or if it has no server at |
| 2635 | * all (eg: for stats). Then we display the total weight, number of |
| 2636 | * active and backups. */ |
| 2637 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 2638 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 2639 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2640 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 2641 | U2H(px->be_counters.failed_conns), |
| 2642 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2643 | px->be_counters.cli_aborts, |
| 2644 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2645 | px->be_counters.retries, px->be_counters.redispatches, |
| 2646 | human_time(now.tv_sec - px->last_change, 1), |
| 2647 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 2648 | "<font color=\"red\"><b>DOWN</b></font>", |
| 2649 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2650 | px->srv_act, px->srv_bck); |
| 2651 | |
| 2652 | chunk_appendf(&trash, |
| 2653 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 2654 | "<td class=ac> </td><td>%d</td>" |
| 2655 | "<td>%s</td>" |
| 2656 | "<td></td>" |
| 2657 | "</tr>", |
| 2658 | px->down_trans, |
| 2659 | px->srv?human_time(be_downtime(px), 1):" "); |
| 2660 | } |
| 2661 | else { /* CSV mode */ |
| 2662 | chunk_appendf(&trash, |
| 2663 | /* pxid, name */ |
| 2664 | "%s,BACKEND," |
| 2665 | /* queue : current, max */ |
| 2666 | "%d,%d," |
| 2667 | /* sessions : current, max, limit, total */ |
| 2668 | "%d,%d,%d,%lld," |
| 2669 | /* bytes : in, out */ |
| 2670 | "%lld,%lld," |
| 2671 | /* denied: req, resp */ |
| 2672 | "%lld,%lld," |
| 2673 | /* errors : request, connect, response */ |
| 2674 | ",%lld,%lld," |
| 2675 | /* warnings: retries, redispatches */ |
| 2676 | "%lld,%lld," |
| 2677 | /* backend status: reflect backend status (up/down): we display UP |
| 2678 | * if the backend has known working servers or if it has no server at |
| 2679 | * all (eg: for stats). Then we display the total weight, number of |
| 2680 | * active and backups. */ |
| 2681 | "%s," |
| 2682 | "%d,%d,%d," |
| 2683 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 2684 | ",%d,%d,%d,," |
| 2685 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2686 | "%d,%d,0,,%lld,,%d," |
| 2687 | /* rate, rate_lim, rate_max, */ |
| 2688 | "%u,,%u," |
| 2689 | /* check_status, check_code, check_duration */ |
| 2690 | ",,,", |
| 2691 | px->id, |
| 2692 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 2693 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 2694 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 2695 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 2696 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 2697 | px->be_counters.retries, px->be_counters.redispatches, |
| 2698 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 2699 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2700 | px->srv_act, px->srv_bck, |
| 2701 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 2702 | px->srv?be_downtime(px):0, |
| 2703 | relative_pid, px->uuid, |
| 2704 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 2705 | read_freq_ctr(&px->be_sess_per_sec), |
| 2706 | px->be_counters.sps_max); |
| 2707 | |
| 2708 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2709 | if (px->mode == PR_MODE_HTTP) { |
| 2710 | for (i=1; i<6; i++) |
| 2711 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 2712 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 2713 | } |
| 2714 | else |
| 2715 | chunk_appendf(&trash, ",,,,,,"); |
| 2716 | |
| 2717 | /* failed health analyses */ |
| 2718 | chunk_appendf(&trash, ","); |
| 2719 | |
| 2720 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2721 | chunk_appendf(&trash, ",,,"); |
| 2722 | |
| 2723 | /* errors: cli_aborts, srv_aborts */ |
| 2724 | chunk_appendf(&trash, "%lld,%lld,", |
| 2725 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 2726 | |
| 2727 | /* compression: in, out, bypassed */ |
| 2728 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2729 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 2730 | |
| 2731 | /* compression: comp_rsp */ |
| 2732 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 2733 | |
| 2734 | /* finish with EOL */ |
| 2735 | chunk_appendf(&trash, "\n"); |
| 2736 | } |
| 2737 | return 1; |
| 2738 | } |
| 2739 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2740 | /* 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] | 2741 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2742 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2743 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2744 | 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] | 2745 | { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2746 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 2747 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2748 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 2749 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2750 | |
| 2751 | /* scope_txt = search pattern + search query, si->applet.ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 2752 | scope_txt[0] = 0; |
| 2753 | if (si->applet.ctx.stats.scope_len) { |
| 2754 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
| 2755 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + si->applet.ctx.stats.scope_str, si->applet.ctx.stats.scope_len); |
| 2756 | scope_txt[strlen(STAT_SCOPE_PATTERN) + si->applet.ctx.stats.scope_len] = 0; |
| 2757 | } |
| 2758 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2759 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2760 | "<form action=\"%s%s%s%s\" method=\"post\">", |
| 2761 | uri->uri_prefix, |
| 2762 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2763 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2764 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2765 | } |
| 2766 | |
| 2767 | /* print a new table */ |
| 2768 | chunk_appendf(&trash, |
| 2769 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2770 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2771 | "<th class=\"pxname\" width=\"10%%\">"); |
| 2772 | |
| 2773 | chunk_appendf(&trash, |
| 2774 | "<a name=\"%s\"></a>%s" |
| 2775 | "<a class=px href=\"#%s\">%s</a>", |
| 2776 | px->id, |
| 2777 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 2778 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2779 | |
| 2780 | if (uri->flags & ST_SHLGNDS) { |
| 2781 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 2782 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2783 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 2784 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2785 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2789 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2790 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 2791 | "</tr>\n" |
| 2792 | "</table>\n" |
| 2793 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2794 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2795 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 2796 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 2797 | |
| 2798 | if ((px->cap & PR_CAP_BE) && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 2799 | /* Column heading for Enable or Disable server */ |
| 2800 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2801 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2802 | |
| 2803 | chunk_appendf(&trash, |
| 2804 | "<th rowspan=2></th>" |
| 2805 | "<th colspan=3>Queue</th>" |
| 2806 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
| 2807 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 2808 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 2809 | "<th colspan=9>Server</th>" |
| 2810 | "</tr>\n" |
| 2811 | "<tr class=\"titre\">" |
| 2812 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 2813 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 2814 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>" |
| 2815 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 2816 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 2817 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 2818 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 2819 | "<th>Thrtle</th>\n" |
| 2820 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2821 | } |
| 2822 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2823 | /* 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] | 2824 | * 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] | 2825 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2826 | 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] | 2827 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2828 | chunk_appendf(&trash, "</table>"); |
| 2829 | |
| 2830 | if ((px->cap & PR_CAP_BE) && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 2831 | /* close the form used to enable/disable this proxy servers */ |
| 2832 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2833 | "Choose the action to perform on the checked servers : " |
| 2834 | "<select name=action>" |
| 2835 | "<option value=\"\"></option>" |
| 2836 | "<option value=\"disable\">Disable</option>" |
| 2837 | "<option value=\"enable\">Enable</option>" |
| 2838 | "<option value=\"stop\">Soft Stop</option>" |
| 2839 | "<option value=\"start\">Soft Start</option>" |
| 2840 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 2841 | "</select>" |
| 2842 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 2843 | " <input type=\"submit\" value=\"Apply\">" |
| 2844 | "</form>", |
| 2845 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2849 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2850 | |
| 2851 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2852 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 2853 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 2854 | * buffer space, or non-zero if everything completed. This function is used |
| 2855 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 2856 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2857 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2858 | 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] | 2859 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 2860 | struct session *s = si->conn->xprt_ctx; |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2861 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2862 | 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] | 2863 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2864 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2865 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2866 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2867 | switch (si->applet.ctx.stats.px_st) { |
| 2868 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2869 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2870 | if (uri && uri->scope) { |
| 2871 | /* we have a limited scope, we have to check the proxy name */ |
| 2872 | struct stat_scope *scope; |
| 2873 | int len; |
| 2874 | |
| 2875 | len = strlen(px->id); |
| 2876 | scope = uri->scope; |
| 2877 | |
| 2878 | while (scope) { |
| 2879 | /* match exact proxy name */ |
| 2880 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 2881 | break; |
| 2882 | |
| 2883 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 2884 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2885 | break; |
| 2886 | scope = scope->next; |
| 2887 | } |
| 2888 | |
| 2889 | /* proxy name not found : don't dump anything */ |
| 2890 | if (scope == NULL) |
| 2891 | return 1; |
| 2892 | } |
| 2893 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 2894 | /* if the user has requested a limited output and the proxy |
| 2895 | * name does not match, skip it. |
| 2896 | */ |
| 2897 | if (si->applet.ctx.stats.scope_len && |
| 2898 | strnistr(px->id, strlen(px->id), bo_ptr(si->ob->buf) + si->applet.ctx.stats.scope_str, si->applet.ctx.stats.scope_len) == NULL) |
| 2899 | return 1; |
| 2900 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2901 | if ((si->applet.ctx.stats.flags & STAT_BOUND) && |
| 2902 | (si->applet.ctx.stats.iid != -1) && |
| 2903 | (px->uuid != si->applet.ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2904 | return 1; |
| 2905 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2906 | si->applet.ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2907 | /* fall through */ |
| 2908 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2909 | case STAT_PX_ST_TH: |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 2910 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2911 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2912 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2913 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2914 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2915 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2916 | si->applet.ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2917 | /* fall through */ |
| 2918 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2919 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2920 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2921 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2922 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2923 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2924 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2925 | si->applet.ctx.stats.l = px->conf.listeners.n; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2926 | si->applet.ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2927 | /* fall through */ |
| 2928 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2929 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2930 | /* stats.l has been initialized above */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2931 | for (; si->applet.ctx.stats.l != &px->conf.listeners; si->applet.ctx.stats.l = l->by_fe.n) { |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2932 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2933 | return 0; |
| 2934 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2935 | l = LIST_ELEM(si->applet.ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2936 | if (!l->counters) |
| 2937 | continue; |
| 2938 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2939 | if (si->applet.ctx.stats.flags & STAT_BOUND) { |
| 2940 | if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2941 | break; |
| 2942 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2943 | if (si->applet.ctx.stats.sid != -1 && l->luid != si->applet.ctx.stats.sid) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2944 | continue; |
| 2945 | } |
| 2946 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2947 | /* print the frontend */ |
| 2948 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 2949 | if (bi_putchk(rep, &trash) == -1) |
| 2950 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2951 | } |
| 2952 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2953 | si->applet.ctx.stats.sv = px->srv; /* may be NULL */ |
| 2954 | si->applet.ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2955 | /* fall through */ |
| 2956 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2957 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2958 | /* stats.sv has been initialized above */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2959 | for (; si->applet.ctx.stats.sv != NULL; si->applet.ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2960 | 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] | 2961 | |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2962 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2963 | return 0; |
| 2964 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2965 | sv = si->applet.ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2966 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2967 | if (si->applet.ctx.stats.flags & STAT_BOUND) { |
| 2968 | if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2969 | break; |
| 2970 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2971 | if (si->applet.ctx.stats.sid != -1 && sv->puid != si->applet.ctx.stats.sid) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2972 | continue; |
| 2973 | } |
| 2974 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2975 | if (sv->track) |
| 2976 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2977 | else |
| 2978 | svs = sv; |
| 2979 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2980 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2981 | if (!(svs->state & SRV_CHECKED)) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2982 | sv_state = 8; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2983 | else if (svs->state & SRV_RUNNING) { |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 2984 | if (svs->check.health == svs->check.rise + svs->check.fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2985 | sv_state = 3; /* UP */ |
| 2986 | else |
| 2987 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2988 | |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 2989 | if (svs->state & SRV_DRAIN) |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 2990 | sv_state += 4; |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 2991 | else if (svs->state & SRV_GOINGDOWN) |
| 2992 | sv_state += 2; |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2993 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2994 | else |
Simon Horman | 125d099 | 2013-02-24 17:23:38 +0900 | [diff] [blame] | 2995 | if (svs->check.health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2996 | sv_state = 1; /* going up */ |
| 2997 | else |
| 2998 | sv_state = 0; /* DOWN */ |
| 2999 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3000 | if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (si->applet.ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3001 | /* do not report servers which are DOWN */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3002 | si->applet.ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3003 | continue; |
| 3004 | } |
| 3005 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3006 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 3007 | if (bi_putchk(rep, &trash) == -1) |
| 3008 | return 0; |
| 3009 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 3010 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3011 | si->applet.ctx.stats.px_st = STAT_PX_ST_BE; |
| 3012 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3013 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3014 | case STAT_PX_ST_BE: |
| 3015 | /* print the backend */ |
| 3016 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 3017 | if (bi_putchk(rep, &trash) == -1) |
| 3018 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3019 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3020 | si->applet.ctx.stats.px_st = STAT_PX_ST_END; |
| 3021 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3022 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3023 | case STAT_PX_ST_END: |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3024 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3025 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3026 | if (bi_putchk(rep, &trash) == -1) |
| 3027 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3028 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3029 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3030 | si->applet.ctx.stats.px_st = STAT_PX_ST_FIN; |
| 3031 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3032 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3033 | case STAT_PX_ST_FIN: |
| 3034 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3035 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3036 | default: |
| 3037 | /* unknown state, we should put an abort() here ! */ |
| 3038 | return 1; |
| 3039 | } |
| 3040 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3041 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3042 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 3043 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3044 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3045 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3046 | { |
| 3047 | /* WARNING! This must fit in the first buffer !!! */ |
| 3048 | chunk_appendf(&trash, |
| 3049 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3050 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3051 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 3052 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3053 | "<style type=\"text/css\"><!--\n" |
| 3054 | "body {" |
| 3055 | " font-family: arial, helvetica, sans-serif;" |
| 3056 | " font-size: 12px;" |
| 3057 | " font-weight: normal;" |
| 3058 | " color: black;" |
| 3059 | " background: white;" |
| 3060 | "}\n" |
| 3061 | "th,td {" |
| 3062 | " font-size: 10px;" |
| 3063 | "}\n" |
| 3064 | "h1 {" |
| 3065 | " font-size: x-large;" |
| 3066 | " margin-bottom: 0.5em;" |
| 3067 | "}\n" |
| 3068 | "h2 {" |
| 3069 | " font-family: helvetica, arial;" |
| 3070 | " font-size: x-large;" |
| 3071 | " font-weight: bold;" |
| 3072 | " font-style: italic;" |
| 3073 | " color: #6020a0;" |
| 3074 | " margin-top: 0em;" |
| 3075 | " margin-bottom: 0em;" |
| 3076 | "}\n" |
| 3077 | "h3 {" |
| 3078 | " font-family: helvetica, arial;" |
| 3079 | " font-size: 16px;" |
| 3080 | " font-weight: bold;" |
| 3081 | " color: #b00040;" |
| 3082 | " background: #e8e8d0;" |
| 3083 | " margin-top: 0em;" |
| 3084 | " margin-bottom: 0em;" |
| 3085 | "}\n" |
| 3086 | "li {" |
| 3087 | " margin-top: 0.25em;" |
| 3088 | " margin-right: 2em;" |
| 3089 | "}\n" |
| 3090 | ".hr {margin-top: 0.25em;" |
| 3091 | " border-color: black;" |
| 3092 | " border-bottom-style: solid;" |
| 3093 | "}\n" |
| 3094 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3095 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3096 | ".frontend {background: #e8e8d0;}\n" |
| 3097 | ".socket {background: #d0d0d0;}\n" |
| 3098 | ".backend {background: #e8e8d0;}\n" |
| 3099 | ".active0 {background: #ff9090;}\n" |
| 3100 | ".active1 {background: #ffd020;}\n" |
| 3101 | ".active2 {background: #ffffa0;}\n" |
| 3102 | ".active3 {background: #c0ffc0;}\n" |
| 3103 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3104 | ".active5 {background: #20a0ff;}\n" /* NOLB state shows different to be detected */ |
| 3105 | ".active6 {background: #ffffa0;}\n" /* DRAIN going down = same as going down */ |
| 3106 | ".active7 {background: #20a0FF;}\n" /* DRAIN must be detected (weight=0) */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3107 | ".active8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3108 | ".backup0 {background: #ff9090;}\n" |
| 3109 | ".backup1 {background: #ff80ff;}\n" |
| 3110 | ".backup2 {background: #c060ff;}\n" |
| 3111 | ".backup3 {background: #b0d0ff;}\n" |
| 3112 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3113 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3114 | ".backup6 {background: #c060ff;}\n" |
| 3115 | ".backup7 {background: #cc9900;}\n" |
| 3116 | ".backup8 {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3117 | ".maintain {background: #c07820;}\n" |
| 3118 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3119 | "\n" |
| 3120 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3121 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3122 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3123 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3124 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3125 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3126 | "\n" |
| 3127 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3128 | "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" |
| 3129 | "table.tbl td.ac { text-align: center;}\n" |
| 3130 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3131 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3132 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3133 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3134 | "\n" |
| 3135 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3136 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3137 | "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] | 3138 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3139 | "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" |
| 3140 | "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] | 3141 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3142 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3143 | " display:block;\n" |
| 3144 | " visibility:hidden;\n" |
| 3145 | " z-index:2147483647;\n" |
| 3146 | " position:absolute;\n" |
| 3147 | " padding:2px 4px 3px;\n" |
| 3148 | " background:#f0f060; color:#000000;\n" |
| 3149 | " border:1px solid #7040c0;\n" |
| 3150 | " white-space:nowrap;\n" |
| 3151 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3152 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3153 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3154 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3155 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3156 | "-->\n" |
| 3157 | "</style></head>\n", |
| 3158 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3159 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3160 | ); |
| 3161 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3162 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3163 | /* 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] | 3164 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3165 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3166 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3167 | 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] | 3168 | { |
| 3169 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3170 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3171 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3172 | /* WARNING! this has to fit the first packet too. |
| 3173 | * We are around 3.5 kB, add adding entries will |
| 3174 | * become tricky if we want to support 4kB buffers ! |
| 3175 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3176 | chunk_appendf(&trash, |
| 3177 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3178 | PRODUCT_NAME "%s</a></h1>\n" |
| 3179 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3180 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3181 | "<h3>> General process information</h3>\n" |
| 3182 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3183 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3184 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3185 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3186 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3187 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3188 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3189 | "</td><td align=\"center\" nowrap>\n" |
| 3190 | "<table class=\"lgd\"><tr>\n" |
| 3191 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3192 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3193 | "</tr><tr>\n" |
| 3194 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3195 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3196 | "</tr><tr>\n" |
| 3197 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3198 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3199 | "</tr><tr>\n" |
| 3200 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3201 | "</tr><tr>\n" |
| 3202 | "<td class=\"active8\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3203 | "</tr><tr>\n" |
| 3204 | "<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] | 3205 | "</tr><tr>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3206 | "<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] | 3207 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 3208 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3209 | "</td>" |
| 3210 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3211 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3212 | "", |
| 3213 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3214 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3215 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3216 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3217 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3218 | pid, relative_pid, global.nbproc, |
| 3219 | up / 86400, (up % 86400) / 3600, |
| 3220 | (up % 3600) / 60, (up % 60), |
| 3221 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3222 | global.rlimit_memmax ? " MB" : "", |
| 3223 | global.rlimit_nofile, |
| 3224 | global.maxsock, global.maxconn, global.maxpipes, |
| 3225 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3226 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3227 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3228 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3229 | /* scope_txt = search query, si->applet.ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3230 | memcpy(scope_txt, bo_ptr(si->ob->buf) + si->applet.ctx.stats.scope_str, si->applet.ctx.stats.scope_len); |
| 3231 | scope_txt[si->applet.ctx.stats.scope_len] = '\0'; |
| 3232 | |
| 3233 | chunk_appendf(&trash, |
Cyril Bonté | 5465684 | 2013-04-18 22:38:35 +0200 | [diff] [blame] | 3234 | "<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] | 3235 | uri->uri_prefix, |
| 3236 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3237 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3238 | (si->applet.ctx.stats.scope_len > 0) ? scope_txt : "", |
| 3239 | STAT_SCOPE_TXT_MAXLEN); |
| 3240 | |
| 3241 | /* scope_txt = search pattern + search query, si->applet.ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3242 | scope_txt[0] = 0; |
| 3243 | if (si->applet.ctx.stats.scope_len) { |
| 3244 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
| 3245 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si->ob->buf) + si->applet.ctx.stats.scope_str, si->applet.ctx.stats.scope_len); |
| 3246 | scope_txt[strlen(STAT_SCOPE_PATTERN) + si->applet.ctx.stats.scope_len] = 0; |
| 3247 | } |
| 3248 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3249 | if (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) |
| 3250 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3251 | "<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] | 3252 | uri->uri_prefix, |
| 3253 | "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3254 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3255 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3256 | else |
| 3257 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3258 | "<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] | 3259 | uri->uri_prefix, |
| 3260 | ";up", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3261 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3262 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3263 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3264 | if (uri->refresh > 0) { |
| 3265 | if (si->applet.ctx.stats.flags & STAT_NO_REFRESH) |
| 3266 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3267 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3268 | uri->uri_prefix, |
| 3269 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3270 | "", |
| 3271 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3272 | else |
| 3273 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3274 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3275 | uri->uri_prefix, |
| 3276 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3277 | ";norefresh", |
| 3278 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3279 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3280 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3281 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3282 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3283 | uri->uri_prefix, |
| 3284 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3285 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3286 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3287 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3288 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3289 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3290 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 3291 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3292 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3293 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3294 | chunk_appendf(&trash, |
| 3295 | "</ul></td>" |
| 3296 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3297 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3298 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3299 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3300 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3301 | "</ul>" |
| 3302 | "</td>" |
| 3303 | "</tr></table>\n" |
| 3304 | "" |
| 3305 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3306 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3307 | if (si->applet.ctx.stats.st_code) { |
| 3308 | switch (si->applet.ctx.stats.st_code) { |
| 3309 | case STAT_STATUS_DONE: |
| 3310 | chunk_appendf(&trash, |
| 3311 | "<p><div class=active3>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3312 | "<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] | 3313 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3314 | "</div>\n", uri->uri_prefix, |
| 3315 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3316 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3317 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3318 | break; |
| 3319 | case STAT_STATUS_NONE: |
| 3320 | chunk_appendf(&trash, |
| 3321 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3322 | "<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] | 3323 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3324 | "</div>\n", uri->uri_prefix, |
| 3325 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3326 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3327 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3328 | break; |
| 3329 | case STAT_STATUS_PART: |
| 3330 | chunk_appendf(&trash, |
| 3331 | "<p><div class=active2>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3332 | "<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] | 3333 | "Action partially processed.<br>" |
| 3334 | "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] | 3335 | "</div>\n", uri->uri_prefix, |
| 3336 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3337 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3338 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3339 | break; |
| 3340 | case STAT_STATUS_ERRP: |
| 3341 | chunk_appendf(&trash, |
| 3342 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3343 | "<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] | 3344 | "Action not processed because of invalid parameters." |
| 3345 | "<ul>" |
| 3346 | "<li>The action is maybe unknown.</li>" |
| 3347 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3348 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3349 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3350 | "</div>\n", uri->uri_prefix, |
| 3351 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3352 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3353 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3354 | break; |
| 3355 | case STAT_STATUS_EXCD: |
| 3356 | chunk_appendf(&trash, |
| 3357 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3358 | "<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] | 3359 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3360 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3361 | "</div>\n", uri->uri_prefix, |
| 3362 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3363 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3364 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3365 | break; |
| 3366 | case STAT_STATUS_DENY: |
| 3367 | chunk_appendf(&trash, |
| 3368 | "<p><div class=active0>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3369 | "<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] | 3370 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3371 | "</div>\n", uri->uri_prefix, |
| 3372 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3373 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3374 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3375 | break; |
| 3376 | default: |
| 3377 | chunk_appendf(&trash, |
Simon Horman | 8c3d0be | 2013-11-25 10:46:40 +0900 | [diff] [blame] | 3378 | "<p><div class=active8>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3379 | "<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] | 3380 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 3381 | "</div>\n", uri->uri_prefix, |
| 3382 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3383 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3384 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3385 | } |
| 3386 | chunk_appendf(&trash, "<p>\n"); |
| 3387 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3388 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3389 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3390 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3391 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3392 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3393 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3394 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3395 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3396 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3397 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3398 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3399 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
| 3400 | * are ignored for CSV format (hence <uri> may be NULL there). The xprt_ctx must |
| 3401 | * have been zeroed first, and the flags properly set. It returns 0 if it had to |
| 3402 | * stop writing data and an I/O is needed, 1 if the dump is finished and the |
| 3403 | * session must be closed, or -1 in case of any error. This function is used by |
| 3404 | * both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3405 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3406 | 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] | 3407 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3408 | struct channel *rep = si->ib; |
| 3409 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3410 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3411 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3412 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3413 | switch (si->conn->xprt_st) { |
| 3414 | case STAT_ST_INIT: |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3415 | si->conn->xprt_st = STAT_ST_HEAD; /* let's start producing data */ |
| 3416 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3417 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3418 | case STAT_ST_HEAD: |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3419 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3420 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3421 | else |
| 3422 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3423 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3424 | if (bi_putchk(rep, &trash) == -1) |
| 3425 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3426 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3427 | si->conn->xprt_st = STAT_ST_INFO; |
| 3428 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3429 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3430 | case STAT_ST_INFO: |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3431 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3432 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3433 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3434 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3435 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3436 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3437 | si->applet.ctx.stats.px = proxy; |
| 3438 | si->applet.ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3439 | si->conn->xprt_st = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3440 | /* fall through */ |
| 3441 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3442 | case STAT_ST_LIST: |
| 3443 | /* dump proxies */ |
| 3444 | while (si->applet.ctx.stats.px) { |
| 3445 | if (buffer_almost_full(rep->buf)) |
| 3446 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3447 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3448 | px = si->applet.ctx.stats.px; |
| 3449 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 3450 | 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] | 3451 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3452 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3453 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3454 | si->applet.ctx.stats.px = px->next; |
| 3455 | si->applet.ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3456 | } |
| 3457 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3458 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3459 | si->conn->xprt_st = STAT_ST_END; |
| 3460 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3461 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3462 | case STAT_ST_END: |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3463 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3464 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3465 | if (bi_putchk(rep, &trash) == -1) |
| 3466 | return 0; |
| 3467 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3468 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3469 | si->conn->xprt_st = STAT_ST_FIN; |
| 3470 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 3471 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3472 | case STAT_ST_FIN: |
| 3473 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3474 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3475 | default: |
| 3476 | /* unknown state ! */ |
| 3477 | si->conn->xprt_st = STAT_ST_FIN; |
| 3478 | return -1; |
| 3479 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3480 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3481 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3482 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 3483 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
| 3484 | * si->applet.st0 becomes non-zero once the transfer is finished. The handler |
| 3485 | * automatically unregisters itself once transfer is complete. |
| 3486 | */ |
| 3487 | static void http_stats_io_handler(struct stream_interface *si) |
| 3488 | { |
| 3489 | struct session *s = si->conn->xprt_ctx; |
| 3490 | struct channel *req = si->ob; |
| 3491 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3492 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3493 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 3494 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3495 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3496 | /* check that the output is not closed */ |
| 3497 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
| 3498 | si->applet.st0 = 1; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3499 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3500 | if (!si->applet.st0) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3501 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) { |
Willy Tarreau | 1facd6d | 2012-12-22 22:03:39 +0100 | [diff] [blame] | 3502 | si->applet.st0 = 1; |
| 3503 | si_shutw(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3504 | } |
| 3505 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3506 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3507 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 3508 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3509 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3510 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && si->applet.st0) { |
| 3511 | si_shutr(si); |
| 3512 | res->flags |= CF_READ_NULL; |
| 3513 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3514 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3515 | /* update all other flags and resync with the other side */ |
| 3516 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3517 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3518 | /* we don't want to expire timeouts while we're processing requests */ |
| 3519 | si->ib->rex = TICK_ETERNITY; |
| 3520 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3521 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3522 | out: |
| 3523 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 3524 | /* check that we have released everything then unregister */ |
| 3525 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3526 | } |
| 3527 | } |
| 3528 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3529 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3530 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 3531 | { |
| 3532 | if (!conn->ctrl) |
| 3533 | return "NONE"; |
| 3534 | return conn->ctrl->name; |
| 3535 | } |
| 3536 | |
| 3537 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 3538 | { |
| 3539 | static char ptr[17]; |
| 3540 | |
| 3541 | if (!conn->xprt) |
| 3542 | return "NONE"; |
| 3543 | |
| 3544 | if (conn->xprt == &raw_sock) |
| 3545 | return "RAW"; |
| 3546 | |
| 3547 | #ifdef USE_OPENSSL |
| 3548 | if (conn->xprt == &ssl_sock) |
| 3549 | return "SSL"; |
| 3550 | #endif |
| 3551 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 3552 | return ptr; |
| 3553 | } |
| 3554 | |
| 3555 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 3556 | { |
| 3557 | static char ptr[17]; |
| 3558 | |
| 3559 | if (!conn->data) |
| 3560 | return "NONE"; |
| 3561 | |
| 3562 | if (conn->data == &sess_conn_cb) |
| 3563 | return "SESS"; |
| 3564 | |
| 3565 | if (conn->data == &si_conn_cb) |
| 3566 | return "STRM"; |
| 3567 | |
| 3568 | if (conn->data == &check_conn_cb) |
| 3569 | return "CHCK"; |
| 3570 | |
| 3571 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 3572 | return ptr; |
| 3573 | } |
| 3574 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 3575 | /* This function dumps a complete session state onto the stream interface's |
| 3576 | * read buffer. The xprt_ctx must have been zeroed first, and the flags |
| 3577 | * properly set. The session has to be set in xprt_ctx.sess.target. It returns |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3578 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 3579 | * 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] | 3580 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3581 | 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] | 3582 | { |
| 3583 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3584 | extern const char *monthname[12]; |
| 3585 | char pn[INET6_ADDRSTRLEN]; |
| 3586 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3587 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3588 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3589 | if (si->applet.ctx.sess.section > 0 && si->applet.ctx.sess.uid != sess->uniq_id) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3590 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3591 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 3592 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3593 | return 0; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3594 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3595 | si->applet.ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3596 | return 1; |
| 3597 | } |
| 3598 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3599 | switch (si->applet.ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3600 | case 0: /* main status of the session */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3601 | si->applet.ctx.sess.uid = sess->uniq_id; |
| 3602 | si->applet.ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3603 | /* fall through */ |
| 3604 | |
| 3605 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3606 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3607 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3608 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3609 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3610 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 3611 | 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] | 3612 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 3613 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3614 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3615 | switch (addr_to_str(&sess->si[0].conn->addr.from, pn, sizeof(pn))) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3616 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3617 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3618 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3619 | pn, get_host_port(&sess->si[0].conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3620 | break; |
| 3621 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3622 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3623 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3624 | default: |
| 3625 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3626 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3627 | break; |
| 3628 | } |
| 3629 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3630 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3631 | " 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] | 3632 | 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] | 3633 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3634 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3635 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3636 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 3637 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 3638 | sess->listener ? sess->listener->luid : 0); |
| 3639 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3640 | conn_get_to_addr(sess->si[0].conn); |
| 3641 | switch (addr_to_str(&sess->si[0].conn->addr.to, pn, sizeof(pn))) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3642 | case AF_INET: |
| 3643 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3644 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3645 | pn, get_host_port(&sess->si[0].conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3646 | break; |
| 3647 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3648 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3649 | break; |
| 3650 | default: |
| 3651 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3652 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3653 | break; |
| 3654 | } |
| 3655 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3656 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3657 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3658 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3659 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3660 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 3661 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3662 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3663 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3664 | conn_get_from_addr(sess->si[1].conn); |
| 3665 | switch (addr_to_str(&sess->si[1].conn->addr.from, pn, sizeof(pn))) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3666 | case AF_INET: |
| 3667 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3668 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3669 | pn, get_host_port(&sess->si[1].conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3670 | break; |
| 3671 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3672 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3673 | break; |
| 3674 | default: |
| 3675 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3676 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3677 | break; |
| 3678 | } |
| 3679 | |
| 3680 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3681 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3682 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 3683 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 3684 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3685 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3686 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3687 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3688 | conn_get_to_addr(sess->si[1].conn); |
| 3689 | switch (addr_to_str(&sess->si[1].conn->addr.to, pn, sizeof(pn))) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3690 | case AF_INET: |
| 3691 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3692 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3693 | pn, get_host_port(&sess->si[1].conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3694 | break; |
| 3695 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3696 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3697 | break; |
| 3698 | default: |
| 3699 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3700 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3701 | break; |
| 3702 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3703 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3704 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3705 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3706 | sess->task, |
| 3707 | sess->task->state, |
| 3708 | sess->task->nice, sess->task->calls, |
| 3709 | sess->task->expire ? |
| 3710 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 3711 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 3712 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3713 | task_in_rq(sess->task) ? ", running" : ""); |
| 3714 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3715 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3716 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3717 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 3718 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3719 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3720 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 3721 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 3722 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 3723 | |
| 3724 | chunk_appendf(&trash, |
| 3725 | " si[0]=%p (state=%s flags=0x%02x conn0=%p exp=%s, et=0x%03x)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3726 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3727 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3728 | sess->si[0].flags, |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3729 | sess->si[0].conn, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3730 | sess->si[0].exp ? |
| 3731 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 3732 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 3733 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3734 | sess->si[0].err_type); |
| 3735 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3736 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3737 | " si[1]=%p (state=%s flags=0x%02x conn1=%p exp=%s, et=0x%03x)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3738 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3739 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3740 | sess->si[1].flags, |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3741 | sess->si[1].conn, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3742 | sess->si[1].exp ? |
| 3743 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 3744 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 3745 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3746 | sess->si[1].err_type); |
| 3747 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3748 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3749 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3750 | sess->si[0].conn, |
| 3751 | get_conn_ctrl_name(sess->si[0].conn), |
| 3752 | get_conn_xprt_name(sess->si[0].conn), |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3753 | get_conn_data_name(sess->si[0].conn), |
| 3754 | obj_type_name(sess->si[0].conn->target), |
| 3755 | obj_base_ptr(sess->si[0].conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3756 | |
| 3757 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3758 | " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n", |
Willy Tarreau | 1feca01 | 2012-11-19 18:15:19 +0100 | [diff] [blame] | 3759 | sess->si[0].conn->flags, |
| 3760 | sess->si[0].conn->t.sock.fd, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3761 | sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].spec_e : 0, |
| 3762 | sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].spec_p : 0, |
| 3763 | sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].updated : 0); |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3764 | |
| 3765 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3766 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3767 | sess->si[1].conn, |
| 3768 | get_conn_ctrl_name(sess->si[1].conn), |
| 3769 | get_conn_xprt_name(sess->si[1].conn), |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3770 | get_conn_data_name(sess->si[1].conn), |
| 3771 | obj_type_name(sess->si[1].conn->target), |
| 3772 | obj_base_ptr(sess->si[1].conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3773 | |
| 3774 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3775 | " flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n", |
Willy Tarreau | 1feca01 | 2012-11-19 18:15:19 +0100 | [diff] [blame] | 3776 | sess->si[1].conn->flags, |
| 3777 | sess->si[1].conn->t.sock.fd, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3778 | sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].spec_e : 0, |
| 3779 | sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].spec_p : 0, |
| 3780 | sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].updated : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3781 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3782 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3783 | " 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] | 3784 | " an_exp=%s", |
| 3785 | sess->req, |
| 3786 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3787 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3788 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3789 | sess->req->analyse_exp ? |
| 3790 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 3791 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3792 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3793 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3794 | " rex=%s", |
| 3795 | sess->req->rex ? |
| 3796 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 3797 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3798 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3799 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3800 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3801 | " 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] | 3802 | sess->req->wex ? |
| 3803 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 3804 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3805 | sess->req->buf, |
| 3806 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3807 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3808 | sess->txn.req.next, sess->req->buf->i, |
| 3809 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3810 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3811 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3812 | " 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] | 3813 | " an_exp=%s", |
| 3814 | sess->rep, |
| 3815 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3816 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3817 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3818 | sess->rep->analyse_exp ? |
| 3819 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 3820 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3821 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3822 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3823 | " rex=%s", |
| 3824 | sess->rep->rex ? |
| 3825 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 3826 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3827 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3828 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3829 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3830 | " 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] | 3831 | sess->rep->wex ? |
| 3832 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 3833 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3834 | sess->rep->buf, |
| 3835 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3836 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3837 | sess->txn.rsp.next, sess->rep->buf->i, |
| 3838 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3839 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3840 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3841 | return 0; |
| 3842 | |
| 3843 | /* use other states to dump the contents */ |
| 3844 | } |
| 3845 | /* end of dump */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3846 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3847 | si->applet.ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3848 | return 1; |
| 3849 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3850 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 3851 | /* This function dumps all sessions' states onto the stream interface's |
| 3852 | * read buffer. The xprt_ctx must have been zeroed first, and the flags |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3853 | * properly set. It returns 0 if the output buffer is full and it needs |
| 3854 | * to be called again, otherwise non-zero. It is designed to be called |
| 3855 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3856 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 3857 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3858 | { |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 3859 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3860 | /* If we're forced to shut down, we might have to remove our |
| 3861 | * reference to the last session being dumped. |
| 3862 | */ |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3863 | if (si->conn->xprt_st == STAT_ST_LIST) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3864 | if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) { |
| 3865 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3866 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3867 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3868 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 3869 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3870 | } |
| 3871 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3872 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3873 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3874 | switch (si->conn->xprt_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3875 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3876 | /* the function had not been called yet, let's prepare the |
| 3877 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3878 | * pointer to the first in the global list. When a target |
| 3879 | * session is being destroyed, it is responsible for updating |
| 3880 | * this pointer. We know we have reached the end when this |
| 3881 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3882 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3883 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
| 3884 | si->applet.ctx.sess.bref.ref = sessions.n; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3885 | si->conn->xprt_st = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3886 | /* fall through */ |
| 3887 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3888 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3889 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3890 | if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) { |
| 3891 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3892 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3893 | } |
| 3894 | |
| 3895 | /* and start from where we stopped */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3896 | while (si->applet.ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 3897 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3898 | struct session *curr_sess; |
| 3899 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3900 | curr_sess = LIST_ELEM(si->applet.ctx.sess.bref.ref, struct session *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3901 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3902 | if (si->applet.ctx.sess.target) { |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3903 | if (si->applet.ctx.sess.target != (void *)-1 && si->applet.ctx.sess.target != curr_sess) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3904 | goto next_sess; |
| 3905 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3906 | LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3907 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3908 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3909 | return 0; |
| 3910 | |
| 3911 | /* session dump complete */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3912 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3913 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3914 | if (si->applet.ctx.sess.target != (void *)-1) { |
| 3915 | si->applet.ctx.sess.target = NULL; |
| 3916 | break; |
| 3917 | } |
| 3918 | else |
| 3919 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3920 | } |
| 3921 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3922 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3923 | "%p: proto=%s", |
| 3924 | curr_sess, |
| 3925 | curr_sess->listener->proto->name); |
| 3926 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3927 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3928 | switch (addr_to_str(&curr_sess->si[0].conn->addr.from, pn, sizeof(pn))) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 3929 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3930 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3931 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3932 | " src=%s:%d fe=%s be=%s srv=%s", |
| 3933 | pn, |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3934 | get_host_port(&curr_sess->si[0].conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3935 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3936 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 3937 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3938 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3939 | break; |
| 3940 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3941 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3942 | " src=unix:%d fe=%s be=%s srv=%s", |
| 3943 | curr_sess->listener->luid, |
| 3944 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3945 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 3946 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3947 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3948 | break; |
| 3949 | } |
| 3950 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3951 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 3952 | " ts=%02x age=%s calls=%d", |
| 3953 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 3954 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 3955 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3956 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3957 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 3958 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3959 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3960 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3961 | curr_sess->req->analysers, |
| 3962 | curr_sess->req->rex ? |
| 3963 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 3964 | TICKS_TO_MS(1000)) : ""); |
| 3965 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3966 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3967 | ",wx=%s", |
| 3968 | curr_sess->req->wex ? |
| 3969 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 3970 | TICKS_TO_MS(1000)) : ""); |
| 3971 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3972 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3973 | ",ax=%s]", |
| 3974 | curr_sess->req->analyse_exp ? |
| 3975 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 3976 | TICKS_TO_MS(1000)) : ""); |
| 3977 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3978 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 3979 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3980 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3981 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3982 | curr_sess->rep->analysers, |
| 3983 | curr_sess->rep->rex ? |
| 3984 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 3985 | TICKS_TO_MS(1000)) : ""); |
| 3986 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3987 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3988 | ",wx=%s", |
| 3989 | curr_sess->rep->wex ? |
| 3990 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 3991 | TICKS_TO_MS(1000)) : ""); |
| 3992 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3993 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3994 | ",ax=%s]", |
| 3995 | curr_sess->rep->analyse_exp ? |
| 3996 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 3997 | TICKS_TO_MS(1000)) : ""); |
| 3998 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3999 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4000 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 4001 | curr_sess->si[0].state, |
| 4002 | curr_sess->si[0].flags, |
Willy Tarreau | 7f7ad91 | 2012-11-11 19:27:15 +0100 | [diff] [blame] | 4003 | curr_sess->si[0].conn->t.sock.fd, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4004 | curr_sess->si[0].exp ? |
| 4005 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 4006 | TICKS_TO_MS(1000)) : ""); |
| 4007 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4008 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4009 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 4010 | curr_sess->si[1].state, |
| 4011 | curr_sess->si[1].flags, |
Willy Tarreau | 7f7ad91 | 2012-11-11 19:27:15 +0100 | [diff] [blame] | 4012 | curr_sess->si[1].conn->t.sock.fd, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4013 | curr_sess->si[1].exp ? |
| 4014 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 4015 | TICKS_TO_MS(1000)) : ""); |
| 4016 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4017 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4018 | " exp=%s", |
| 4019 | curr_sess->task->expire ? |
| 4020 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 4021 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 4022 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4023 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 4024 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4025 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4026 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4027 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 4028 | /* let's try again later from this session. We add ourselves into |
| 4029 | * this session's users so that it can remove us upon termination. |
| 4030 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4031 | LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4032 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4033 | } |
| 4034 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4035 | next_sess: |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4036 | si->applet.ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4037 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4038 | |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 4039 | if (si->applet.ctx.sess.target && si->applet.ctx.sess.target != (void *)-1) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4040 | /* specified session not found */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4041 | if (si->applet.ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4042 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4043 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4044 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4045 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4046 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4047 | return 0; |
| 4048 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4049 | si->applet.ctx.sess.target = NULL; |
| 4050 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 4051 | return 1; |
| 4052 | } |
| 4053 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4054 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4055 | /* fall through */ |
| 4056 | |
| 4057 | default: |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4058 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 4059 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4060 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 4061 | } |
| 4062 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4063 | /* This is called when the stream interface is closed. For instance, upon an |
| 4064 | * external abort, we won't call the i/o handler anymore so we may need to |
| 4065 | * remove back references to the session currently being dumped. |
| 4066 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 4067 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4068 | { |
| 4069 | if (si->applet.st0 == STAT_CLI_O_SESS && si->conn->xprt_st == STAT_ST_LIST) { |
| 4070 | if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) |
| 4071 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 4072 | } |
| 4073 | } |
| 4074 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4075 | /* This function is used to either dump tables states (when action is set |
| 4076 | * to STAT_CLI_O_TAB) or clear tables (when action is STAT_CLI_O_CLR). |
| 4077 | * The xprt_ctx must have been zeroed first, and the flags properly set. |
| 4078 | * It returns 0 if the output buffer is full and it needs to be called |
| 4079 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4080 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4081 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4082 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4083 | struct session *s = si->conn->xprt_ctx; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4084 | struct ebmb_node *eb; |
| 4085 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4086 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 4087 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4088 | |
| 4089 | /* |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4090 | * We have 3 possible states in si->conn->xprt_st : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4091 | * - STAT_ST_INIT : the first call |
| 4092 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4093 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4094 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4095 | * and the entry pointer points to the next entry to be dumped, |
| 4096 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4097 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4098 | * data though. |
| 4099 | */ |
| 4100 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4101 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4102 | /* in case of abort, remove any refcount we might have set on an entry */ |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4103 | if (si->conn->xprt_st == STAT_ST_LIST) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4104 | si->applet.ctx.table.entry->ref_cnt--; |
| 4105 | stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry); |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 4106 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4107 | return 1; |
| 4108 | } |
| 4109 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4110 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4111 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4112 | while (si->conn->xprt_st != STAT_ST_FIN) { |
| 4113 | switch (si->conn->xprt_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4114 | case STAT_ST_INIT: |
| 4115 | si->applet.ctx.table.proxy = si->applet.ctx.table.target; |
| 4116 | if (!si->applet.ctx.table.proxy) |
| 4117 | si->applet.ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4118 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4119 | si->applet.ctx.table.entry = NULL; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4120 | si->conn->xprt_st = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4121 | break; |
| 4122 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4123 | case STAT_ST_INFO: |
| 4124 | if (!si->applet.ctx.table.proxy || |
| 4125 | (si->applet.ctx.table.target && |
| 4126 | si->applet.ctx.table.proxy != si->applet.ctx.table.target)) { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4127 | si->conn->xprt_st = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4128 | break; |
| 4129 | } |
| 4130 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4131 | if (si->applet.ctx.table.proxy->table.size) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4132 | if (show && !stats_dump_table_head_to_buffer(&trash, si, si->applet.ctx.table.proxy, |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4133 | si->applet.ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4134 | return 0; |
| 4135 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4136 | if (si->applet.ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 4137 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4138 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4139 | eb = ebmb_first(&si->applet.ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4140 | if (eb) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4141 | si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 4142 | si->applet.ctx.table.entry->ref_cnt++; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4143 | si->conn->xprt_st = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4144 | break; |
| 4145 | } |
| 4146 | } |
| 4147 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4148 | si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4149 | break; |
| 4150 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4151 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4152 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4153 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4154 | if (si->applet.ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4155 | /* we're filtering on some data contents */ |
| 4156 | void *ptr; |
| 4157 | long long data; |
| 4158 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4159 | dt = si->applet.ctx.table.data_type; |
| 4160 | ptr = stktable_data_ptr(&si->applet.ctx.table.proxy->table, |
| 4161 | si->applet.ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4162 | dt); |
| 4163 | |
| 4164 | data = 0; |
| 4165 | switch (stktable_data_types[dt].std_type) { |
| 4166 | case STD_T_SINT: |
| 4167 | data = stktable_data_cast(ptr, std_t_sint); |
| 4168 | break; |
| 4169 | case STD_T_UINT: |
| 4170 | data = stktable_data_cast(ptr, std_t_uint); |
| 4171 | break; |
| 4172 | case STD_T_ULL: |
| 4173 | data = stktable_data_cast(ptr, std_t_ull); |
| 4174 | break; |
| 4175 | case STD_T_FRQP: |
| 4176 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4177 | si->applet.ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4178 | break; |
| 4179 | } |
| 4180 | |
| 4181 | /* skip the entry if the data does not match the test and the value */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4182 | if ((data < si->applet.ctx.table.value && |
| 4183 | (si->applet.ctx.table.data_op == STD_OP_EQ || |
| 4184 | si->applet.ctx.table.data_op == STD_OP_GT || |
| 4185 | si->applet.ctx.table.data_op == STD_OP_GE)) || |
| 4186 | (data == si->applet.ctx.table.value && |
| 4187 | (si->applet.ctx.table.data_op == STD_OP_NE || |
| 4188 | si->applet.ctx.table.data_op == STD_OP_GT || |
| 4189 | si->applet.ctx.table.data_op == STD_OP_LT)) || |
| 4190 | (data > si->applet.ctx.table.value && |
| 4191 | (si->applet.ctx.table.data_op == STD_OP_EQ || |
| 4192 | si->applet.ctx.table.data_op == STD_OP_LT || |
| 4193 | si->applet.ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4194 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4195 | } |
| 4196 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4197 | if (show && !skip_entry && |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4198 | !stats_dump_table_entry_to_buffer(&trash, si, si->applet.ctx.table.proxy, |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 4199 | si->applet.ctx.table.entry)) |
| 4200 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4201 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4202 | si->applet.ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4203 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4204 | eb = ebmb_next(&si->applet.ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4205 | if (eb) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4206 | struct stksess *old = si->applet.ctx.table.entry; |
| 4207 | si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 4208 | if (show) |
| 4209 | stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, old); |
Willy Tarreau | 33fba6f | 2013-08-13 16:44:40 +0200 | [diff] [blame] | 4210 | else if (!skip_entry && !si->applet.ctx.table.entry->ref_cnt) |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 4211 | stksess_kill(&si->applet.ctx.table.proxy->table, old); |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4212 | si->applet.ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4213 | break; |
| 4214 | } |
| 4215 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4216 | |
| 4217 | if (show) |
| 4218 | stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry); |
| 4219 | else if (!skip_entry && !si->applet.ctx.table.entry->ref_cnt) |
| 4220 | stksess_kill(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry); |
| 4221 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4222 | si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4223 | si->conn->xprt_st = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4224 | break; |
| 4225 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4226 | case STAT_ST_END: |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4227 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4228 | break; |
| 4229 | } |
| 4230 | } |
| 4231 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4232 | } |
| 4233 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4234 | /* 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] | 4235 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 4236 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 4237 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 4238 | * lines are respected within the limit of 70 output chars. Lines that are |
| 4239 | * continuation of a previous truncated line begin with "+" instead of " " |
| 4240 | * after the offset. The new pointer is returned. |
| 4241 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4242 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 4243 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4244 | { |
| 4245 | int end; |
| 4246 | unsigned char c; |
| 4247 | |
| 4248 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4249 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4250 | return ptr; |
| 4251 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 4252 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4253 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4254 | while (ptr < len && ptr < bsize) { |
| 4255 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4256 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4257 | if (out->len > end - 2) |
| 4258 | break; |
| 4259 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4260 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4261 | if (out->len > end - 3) |
| 4262 | break; |
| 4263 | out->str[out->len++] = '\\'; |
| 4264 | switch (c) { |
| 4265 | case '\t': c = 't'; break; |
| 4266 | case '\n': c = 'n'; break; |
| 4267 | case '\r': c = 'r'; break; |
| 4268 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4269 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4270 | } |
| 4271 | out->str[out->len++] = c; |
| 4272 | } else { |
| 4273 | if (out->len > end - 5) |
| 4274 | break; |
| 4275 | out->str[out->len++] = '\\'; |
| 4276 | out->str[out->len++] = 'x'; |
| 4277 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 4278 | out->str[out->len++] = hextab[c & 0xF]; |
| 4279 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4280 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4281 | /* we had a line break, let's return now */ |
| 4282 | out->str[out->len++] = '\n'; |
| 4283 | *line = ptr; |
| 4284 | return ptr; |
| 4285 | } |
| 4286 | } |
| 4287 | /* we have an incomplete line, we return it as-is */ |
| 4288 | out->str[out->len++] = '\n'; |
| 4289 | return ptr; |
| 4290 | } |
| 4291 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4292 | /* This function dumps all captured errors onto the stream interface's |
| 4293 | * read buffer. The xprt_ctx must have been zeroed first, and the flags |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 4294 | * properly set. It returns 0 if the output buffer is full and it needs |
| 4295 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4296 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4297 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4298 | { |
| 4299 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4300 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4301 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4302 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4303 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4304 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4305 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4306 | if (!si->applet.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4307 | /* the function had not been called yet, let's prepare the |
| 4308 | * buffer for a response. |
| 4309 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4310 | struct tm tm; |
| 4311 | |
| 4312 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4313 | 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] | 4314 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4315 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 4316 | error_snapshot_id); |
| 4317 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4318 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4319 | /* Socket buffer full. Let's try again later from the same point */ |
| 4320 | return 0; |
| 4321 | } |
| 4322 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4323 | si->applet.ctx.errors.px = proxy; |
| 4324 | si->applet.ctx.errors.buf = 0; |
| 4325 | si->applet.ctx.errors.bol = 0; |
| 4326 | si->applet.ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4327 | } |
| 4328 | |
| 4329 | /* we have two inner loops here, one for the proxy, the other one for |
| 4330 | * the buffer. |
| 4331 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4332 | while (si->applet.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4333 | struct error_snapshot *es; |
| 4334 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4335 | if (si->applet.ctx.errors.buf == 0) |
| 4336 | es = &si->applet.ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4337 | else |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4338 | es = &si->applet.ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4339 | |
| 4340 | if (!es->when.tv_sec) |
| 4341 | goto next; |
| 4342 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4343 | if (si->applet.ctx.errors.iid >= 0 && |
| 4344 | si->applet.ctx.errors.px->uuid != si->applet.ctx.errors.iid && |
| 4345 | es->oe->uuid != si->applet.ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4346 | goto next; |
| 4347 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4348 | if (si->applet.ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4349 | /* just print headers now */ |
| 4350 | |
| 4351 | char pn[INET6_ADDRSTRLEN]; |
| 4352 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4353 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4354 | |
| 4355 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4356 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4357 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4358 | 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] | 4359 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4360 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 4361 | case AF_INET: |
| 4362 | case AF_INET6: |
| 4363 | port = get_host_port(&es->src); |
| 4364 | break; |
| 4365 | default: |
| 4366 | port = 0; |
| 4367 | } |
| 4368 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4369 | switch (si->applet.ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4370 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4371 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4372 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4373 | " backend %s (#%d)", |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4374 | si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4375 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 4376 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4377 | break; |
| 4378 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4379 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4380 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4381 | " frontend %s (#%d)", |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4382 | si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4383 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4384 | break; |
| 4385 | } |
| 4386 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4387 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4388 | ", server %s (#%d), event #%u\n" |
| 4389 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 4390 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 4391 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 4392 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 4393 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 4394 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 4395 | es->ev_id, |
| 4396 | pn, port, es->sid, es->s_flags, |
| 4397 | es->state, es->m_flags, es->t_flags, |
| 4398 | es->m_clen, es->m_blen, |
| 4399 | es->b_flags, es->b_out, es->b_tot, |
| 4400 | es->len, es->b_wrap, es->pos); |
| 4401 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4402 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4403 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4404 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4405 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4406 | si->applet.ctx.errors.ptr = 0; |
| 4407 | si->applet.ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4408 | } |
| 4409 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4410 | if (si->applet.ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4411 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4412 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4413 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4414 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4415 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4416 | goto next; |
| 4417 | } |
| 4418 | |
| 4419 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4420 | while (si->applet.ctx.errors.ptr < es->len && si->applet.ctx.errors.ptr < sizeof(es->buf)) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4421 | int newptr; |
| 4422 | int newline; |
| 4423 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4424 | newline = si->applet.ctx.errors.bol; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4425 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, si->applet.ctx.errors.ptr); |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4426 | if (newptr == si->applet.ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4427 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4428 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4429 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4430 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4431 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4432 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4433 | si->applet.ctx.errors.ptr = newptr; |
| 4434 | si->applet.ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4435 | }; |
| 4436 | next: |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4437 | si->applet.ctx.errors.bol = 0; |
| 4438 | si->applet.ctx.errors.ptr = -1; |
| 4439 | si->applet.ctx.errors.buf++; |
| 4440 | if (si->applet.ctx.errors.buf > 1) { |
| 4441 | si->applet.ctx.errors.buf = 0; |
| 4442 | si->applet.ctx.errors.px = si->applet.ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4443 | } |
| 4444 | } |
| 4445 | |
| 4446 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4447 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4448 | } |
| 4449 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4450 | /* parse the "level" argument on the bind lines */ |
| 4451 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 4452 | { |
| 4453 | if (!*args[cur_arg + 1]) { |
| 4454 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 4455 | return ERR_ALERT | ERR_FATAL; |
| 4456 | } |
| 4457 | |
| 4458 | if (!strcmp(args[cur_arg+1], "user")) |
| 4459 | conf->level = ACCESS_LVL_USER; |
| 4460 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 4461 | conf->level = ACCESS_LVL_OPER; |
| 4462 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 4463 | conf->level = ACCESS_LVL_ADMIN; |
| 4464 | else { |
| 4465 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 4466 | args[cur_arg], args[cur_arg+1]); |
| 4467 | return ERR_ALERT | ERR_FATAL; |
| 4468 | } |
| 4469 | |
| 4470 | return 0; |
| 4471 | } |
| 4472 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4473 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4474 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4475 | .name = "<STATS>", /* used for logging */ |
| 4476 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 4477 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4478 | }; |
| 4479 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4480 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4481 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4482 | .name = "<CLI>", /* used for logging */ |
| 4483 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4484 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4485 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4486 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 4487 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4488 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 4489 | { 0, NULL, NULL }, |
| 4490 | }}; |
| 4491 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4492 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 4493 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 4494 | { NULL, NULL, 0 }, |
| 4495 | }}; |
| 4496 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4497 | __attribute__((constructor)) |
| 4498 | static void __dumpstats_module_init(void) |
| 4499 | { |
| 4500 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4501 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4502 | } |
| 4503 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4504 | /* |
| 4505 | * Local variables: |
| 4506 | * c-indent-level: 8 |
| 4507 | * c-basic-offset: 8 |
| 4508 | * End: |
| 4509 | */ |