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 | |
| 340 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 341 | unsigned int low, high; |
| 342 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 343 | if (strcmp(args[cur_arg], "all") == 0) { |
| 344 | set = 0; |
| 345 | break; |
| 346 | } |
| 347 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 348 | set |= 0x55555555; |
| 349 | } |
| 350 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 351 | set |= 0xAAAAAAAA; |
| 352 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 353 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 354 | char *dash = strchr(args[cur_arg], '-'); |
| 355 | |
| 356 | low = high = str2uic(args[cur_arg]); |
| 357 | if (dash) |
| 358 | high = str2uic(dash + 1); |
| 359 | |
| 360 | if (high < low) { |
| 361 | unsigned int swap = low; |
| 362 | low = high; |
| 363 | high = swap; |
| 364 | } |
| 365 | |
| 366 | if (low < 1 || high > 32) { |
| 367 | memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n", |
| 368 | args[0], args[1]); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 369 | return -1; |
| 370 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 371 | |
| 372 | while (low <= high) |
| 373 | set |= 1 << (low++ - 1); |
| 374 | } |
| 375 | else { |
| 376 | memprintf(err, |
| 377 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 378 | args[0], args[1]); |
| 379 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 380 | } |
| 381 | cur_arg++; |
| 382 | } |
| 383 | global.stats_fe->bind_proc = set; |
| 384 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 385 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 386 | 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] | 387 | return -1; |
| 388 | } |
| 389 | return 0; |
| 390 | } |
| 391 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 392 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 393 | * for clearing it if needed. |
| 394 | */ |
| 395 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 396 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 397 | chunk_appendf(&trash, |
| 398 | "# pxname,svname," |
| 399 | "qcur,qmax," |
| 400 | "scur,smax,slim,stot," |
| 401 | "bin,bout," |
| 402 | "dreq,dresp," |
| 403 | "ereq,econ,eresp," |
| 404 | "wretr,wredis," |
| 405 | "status,weight,act,bck," |
| 406 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 407 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 408 | "rate,rate_lim,rate_max," |
| 409 | "check_status,check_code,check_duration," |
| 410 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 411 | "req_rate,req_rate_max,req_tot," |
| 412 | "cli_abrt,srv_abrt," |
| 413 | "comp_in,comp_out,comp_byp,comp_rsp," |
| 414 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 415 | } |
| 416 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 417 | /* print a string of text buffer to <out>. The format is : |
| 418 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 419 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 420 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 421 | */ |
| 422 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 423 | { |
| 424 | unsigned char c; |
| 425 | int ptr = 0; |
| 426 | |
| 427 | while (buf[ptr] && ptr < bsize) { |
| 428 | c = buf[ptr]; |
| 429 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 430 | if (out->len > out->size - 1) |
| 431 | break; |
| 432 | out->str[out->len++] = c; |
| 433 | } |
| 434 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 435 | if (out->len > out->size - 2) |
| 436 | break; |
| 437 | out->str[out->len++] = '\\'; |
| 438 | switch (c) { |
| 439 | case ' ': c = ' '; break; |
| 440 | case '\t': c = 't'; break; |
| 441 | case '\n': c = 'n'; break; |
| 442 | case '\r': c = 'r'; break; |
| 443 | case '\e': c = 'e'; break; |
| 444 | case '\\': c = '\\'; break; |
| 445 | } |
| 446 | out->str[out->len++] = c; |
| 447 | } |
| 448 | else { |
| 449 | if (out->len > out->size - 4) |
| 450 | break; |
| 451 | out->str[out->len++] = '\\'; |
| 452 | out->str[out->len++] = 'x'; |
| 453 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 454 | out->str[out->len++] = hextab[c & 0xF]; |
| 455 | } |
| 456 | ptr++; |
| 457 | } |
| 458 | |
| 459 | return ptr; |
| 460 | } |
| 461 | |
| 462 | /* print a buffer in hexa. |
| 463 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 464 | */ |
| 465 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 466 | { |
| 467 | unsigned char c; |
| 468 | int ptr = 0; |
| 469 | |
| 470 | while (ptr < bsize) { |
| 471 | c = buf[ptr]; |
| 472 | |
| 473 | if (out->len > out->size - 2) |
| 474 | break; |
| 475 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 476 | out->str[out->len++] = hextab[c & 0xF]; |
| 477 | |
| 478 | ptr++; |
| 479 | } |
| 480 | return ptr; |
| 481 | } |
| 482 | |
| 483 | /* Dump the status of a table to a stream interface's |
| 484 | * read buffer. It returns 0 if the output buffer is full |
| 485 | * and needs to be called again, otherwise non-zero. |
| 486 | */ |
| 487 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 488 | struct proxy *proxy, struct proxy *target) |
| 489 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 490 | struct session *s = si->conn->xprt_ctx; |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 491 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 492 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 493 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 494 | |
| 495 | /* any other information should be dumped here */ |
| 496 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 497 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 498 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 499 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 500 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 501 | return 0; |
| 502 | |
| 503 | return 1; |
| 504 | } |
| 505 | |
| 506 | /* Dump the a table entry to a stream interface's |
| 507 | * read buffer. It returns 0 if the output buffer is full |
| 508 | * and needs to be called again, otherwise non-zero. |
| 509 | */ |
| 510 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 511 | struct proxy *proxy, struct stksess *entry) |
| 512 | { |
| 513 | int dt; |
| 514 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 515 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 516 | |
| 517 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 518 | char addr[INET_ADDRSTRLEN]; |
| 519 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 520 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 521 | } |
| 522 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 523 | char addr[INET6_ADDRSTRLEN]; |
| 524 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 525 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 526 | } |
| 527 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 528 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 529 | } |
| 530 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 531 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 532 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 533 | } |
| 534 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 535 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 536 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 537 | } |
| 538 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 539 | 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] | 540 | |
| 541 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 542 | void *ptr; |
| 543 | |
| 544 | if (proxy->table.data_ofs[dt] == 0) |
| 545 | continue; |
| 546 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 547 | 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] | 548 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 549 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 550 | |
| 551 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 552 | switch (stktable_data_types[dt].std_type) { |
| 553 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 554 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 555 | break; |
| 556 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 557 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 558 | break; |
| 559 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 560 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 561 | break; |
| 562 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 563 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 564 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 565 | proxy->table.data_arg[dt].u)); |
| 566 | break; |
| 567 | } |
| 568 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 569 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 570 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 571 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 572 | return 0; |
| 573 | |
| 574 | return 1; |
| 575 | } |
| 576 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 577 | 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] | 578 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 579 | struct session *s = si->conn->xprt_ctx; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 580 | struct proxy *px = si->applet.ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 581 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 582 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 583 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 584 | long long value; |
| 585 | int data_type; |
| 586 | void *ptr; |
| 587 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 588 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 589 | si->applet.st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 590 | |
| 591 | if (!*args[4]) { |
| 592 | si->applet.ctx.cli.msg = "Key value expected\n"; |
| 593 | si->applet.st0 = STAT_CLI_PRINT; |
| 594 | return; |
| 595 | } |
| 596 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 597 | switch (px->table.type) { |
| 598 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 599 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 600 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 601 | break; |
| 602 | case STKTABLE_TYPE_IPV6: |
| 603 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 604 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 605 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 606 | case STKTABLE_TYPE_INTEGER: |
| 607 | { |
| 608 | char *endptr; |
| 609 | unsigned long val; |
| 610 | errno = 0; |
| 611 | val = strtoul(args[4], &endptr, 10); |
| 612 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 613 | (errno != 0 && val == 0) || endptr == args[4] || |
| 614 | val > 0xffffffff) { |
| 615 | si->applet.ctx.cli.msg = "Invalid key\n"; |
| 616 | si->applet.st0 = STAT_CLI_PRINT; |
| 617 | return; |
| 618 | } |
| 619 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 620 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 621 | break; |
| 622 | } |
| 623 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 624 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 625 | static_table_key->key = args[4]; |
| 626 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 627 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 628 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 629 | switch (action) { |
| 630 | case STAT_CLI_O_TAB: |
| 631 | si->applet.ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n"; |
| 632 | break; |
| 633 | case STAT_CLI_O_CLR: |
| 634 | si->applet.ctx.cli.msg = "Removing keys from ip tables of type other than ip, ipv6, string and integer is not supported\n"; |
| 635 | break; |
| 636 | default: |
| 637 | si->applet.ctx.cli.msg = "Unknown action\n"; |
| 638 | break; |
| 639 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 640 | si->applet.st0 = STAT_CLI_PRINT; |
| 641 | return; |
| 642 | } |
| 643 | |
| 644 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 645 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 646 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 647 | si->applet.st0 = STAT_CLI_PRINT; |
| 648 | return; |
| 649 | } |
| 650 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 651 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 652 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 653 | switch (action) { |
| 654 | case STAT_CLI_O_TAB: |
| 655 | if (!ts) |
| 656 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 657 | chunk_reset(&trash); |
| 658 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 659 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 660 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 661 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 662 | |
| 663 | case STAT_CLI_O_CLR: |
| 664 | if (!ts) |
| 665 | return; |
| 666 | if (ts->ref_cnt) { |
| 667 | /* don't delete an entry which is currently referenced */ |
| 668 | si->applet.ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 669 | si->applet.st0 = STAT_CLI_PRINT; |
| 670 | return; |
| 671 | } |
| 672 | stksess_kill(&px->table, ts); |
| 673 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 674 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 675 | case STAT_CLI_O_SET: |
| 676 | if (strncmp(args[5], "data.", 5) != 0) { |
| 677 | si->applet.ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 678 | si->applet.st0 = STAT_CLI_PRINT; |
| 679 | return; |
| 680 | } |
| 681 | |
| 682 | data_type = stktable_get_data_type(args[5] + 5); |
| 683 | if (data_type < 0) { |
| 684 | si->applet.ctx.cli.msg = "Unknown data type\n"; |
| 685 | si->applet.st0 = STAT_CLI_PRINT; |
| 686 | return; |
| 687 | } |
| 688 | |
| 689 | if (!px->table.data_ofs[data_type]) { |
| 690 | si->applet.ctx.cli.msg = "Data type not stored in this table\n"; |
| 691 | si->applet.st0 = STAT_CLI_PRINT; |
| 692 | return; |
| 693 | } |
| 694 | |
| 695 | if (!*args[6] || strl2llrc(args[6], strlen(args[6]), &value) != 0) { |
| 696 | si->applet.ctx.cli.msg = "Require a valid integer value to store\n"; |
| 697 | si->applet.st0 = STAT_CLI_PRINT; |
| 698 | return; |
| 699 | } |
| 700 | |
| 701 | if (ts) |
| 702 | stktable_touch(&px->table, ts, 1); |
| 703 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 704 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 705 | if (!ts) { |
| 706 | /* don't delete an entry which is currently referenced */ |
| 707 | si->applet.ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 708 | si->applet.st0 = STAT_CLI_PRINT; |
| 709 | return; |
| 710 | } |
| 711 | stktable_store(&px->table, ts, 1); |
| 712 | } |
| 713 | |
| 714 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 715 | switch (stktable_data_types[data_type].std_type) { |
| 716 | case STD_T_SINT: |
| 717 | stktable_data_cast(ptr, std_t_sint) = value; |
| 718 | break; |
| 719 | case STD_T_UINT: |
| 720 | stktable_data_cast(ptr, std_t_uint) = value; |
| 721 | break; |
| 722 | case STD_T_ULL: |
| 723 | stktable_data_cast(ptr, std_t_ull) = value; |
| 724 | break; |
| 725 | case STD_T_FRQP: |
| 726 | /* We only reset the previous value so that it slowly fades out */ |
| 727 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 728 | frqp->curr_tick = now_ms; |
| 729 | frqp->prev_ctr = value; |
| 730 | frqp->curr_ctr = 0; |
| 731 | break; |
| 732 | } |
| 733 | break; |
| 734 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 735 | default: |
| 736 | si->applet.ctx.cli.msg = "Unknown action\n"; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 737 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 738 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 739 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 740 | } |
| 741 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 742 | 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] | 743 | { |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 744 | if (action != STAT_CLI_O_TAB) { |
| 745 | si->applet.ctx.cli.msg = "content-based lookup is only supported with the \"show\" action"; |
| 746 | si->applet.st0 = STAT_CLI_PRINT; |
| 747 | return; |
| 748 | } |
| 749 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 750 | /* condition on stored data value */ |
| 751 | si->applet.ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 752 | if (si->applet.ctx.table.data_type < 0) { |
| 753 | si->applet.ctx.cli.msg = "Unknown data type\n"; |
| 754 | si->applet.st0 = STAT_CLI_PRINT; |
| 755 | return; |
| 756 | } |
| 757 | |
| 758 | if (!((struct proxy *)si->applet.ctx.table.target)->table.data_ofs[si->applet.ctx.table.data_type]) { |
| 759 | si->applet.ctx.cli.msg = "Data type not stored in this table\n"; |
| 760 | si->applet.st0 = STAT_CLI_PRINT; |
| 761 | return; |
| 762 | } |
| 763 | |
| 764 | si->applet.ctx.table.data_op = get_std_op(args[4]); |
| 765 | if (si->applet.ctx.table.data_op < 0) { |
| 766 | si->applet.ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 767 | si->applet.st0 = STAT_CLI_PRINT; |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &si->applet.ctx.table.value) != 0) { |
| 772 | si->applet.ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 773 | si->applet.st0 = STAT_CLI_PRINT; |
| 774 | return; |
| 775 | } |
| 776 | } |
| 777 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 778 | 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] | 779 | { |
| 780 | si->applet.ctx.table.data_type = -1; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 781 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | e17a8d0 | 2011-08-24 08:23:34 +0200 | [diff] [blame] | 782 | si->applet.ctx.table.target = NULL; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 783 | si->applet.ctx.table.proxy = NULL; |
| 784 | si->applet.ctx.table.entry = NULL; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 785 | si->applet.st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 786 | |
| 787 | if (*args[2]) { |
| 788 | si->applet.ctx.table.target = find_stktable(args[2]); |
| 789 | if (!si->applet.ctx.table.target) { |
| 790 | si->applet.ctx.cli.msg = "No such table\n"; |
| 791 | si->applet.st0 = STAT_CLI_PRINT; |
| 792 | return; |
| 793 | } |
| 794 | } |
| 795 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 796 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 797 | goto err_args; |
| 798 | return; |
| 799 | } |
| 800 | |
| 801 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 802 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 803 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 804 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 805 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 806 | goto err_args; |
| 807 | |
| 808 | return; |
| 809 | |
| 810 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 811 | switch (action) { |
| 812 | case STAT_CLI_O_TAB: |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 813 | 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] | 814 | break; |
| 815 | case STAT_CLI_O_CLR: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 816 | 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] | 817 | break; |
| 818 | default: |
| 819 | si->applet.ctx.cli.msg = "Unknown action\n"; |
| 820 | break; |
| 821 | } |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 822 | si->applet.st0 = STAT_CLI_PRINT; |
| 823 | } |
| 824 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 825 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 826 | * adequate error messages and returns NULL. This function also expects the session |
| 827 | * level to be admin. |
| 828 | */ |
| 829 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 830 | { |
| 831 | struct proxy *px; |
| 832 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 833 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 834 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 835 | si->applet.st0 = STAT_CLI_PRINT; |
| 836 | return NULL; |
| 837 | } |
| 838 | |
| 839 | if (!*arg) { |
| 840 | si->applet.ctx.cli.msg = "A frontend name is expected.\n"; |
| 841 | si->applet.st0 = STAT_CLI_PRINT; |
| 842 | return NULL; |
| 843 | } |
| 844 | |
| 845 | px = findproxy(arg, PR_CAP_FE); |
| 846 | if (!px) { |
| 847 | si->applet.ctx.cli.msg = "No such frontend.\n"; |
| 848 | si->applet.st0 = STAT_CLI_PRINT; |
| 849 | return NULL; |
| 850 | } |
| 851 | return px; |
| 852 | } |
| 853 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 854 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 855 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 856 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 857 | * the <arg> is modified to remove the '/'. |
| 858 | */ |
| 859 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 860 | { |
| 861 | struct proxy *px; |
| 862 | struct server *sv; |
| 863 | char *line; |
| 864 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 865 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 866 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 867 | si->applet.st0 = STAT_CLI_PRINT; |
| 868 | return NULL; |
| 869 | } |
| 870 | |
| 871 | /* split "backend/server" and make <line> point to server */ |
| 872 | for (line = arg; *line; line++) |
| 873 | if (*line == '/') { |
| 874 | *line++ = '\0'; |
| 875 | break; |
| 876 | } |
| 877 | |
| 878 | if (!*line || !*arg) { |
| 879 | si->applet.ctx.cli.msg = "Require 'backend/server'.\n"; |
| 880 | si->applet.st0 = STAT_CLI_PRINT; |
| 881 | return NULL; |
| 882 | } |
| 883 | |
| 884 | if (!get_backend_server(arg, line, &px, &sv)) { |
| 885 | si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 886 | si->applet.st0 = STAT_CLI_PRINT; |
| 887 | return NULL; |
| 888 | } |
| 889 | |
| 890 | if (px->state == PR_STSTOPPED) { |
| 891 | si->applet.ctx.cli.msg = "Proxy is disabled.\n"; |
| 892 | si->applet.st0 = STAT_CLI_PRINT; |
| 893 | return NULL; |
| 894 | } |
| 895 | |
| 896 | return sv; |
| 897 | } |
| 898 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 899 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 900 | * 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] | 901 | * 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] | 902 | * designating the function which will have to process the request, which can |
| 903 | * 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] | 904 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 905 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 906 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 907 | struct session *s = si->conn->xprt_ctx; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 908 | char *args[MAX_STATS_ARGS + 1]; |
| 909 | int arg; |
| 910 | |
| 911 | while (isspace((unsigned char)*line)) |
| 912 | line++; |
| 913 | |
| 914 | arg = 0; |
| 915 | args[arg] = line; |
| 916 | |
| 917 | while (*line && arg < MAX_STATS_ARGS) { |
| 918 | if (isspace((unsigned char)*line)) { |
| 919 | *line++ = '\0'; |
| 920 | |
| 921 | while (isspace((unsigned char)*line)) |
| 922 | line++; |
| 923 | |
| 924 | args[++arg] = line; |
| 925 | continue; |
| 926 | } |
| 927 | |
| 928 | line++; |
| 929 | } |
| 930 | |
| 931 | while (++arg <= MAX_STATS_ARGS) |
| 932 | args[arg] = line; |
| 933 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 934 | si->applet.ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 935 | if (strcmp(args[0], "show") == 0) { |
| 936 | if (strcmp(args[1], "stat") == 0) { |
| 937 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 938 | si->applet.ctx.stats.flags |= STAT_BOUND; |
| 939 | si->applet.ctx.stats.iid = atoi(args[2]); |
| 940 | si->applet.ctx.stats.type = atoi(args[3]); |
| 941 | si->applet.ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 942 | } |
| 943 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 944 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 945 | si->applet.st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 946 | } |
| 947 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 948 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 949 | si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 950 | } |
| 951 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 952 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 953 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 954 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 955 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 956 | return 1; |
| 957 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 958 | if (*args[2] && strcmp(args[2], "all") == 0) |
| 959 | si->applet.ctx.sess.target = (void *)-1; |
| 960 | else if (*args[2]) |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 961 | si->applet.ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 962 | else |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 963 | si->applet.ctx.sess.target = NULL; |
| 964 | si->applet.ctx.sess.section = 0; /* start with session status */ |
| 965 | si->applet.ctx.sess.pos = 0; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 966 | si->applet.st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 967 | } |
| 968 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 969 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 970 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 971 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 972 | return 1; |
| 973 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 974 | if (*args[2]) |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 975 | si->applet.ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 976 | else |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 977 | si->applet.ctx.errors.iid = -1; |
| 978 | si->applet.ctx.errors.px = NULL; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 979 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 980 | si->applet.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 981 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 982 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 983 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 984 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 985 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 986 | return 0; |
| 987 | } |
| 988 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 989 | else if (strcmp(args[0], "clear") == 0) { |
| 990 | if (strcmp(args[1], "counters") == 0) { |
| 991 | struct proxy *px; |
| 992 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 993 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 994 | int clrall = 0; |
| 995 | |
| 996 | if (strcmp(args[2], "all") == 0) |
| 997 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 998 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 999 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1000 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 1001 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1002 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1003 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1004 | return 1; |
| 1005 | } |
| 1006 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1007 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1008 | if (clrall) { |
| 1009 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1010 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1011 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1012 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1013 | px->be_counters.conn_max = 0; |
| 1014 | px->be_counters.p.http.rps_max = 0; |
| 1015 | px->be_counters.sps_max = 0; |
| 1016 | px->be_counters.cps_max = 0; |
| 1017 | px->be_counters.nbpend_max = 0; |
| 1018 | |
| 1019 | px->fe_counters.conn_max = 0; |
| 1020 | px->fe_counters.p.http.rps_max = 0; |
| 1021 | px->fe_counters.sps_max = 0; |
| 1022 | px->fe_counters.cps_max = 0; |
| 1023 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1024 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1025 | |
| 1026 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1027 | if (clrall) |
| 1028 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1029 | else { |
| 1030 | sv->counters.cur_sess_max = 0; |
| 1031 | sv->counters.nbpend_max = 0; |
| 1032 | sv->counters.sps_max = 0; |
| 1033 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1034 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1035 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1036 | if (li->counters) { |
| 1037 | if (clrall) |
| 1038 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1039 | else |
| 1040 | li->counters->conn_max = 0; |
| 1041 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1042 | } |
| 1043 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1044 | global.cps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1045 | return 1; |
| 1046 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1047 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1048 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1049 | /* end of processing */ |
| 1050 | return 1; |
| 1051 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1052 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1053 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1054 | return 0; |
| 1055 | } |
| 1056 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1057 | else if (strcmp(args[0], "get") == 0) { |
| 1058 | if (strcmp(args[1], "weight") == 0) { |
| 1059 | struct proxy *px; |
| 1060 | struct server *sv; |
| 1061 | |
| 1062 | /* split "backend/server" and make <line> point to server */ |
| 1063 | for (line = args[2]; *line; line++) |
| 1064 | if (*line == '/') { |
| 1065 | *line++ = '\0'; |
| 1066 | break; |
| 1067 | } |
| 1068 | |
| 1069 | if (!*line) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1070 | si->applet.ctx.cli.msg = "Require 'backend/server'.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1071 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1072 | return 1; |
| 1073 | } |
| 1074 | |
| 1075 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1076 | 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] | 1077 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1078 | return 1; |
| 1079 | } |
| 1080 | |
| 1081 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1082 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1083 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1084 | return 1; |
| 1085 | } |
| 1086 | else { /* not "get weight" */ |
| 1087 | return 0; |
| 1088 | } |
| 1089 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1090 | else if (strcmp(args[0], "set") == 0) { |
| 1091 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1092 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1093 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1094 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1095 | sv = expect_server_admin(s, si, args[2]); |
| 1096 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1097 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1098 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1099 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1100 | if (warning) { |
| 1101 | si->applet.ctx.cli.msg = warning; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1102 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1103 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1104 | return 1; |
| 1105 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1106 | else if (strcmp(args[1], "timeout") == 0) { |
| 1107 | if (strcmp(args[2], "cli") == 0) { |
| 1108 | unsigned timeout; |
| 1109 | const char *res; |
| 1110 | |
| 1111 | if (!*args[3]) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1112 | si->applet.ctx.cli.msg = "Expects an integer value.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1113 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1114 | return 1; |
| 1115 | } |
| 1116 | |
| 1117 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1118 | if (res || timeout < 1) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1119 | si->applet.ctx.cli.msg = "Invalid timeout value.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1120 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1121 | return 1; |
| 1122 | } |
| 1123 | |
| 1124 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1125 | return 1; |
| 1126 | } |
| 1127 | else { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1128 | si->applet.ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1129 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1130 | return 1; |
| 1131 | } |
| 1132 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1133 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1134 | if (strcmp(args[2], "frontend") == 0) { |
| 1135 | struct proxy *px; |
| 1136 | struct listener *l; |
| 1137 | int v; |
| 1138 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1139 | px = expect_frontend_admin(s, si, args[3]); |
| 1140 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1141 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1142 | |
| 1143 | if (!*args[4]) { |
| 1144 | si->applet.ctx.cli.msg = "Integer value expected.\n"; |
| 1145 | si->applet.st0 = STAT_CLI_PRINT; |
| 1146 | return 1; |
| 1147 | } |
| 1148 | |
| 1149 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1150 | if (v < 0) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1151 | si->applet.ctx.cli.msg = "Value out of range.\n"; |
| 1152 | si->applet.st0 = STAT_CLI_PRINT; |
| 1153 | return 1; |
| 1154 | } |
| 1155 | |
| 1156 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1157 | * its listeners. The blocked ones will be dequeued. |
| 1158 | */ |
| 1159 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1160 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1161 | l->maxconn = v; |
| 1162 | if (l->state == LI_FULL) |
| 1163 | resume_listener(l); |
| 1164 | } |
| 1165 | |
| 1166 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1167 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1168 | |
| 1169 | return 1; |
| 1170 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1171 | else if (strcmp(args[2], "global") == 0) { |
| 1172 | int v; |
| 1173 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1174 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1175 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 1176 | si->applet.st0 = STAT_CLI_PRINT; |
| 1177 | return 1; |
| 1178 | } |
| 1179 | |
| 1180 | if (!*args[3]) { |
| 1181 | si->applet.ctx.cli.msg = "Expects an integer value.\n"; |
| 1182 | si->applet.st0 = STAT_CLI_PRINT; |
| 1183 | return 1; |
| 1184 | } |
| 1185 | |
| 1186 | v = atoi(args[3]); |
| 1187 | if (v > global.hardmaxconn) { |
| 1188 | si->applet.ctx.cli.msg = "Value out of range.\n"; |
| 1189 | si->applet.st0 = STAT_CLI_PRINT; |
| 1190 | return 1; |
| 1191 | } |
| 1192 | |
| 1193 | /* check for unlimited values */ |
| 1194 | if (v <= 0) |
| 1195 | v = global.hardmaxconn; |
| 1196 | |
| 1197 | global.maxconn = v; |
| 1198 | |
| 1199 | /* Dequeues all of the listeners waiting for a resource */ |
| 1200 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1201 | dequeue_all_listeners(&global_listener_queue); |
| 1202 | |
| 1203 | return 1; |
| 1204 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1205 | else { |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1206 | 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] | 1207 | si->applet.st0 = STAT_CLI_PRINT; |
| 1208 | return 1; |
| 1209 | } |
| 1210 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1211 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1212 | if (strcmp(args[2], "connections") == 0) { |
| 1213 | if (strcmp(args[3], "global") == 0) { |
| 1214 | int v; |
| 1215 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1216 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1217 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 1218 | si->applet.st0 = STAT_CLI_PRINT; |
| 1219 | return 1; |
| 1220 | } |
| 1221 | |
| 1222 | if (!*args[4]) { |
| 1223 | si->applet.ctx.cli.msg = "Expects an integer value.\n"; |
| 1224 | si->applet.st0 = STAT_CLI_PRINT; |
| 1225 | return 1; |
| 1226 | } |
| 1227 | |
| 1228 | v = atoi(args[4]); |
| 1229 | if (v < 0) { |
| 1230 | si->applet.ctx.cli.msg = "Value out of range.\n"; |
| 1231 | si->applet.st0 = STAT_CLI_PRINT; |
| 1232 | return 1; |
| 1233 | } |
| 1234 | |
| 1235 | global.cps_lim = v; |
| 1236 | |
| 1237 | /* Dequeues all of the listeners waiting for a resource */ |
| 1238 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1239 | dequeue_all_listeners(&global_listener_queue); |
| 1240 | |
| 1241 | return 1; |
| 1242 | } |
| 1243 | else { |
| 1244 | si->applet.ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1245 | si->applet.st0 = STAT_CLI_PRINT; |
| 1246 | return 1; |
| 1247 | } |
| 1248 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1249 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1250 | if (strcmp(args[3], "global") == 0) { |
| 1251 | int v; |
| 1252 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1253 | if (!*args[4]) { |
| 1254 | si->applet.ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1255 | si->applet.st0 = STAT_CLI_PRINT; |
| 1256 | return 1; |
| 1257 | } |
| 1258 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1259 | v = atoi(args[4]); |
| 1260 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1261 | } |
| 1262 | else { |
| 1263 | si->applet.ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1264 | si->applet.st0 = STAT_CLI_PRINT; |
| 1265 | return 1; |
| 1266 | } |
| 1267 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1268 | else { |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1269 | 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] | 1270 | si->applet.st0 = STAT_CLI_PRINT; |
| 1271 | return 1; |
| 1272 | } |
| 1273 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1274 | else if (strcmp(args[1], "table") == 0) { |
| 1275 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1276 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1277 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1278 | return 0; |
| 1279 | } |
| 1280 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1281 | else if (strcmp(args[0], "enable") == 0) { |
| 1282 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1283 | struct server *sv; |
| 1284 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1285 | sv = expect_server_admin(s, si, args[2]); |
| 1286 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1287 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1288 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1289 | if (sv->state & SRV_MAINTAIN) { |
| 1290 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1291 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1292 | /* If this server tracks the status of another one, |
| 1293 | * we must restore the good status. |
| 1294 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1295 | if (sv->track->state & SRV_RUNNING) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1296 | set_server_up(sv); |
Willy Tarreau | 7046130 | 2010-10-22 14:39:02 +0200 | [diff] [blame] | 1297 | sv->health = sv->rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1298 | } else { |
| 1299 | sv->state &= ~SRV_MAINTAIN; |
| 1300 | set_server_down(sv); |
| 1301 | } |
| 1302 | } else { |
| 1303 | set_server_up(sv); |
Willy Tarreau | 7046130 | 2010-10-22 14:39:02 +0200 | [diff] [blame] | 1304 | sv->health = sv->rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1305 | } |
| 1306 | } |
| 1307 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1308 | return 1; |
| 1309 | } |
| 1310 | else if (strcmp(args[1], "frontend") == 0) { |
| 1311 | struct proxy *px; |
| 1312 | |
| 1313 | px = expect_frontend_admin(s, si, args[2]); |
| 1314 | if (!px) |
| 1315 | return 1; |
| 1316 | |
| 1317 | if (px->state == PR_STSTOPPED) { |
| 1318 | si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1319 | si->applet.st0 = STAT_CLI_PRINT; |
| 1320 | return 1; |
| 1321 | } |
| 1322 | |
| 1323 | if (px->state != PR_STPAUSED) { |
| 1324 | si->applet.ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1325 | si->applet.st0 = STAT_CLI_PRINT; |
| 1326 | return 1; |
| 1327 | } |
| 1328 | |
| 1329 | if (!resume_proxy(px)) { |
| 1330 | si->applet.ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1331 | si->applet.st0 = STAT_CLI_PRINT; |
| 1332 | return 1; |
| 1333 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1334 | return 1; |
| 1335 | } |
| 1336 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1337 | si->applet.ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1338 | si->applet.st0 = STAT_CLI_PRINT; |
| 1339 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | else if (strcmp(args[0], "disable") == 0) { |
| 1343 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1344 | struct server *sv; |
| 1345 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1346 | sv = expect_server_admin(s, si, args[2]); |
| 1347 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1348 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1349 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1350 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1351 | /* Not already in maintenance, we can change the server state */ |
| 1352 | sv->state |= SRV_MAINTAIN; |
| 1353 | set_server_down(sv); |
| 1354 | } |
| 1355 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1356 | return 1; |
| 1357 | } |
| 1358 | else if (strcmp(args[1], "frontend") == 0) { |
| 1359 | struct proxy *px; |
| 1360 | |
| 1361 | px = expect_frontend_admin(s, si, args[2]); |
| 1362 | if (!px) |
| 1363 | return 1; |
| 1364 | |
| 1365 | if (px->state == PR_STSTOPPED) { |
| 1366 | si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1367 | si->applet.st0 = STAT_CLI_PRINT; |
| 1368 | return 1; |
| 1369 | } |
| 1370 | |
| 1371 | if (px->state == PR_STPAUSED) { |
| 1372 | si->applet.ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1373 | si->applet.st0 = STAT_CLI_PRINT; |
| 1374 | return 1; |
| 1375 | } |
| 1376 | |
| 1377 | if (!pause_proxy(px)) { |
| 1378 | si->applet.ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1379 | si->applet.st0 = STAT_CLI_PRINT; |
| 1380 | return 1; |
| 1381 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1382 | return 1; |
| 1383 | } |
| 1384 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1385 | si->applet.ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1386 | si->applet.st0 = STAT_CLI_PRINT; |
| 1387 | return 1; |
| 1388 | } |
| 1389 | } |
| 1390 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1391 | if (strcmp(args[1], "frontend") == 0) { |
| 1392 | struct proxy *px; |
| 1393 | |
| 1394 | px = expect_frontend_admin(s, si, args[2]); |
| 1395 | if (!px) |
| 1396 | return 1; |
| 1397 | |
| 1398 | if (px->state == PR_STSTOPPED) { |
| 1399 | si->applet.ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1400 | si->applet.st0 = STAT_CLI_PRINT; |
| 1401 | return 1; |
| 1402 | } |
| 1403 | |
| 1404 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1405 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1406 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1407 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1408 | stop_proxy(px); |
| 1409 | return 1; |
| 1410 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1411 | else if (strcmp(args[1], "session") == 0) { |
| 1412 | struct session *sess, *ptr; |
| 1413 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1414 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1415 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 1416 | si->applet.st0 = STAT_CLI_PRINT; |
| 1417 | return 1; |
| 1418 | } |
| 1419 | |
| 1420 | if (!*args[2]) { |
| 1421 | si->applet.ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1422 | si->applet.st0 = STAT_CLI_PRINT; |
| 1423 | return 1; |
| 1424 | } |
| 1425 | |
| 1426 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1427 | |
| 1428 | /* first, look for the requested session in the session table */ |
| 1429 | list_for_each_entry(sess, &sessions, list) { |
| 1430 | if (sess == ptr) |
| 1431 | break; |
| 1432 | } |
| 1433 | |
| 1434 | /* do we have the session ? */ |
| 1435 | if (sess != ptr) { |
| 1436 | si->applet.ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1437 | si->applet.st0 = STAT_CLI_PRINT; |
| 1438 | return 1; |
| 1439 | } |
| 1440 | |
| 1441 | session_shutdown(sess, SN_ERR_KILLED); |
| 1442 | return 1; |
| 1443 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1444 | else if (strcmp(args[1], "sessions") == 0) { |
| 1445 | if (strcmp(args[2], "server") == 0) { |
| 1446 | struct server *sv; |
| 1447 | struct session *sess, *sess_bck; |
| 1448 | |
| 1449 | sv = expect_server_admin(s, si, args[3]); |
| 1450 | if (!sv) |
| 1451 | return 1; |
| 1452 | |
| 1453 | /* kill all the session that are on this server */ |
| 1454 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1455 | if (sess->srv_conn == sv) |
| 1456 | session_shutdown(sess, SN_ERR_KILLED); |
| 1457 | |
| 1458 | return 1; |
| 1459 | } |
| 1460 | else { |
| 1461 | si->applet.ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1462 | si->applet.st0 = STAT_CLI_PRINT; |
| 1463 | return 1; |
| 1464 | } |
| 1465 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1466 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1467 | 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] | 1468 | si->applet.st0 = STAT_CLI_PRINT; |
| 1469 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1470 | } |
| 1471 | } |
| 1472 | 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] | 1473 | return 0; |
| 1474 | } |
| 1475 | return 1; |
| 1476 | } |
| 1477 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1478 | /* 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] | 1479 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 1480 | * state machine handling requests and various responses. We read a request, |
| 1481 | * 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] | 1482 | * Then we can read again. The state is stored in si->applet.st0 and is one of the |
| 1483 | * 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] | 1484 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1485 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 1486 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1487 | { |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1488 | struct channel *req = si->ob; |
| 1489 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1490 | int reql; |
| 1491 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1492 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1493 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 1494 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1495 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1496 | while (1) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1497 | if (si->applet.st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1498 | /* Stats output not initialized yet */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1499 | memset(&si->applet.ctx.stats, 0, sizeof(si->applet.ctx.stats)); |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1500 | si->applet.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1501 | } |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1502 | else if (si->applet.st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1503 | /* Let's close for real now. We just close the request |
| 1504 | * side, the conditions below will complete if needed. |
| 1505 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1506 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1507 | break; |
| 1508 | } |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1509 | else if (si->applet.st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1510 | /* ensure we have some output room left in the event we |
| 1511 | * would want to return some info right after parsing. |
| 1512 | */ |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1513 | if (buffer_almost_full(si->ib->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1514 | break; |
| 1515 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1516 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1517 | if (reql <= 0) { /* closed or EOL not found */ |
| 1518 | if (reql == 0) |
| 1519 | break; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1520 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1521 | continue; |
| 1522 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1523 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1524 | /* seek for a possible semi-colon. If we find one, we |
| 1525 | * replace it with an LF and skip only this part. |
| 1526 | */ |
| 1527 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1528 | if (trash.str[len] == ';') { |
| 1529 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1530 | reql = len + 1; |
| 1531 | break; |
| 1532 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1533 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1534 | /* now it is time to check that we have a full line, |
| 1535 | * remove the trailing \n and possibly \r, then cut the |
| 1536 | * line. |
| 1537 | */ |
| 1538 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1539 | if (trash.str[len] != '\n') { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1540 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1541 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1542 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1543 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1544 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1545 | len--; |
| 1546 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1547 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1548 | |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1549 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1550 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1551 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1552 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1553 | continue; |
| 1554 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1555 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1556 | si->applet.st1 = !si->applet.st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1557 | else if (strcmp(trash.str, "help") == 0 || |
| 1558 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1559 | si->applet.ctx.cli.msg = stats_sock_usage_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1560 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1561 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1562 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1563 | * another STAT_CLI_O_* into si->applet.st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1564 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1565 | } |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1566 | else if (!si->applet.st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1567 | /* if prompt is disabled, print help on empty lines, |
| 1568 | * so that the user at least knows how to enable |
| 1569 | * prompt and find help. |
| 1570 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1571 | si->applet.ctx.cli.msg = stats_sock_usage_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1572 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1576 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1577 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1578 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1579 | 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] | 1580 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1581 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1582 | continue; |
| 1583 | } |
| 1584 | |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1585 | switch (si->applet.st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1586 | case STAT_CLI_PRINT: |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1587 | if (bi_putstr(si->ib, si->applet.ctx.cli.msg) != -1) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1588 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1589 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1590 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1591 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1592 | si->applet.st0 = STAT_CLI_PROMPT; |
| 1593 | break; |
| 1594 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1595 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1596 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1597 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1598 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1599 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1600 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1601 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1602 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1603 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1604 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1605 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1606 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1607 | case STAT_CLI_O_CLR: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1608 | if (stats_table_request(si, si->applet.st0)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1609 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1610 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1611 | default: /* abnormal state */ |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1612 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1613 | break; |
| 1614 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1615 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1616 | /* 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] | 1617 | if (si->applet.st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1618 | if (bi_putstr(si->ib, si->applet.st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1619 | si->applet.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1622 | /* 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] | 1623 | if (si->applet.st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1624 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1625 | |
| 1626 | /* Now we close the output if one of the writers did so, |
| 1627 | * or if we're not in interactive mode and the request |
| 1628 | * buffer is empty. This still allows pipelined requests |
| 1629 | * to be sent in non-interactive mode. |
| 1630 | */ |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1631 | 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] | 1632 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1633 | continue; |
| 1634 | } |
| 1635 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1636 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1637 | si->applet.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1638 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1639 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1640 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1641 | 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] | 1642 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 1643 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1644 | /* 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] | 1645 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 1646 | * we forward the close to the request side so that it flows upstream to |
| 1647 | * the client. |
| 1648 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1649 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1650 | } |
| 1651 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1652 | 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] | 1653 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 1654 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 1655 | /* We have no more processing to do, and nothing more to send, and |
| 1656 | * the client side has closed. So we'll forward this state downstream |
| 1657 | * on the response buffer. |
| 1658 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1659 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1660 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1664 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1665 | |
| 1666 | /* we don't want to expire timeouts while we're processing requests */ |
| 1667 | si->ib->rex = TICK_ETERNITY; |
| 1668 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1669 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1670 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1671 | 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] | 1672 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1673 | 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] | 1674 | |
| 1675 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 1676 | /* check that we have released everything then unregister */ |
| 1677 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1678 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1679 | } |
| 1680 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1681 | /* This function dumps information onto the stream interface's read buffer. |
| 1682 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 1683 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1684 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1685 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1686 | { |
| 1687 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 1688 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1689 | chunk_printf(&trash, |
| 1690 | "Name: " PRODUCT_NAME "\n" |
| 1691 | "Version: " HAPROXY_VERSION "\n" |
| 1692 | "Release_date: " HAPROXY_DATE "\n" |
| 1693 | "Nbproc: %d\n" |
| 1694 | "Process_num: %d\n" |
| 1695 | "Pid: %d\n" |
| 1696 | "Uptime: %dd %dh%02dm%02ds\n" |
| 1697 | "Uptime_sec: %d\n" |
| 1698 | "Memmax_MB: %d\n" |
| 1699 | "Ulimit-n: %d\n" |
| 1700 | "Maxsock: %d\n" |
| 1701 | "Maxconn: %d\n" |
| 1702 | "Hard_maxconn: %d\n" |
| 1703 | "Maxpipes: %d\n" |
| 1704 | "CurrConns: %d\n" |
| 1705 | "PipesUsed: %d\n" |
| 1706 | "PipesFree: %d\n" |
| 1707 | "ConnRate: %d\n" |
| 1708 | "ConnRateLimit: %d\n" |
| 1709 | "MaxConnRate: %d\n" |
| 1710 | "CompressBpsIn: %u\n" |
| 1711 | "CompressBpsOut: %u\n" |
| 1712 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1713 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1714 | "ZlibMemUsage: %ld\n" |
| 1715 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1716 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1717 | "Tasks: %d\n" |
| 1718 | "Run_queue: %d\n" |
| 1719 | "Idle_pct: %d\n" |
| 1720 | "node: %s\n" |
| 1721 | "description: %s\n" |
| 1722 | "", |
| 1723 | global.nbproc, |
| 1724 | relative_pid, |
| 1725 | pid, |
| 1726 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 1727 | up, |
| 1728 | global.rlimit_memmax, |
| 1729 | global.rlimit_nofile, |
| 1730 | global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes, |
| 1731 | actconn, pipes_used, pipes_free, |
| 1732 | read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max, |
| 1733 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 1734 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1735 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1736 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1737 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 1738 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 1739 | global.node, global.desc ? global.desc : "" |
| 1740 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1741 | |
| 1742 | if (bi_putchk(si->ib, &trash) == -1) |
| 1743 | return 0; |
| 1744 | |
| 1745 | return 1; |
| 1746 | } |
| 1747 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1748 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 1749 | * the state from stream interface <si>. The caller is responsible for clearing |
| 1750 | * 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] | 1751 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1752 | 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] | 1753 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1754 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1755 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1756 | if (!(px->cap & PR_CAP_FE)) |
| 1757 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1758 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1759 | if ((si->applet.ctx.stats.flags & STAT_BOUND) && !(si->applet.ctx.stats.type & (1 << STATS_TYPE_FE))) |
| 1760 | return 0; |
| 1761 | |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 1762 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1763 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1764 | /* name, queue */ |
| 1765 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1766 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1767 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 1768 | /* Column sub-heading for Enable or Disable server */ |
| 1769 | chunk_appendf(&trash, "<td></td>"); |
| 1770 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1771 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1772 | chunk_appendf(&trash, |
| 1773 | "<td class=ac>" |
| 1774 | "<a name=\"%s/Frontend\"></a>" |
| 1775 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 1776 | "<td colspan=3></td>" |
| 1777 | "", |
| 1778 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1779 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1780 | chunk_appendf(&trash, |
| 1781 | /* sessions rate : current */ |
| 1782 | "<td><u>%s<div><table class=det>" |
| 1783 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 1784 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 1785 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1786 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 1787 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 1788 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1789 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1790 | if (px->mode == PR_MODE_HTTP) |
| 1791 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1792 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1793 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1794 | |
| 1795 | chunk_appendf(&trash, |
| 1796 | "</table></div></u></td>" |
| 1797 | /* sessions rate : max */ |
| 1798 | "<td><u>%s<div><table class=det>" |
| 1799 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 1800 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 1801 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1802 | U2H(px->fe_counters.sps_max), |
| 1803 | U2H(px->fe_counters.cps_max), |
| 1804 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1805 | |
| 1806 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1807 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1808 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1809 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1810 | |
| 1811 | chunk_appendf(&trash, |
| 1812 | "</table></div></u></td>" |
| 1813 | /* sessions rate : limit */ |
| 1814 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1815 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1816 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1817 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1818 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1819 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1820 | "<td><u>%s<div><table class=det>" |
| 1821 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 1822 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1823 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1824 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 1825 | U2H(px->fe_counters.cum_sess), |
| 1826 | U2H(px->fe_counters.cum_conn), |
| 1827 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1828 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1829 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1830 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1831 | chunk_appendf(&trash, |
| 1832 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 1833 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 1834 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 1835 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1836 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 1837 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 1838 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 1839 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 1840 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 1841 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1842 | U2H(px->fe_counters.p.http.cum_req), |
| 1843 | U2H(px->fe_counters.p.http.rsp[1]), |
| 1844 | U2H(px->fe_counters.p.http.rsp[2]), |
| 1845 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1846 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1847 | (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] | 1848 | U2H(px->fe_counters.p.http.rsp[3]), |
| 1849 | U2H(px->fe_counters.p.http.rsp[4]), |
| 1850 | U2H(px->fe_counters.p.http.rsp[5]), |
| 1851 | U2H(px->fe_counters.p.http.rsp[0]), |
| 1852 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1853 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1854 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1855 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1856 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1857 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 1858 | "<td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1859 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1860 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1861 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1862 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1863 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1864 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1865 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 1866 | "<td>%s%s<div>compression: in=%lld out=%lld bypassed=%lld savings=%d%%</div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1867 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1868 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1869 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 1870 | px->fe_counters.comp_in ? |
| 1871 | (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] | 1872 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1873 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1874 | chunk_appendf(&trash, |
| 1875 | /* denied: req, resp */ |
| 1876 | "<td>%s</td><td>%s</td>" |
| 1877 | /* errors : request, connect, response */ |
| 1878 | "<td>%s</td><td></td><td></td>" |
| 1879 | /* warnings: retries, redispatches */ |
| 1880 | "<td></td><td></td>" |
| 1881 | /* server status : reflect frontend status */ |
| 1882 | "<td class=ac>%s</td>" |
| 1883 | /* rest of server: nothing */ |
| 1884 | "<td class=ac colspan=8></td></tr>" |
| 1885 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 1886 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 1887 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1888 | px->state == PR_STREADY ? "OPEN" : |
| 1889 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1890 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1891 | else { /* CSV mode */ |
| 1892 | chunk_appendf(&trash, |
| 1893 | /* pxid, name, queue cur, queue max, */ |
| 1894 | "%s,FRONTEND,,," |
| 1895 | /* sessions : current, max, limit, total */ |
| 1896 | "%d,%d,%d,%lld," |
| 1897 | /* bytes : in, out */ |
| 1898 | "%lld,%lld," |
| 1899 | /* denied: req, resp */ |
| 1900 | "%lld,%lld," |
| 1901 | /* errors : request, connect, response */ |
| 1902 | "%lld,,," |
| 1903 | /* warnings: retries, redispatches */ |
| 1904 | ",," |
| 1905 | /* server status : reflect frontend status */ |
| 1906 | "%s," |
| 1907 | /* rest of server: nothing */ |
| 1908 | ",,,,,,,," |
| 1909 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 1910 | "%d,%d,0,,,,%d," |
| 1911 | /* rate, rate_lim, rate_max */ |
| 1912 | "%u,%u,%u," |
| 1913 | /* check_status, check_code, check_duration */ |
| 1914 | ",,,", |
| 1915 | px->id, |
| 1916 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 1917 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 1918 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 1919 | px->fe_counters.failed_req, |
| 1920 | px->state == PR_STREADY ? "OPEN" : |
| 1921 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 1922 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 1923 | read_freq_ctr(&px->fe_sess_per_sec), |
| 1924 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1925 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1926 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1927 | if (px->mode == PR_MODE_HTTP) { |
| 1928 | for (i=1; i<6; i++) |
| 1929 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 1930 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 1931 | } |
| 1932 | else |
| 1933 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1934 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1935 | /* failed health analyses */ |
| 1936 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1937 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1938 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 1939 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 1940 | read_freq_ctr(&px->fe_req_per_sec), |
| 1941 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 1942 | |
| 1943 | /* errors: cli_aborts, srv_aborts */ |
| 1944 | chunk_appendf(&trash, ",,"); |
| 1945 | |
| 1946 | /* compression: in, out, bypassed */ |
| 1947 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 1948 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 1949 | |
| 1950 | /* compression: comp_rsp */ |
| 1951 | chunk_appendf(&trash, "%lld,", |
| 1952 | px->fe_counters.p.http.comp_rsp); |
| 1953 | |
| 1954 | /* finish with EOL */ |
| 1955 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1956 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1957 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1958 | } |
| 1959 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1960 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 1961 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 1962 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 1963 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1964 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1965 | 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] | 1966 | { |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 1967 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1968 | chunk_appendf(&trash, "<tr class=socket>"); |
| 1969 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 1970 | /* Column sub-heading for Enable or Disable server */ |
| 1971 | chunk_appendf(&trash, "<td></td>"); |
| 1972 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1973 | chunk_appendf(&trash, |
| 1974 | /* frontend name, listener name */ |
| 1975 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 1976 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 1977 | "", |
| 1978 | px->id, l->name, |
| 1979 | (flags & ST_SHLGNDS)?"<u>":"", |
| 1980 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1981 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1982 | if (flags & ST_SHLGNDS) { |
| 1983 | char str[INET6_ADDRSTRLEN]; |
| 1984 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1985 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 1986 | chunk_appendf(&trash, "<div>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1987 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 1988 | port = get_host_port(&l->addr); |
| 1989 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 1990 | case AF_INET: |
| 1991 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 1992 | break; |
| 1993 | case AF_INET6: |
| 1994 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 1995 | break; |
| 1996 | case AF_UNIX: |
| 1997 | chunk_appendf(&trash, "unix, "); |
| 1998 | break; |
| 1999 | case -1: |
| 2000 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2001 | break; |
| 2002 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2003 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2004 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2005 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2006 | } |
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 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2009 | /* queue */ |
| 2010 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2011 | /* sessions rate: current, max, limit */ |
| 2012 | "<td colspan=3> </td>" |
| 2013 | /* sessions: current, max, limit, total, lbtot */ |
| 2014 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2015 | "<td>%s</td><td> </td>" |
| 2016 | /* bytes: in, out */ |
| 2017 | "<td>%s</td><td>%s</td>" |
| 2018 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2019 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2020 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 2021 | 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] | 2022 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2023 | chunk_appendf(&trash, |
| 2024 | /* denied: req, resp */ |
| 2025 | "<td>%s</td><td>%s</td>" |
| 2026 | /* errors: request, connect, response */ |
| 2027 | "<td>%s</td><td></td><td></td>" |
| 2028 | /* warnings: retries, redispatches */ |
| 2029 | "<td></td><td></td>" |
| 2030 | /* server status: reflect listener status */ |
| 2031 | "<td class=ac>%s</td>" |
| 2032 | /* rest of server: nothing */ |
| 2033 | "<td class=ac colspan=8></td></tr>" |
| 2034 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2035 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 2036 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2037 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 2038 | } |
| 2039 | else { /* CSV mode */ |
| 2040 | chunk_appendf(&trash, |
| 2041 | /* pxid, name, queue cur, queue max, */ |
| 2042 | "%s,%s,,," |
| 2043 | /* sessions: current, max, limit, total */ |
| 2044 | "%d,%d,%d,%lld," |
| 2045 | /* bytes: in, out */ |
| 2046 | "%lld,%lld," |
| 2047 | /* denied: req, resp */ |
| 2048 | "%lld,%lld," |
| 2049 | /* errors: request, connect, response */ |
| 2050 | "%lld,,," |
| 2051 | /* warnings: retries, redispatches */ |
| 2052 | ",," |
| 2053 | /* server status: reflect listener status */ |
| 2054 | "%s," |
| 2055 | /* rest of server: nothing */ |
| 2056 | ",,,,,,,," |
| 2057 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2058 | "%d,%d,%d,,,,%d," |
| 2059 | /* rate, rate_lim, rate_max */ |
| 2060 | ",,," |
| 2061 | /* check_status, check_code, check_duration */ |
| 2062 | ",,," |
| 2063 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2064 | ",,,,,," |
| 2065 | /* failed health analyses */ |
| 2066 | "," |
| 2067 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2068 | ",,," |
| 2069 | /* errors: cli_aborts, srv_aborts */ |
| 2070 | ",," |
| 2071 | /* compression: in, out, bypassed, comp_rsp */ |
| 2072 | ",,,," |
| 2073 | "\n", |
| 2074 | px->id, l->name, |
| 2075 | l->nbconn, l->counters->conn_max, |
| 2076 | l->maxconn, l->counters->cum_conn, |
| 2077 | l->counters->bytes_in, l->counters->bytes_out, |
| 2078 | l->counters->denied_req, l->counters->denied_resp, |
| 2079 | l->counters->failed_req, |
| 2080 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2081 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2082 | } |
| 2083 | return 1; |
| 2084 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2085 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2086 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 2087 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 2088 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 2089 | * if it emits anything, zero otherwise. The <state> parameter can take the |
| 2090 | * following values : 0=DOWN, 1=going up, 2=going down, 3=UP, 4,5=NOLB, 6=unchecked. |
| 2091 | */ |
| 2092 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, int state) |
| 2093 | { |
| 2094 | struct server *ref = sv->track ? sv->track : sv; |
| 2095 | char str[INET6_ADDRSTRLEN]; |
| 2096 | struct chunk src; |
| 2097 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2098 | |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 2099 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2100 | static char *srv_hlt_st[7] = { |
| 2101 | "DOWN", |
| 2102 | "DN %d/%d ↑", |
| 2103 | "UP %d/%d ↓", |
| 2104 | "UP", |
| 2105 | "NOLB %d/%d ↓", |
| 2106 | "NOLB", |
| 2107 | "<i>no check</i>" |
| 2108 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2109 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2110 | if ((sv->state & SRV_MAINTAIN) || (ref->state & SRV_MAINTAIN)) |
| 2111 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 2112 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2113 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2114 | "<tr class=\"%s%d\">", |
| 2115 | (sv->state & SRV_BACKUP) ? "backup" : "active", state); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2116 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2117 | 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] | 2118 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2119 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2120 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2121 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2122 | chunk_appendf(&trash, |
| 2123 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 2124 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 2125 | "", |
| 2126 | px->id, sv->id, |
| 2127 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 2128 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2129 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2130 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2131 | chunk_appendf(&trash, "<div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2132 | |
| 2133 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2134 | case AF_INET: |
| 2135 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 2136 | break; |
| 2137 | case AF_INET6: |
| 2138 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2139 | break; |
| 2140 | case AF_UNIX: |
| 2141 | chunk_appendf(&trash, "unix, "); |
| 2142 | break; |
| 2143 | case -1: |
| 2144 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 2145 | break; |
| 2146 | default: /* address family not supported */ |
| 2147 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2148 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2149 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2150 | /* id */ |
| 2151 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2152 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2153 | /* cookie */ |
| 2154 | if (sv->cookie) { |
| 2155 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2156 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2157 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2158 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2159 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2160 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2161 | } |
| 2162 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2163 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2164 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2165 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2166 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2167 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2168 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2169 | /* sessions rate : current, max, limit */ |
| 2170 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2171 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2172 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2173 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 2174 | 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] | 2175 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2176 | |
| 2177 | chunk_appendf(&trash, |
| 2178 | /* sessions: current, max, limit, total */ |
| 2179 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2180 | "<td><u>%s<div><table class=det>" |
| 2181 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 2182 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2183 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 2184 | U2H(sv->counters.cum_sess), |
| 2185 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2186 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2187 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2188 | if (px->mode == PR_MODE_HTTP) { |
| 2189 | unsigned long long tot; |
| 2190 | for (tot = i = 0; i < 6; i++) |
| 2191 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2192 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2193 | chunk_appendf(&trash, |
| 2194 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 2195 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2196 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2197 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2198 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2199 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2200 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2201 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2202 | U2H(tot), |
| 2203 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 2204 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 2205 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 2206 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 2207 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 2208 | 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] | 2209 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2210 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2211 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2212 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2213 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2214 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2215 | U2H(sv->counters.cum_lbconn)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2216 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2217 | chunk_appendf(&trash, |
| 2218 | /* bytes : in, out */ |
| 2219 | "<td>%s</td><td>%s</td>" |
| 2220 | /* denied: req, resp */ |
| 2221 | "<td></td><td>%s</td>" |
| 2222 | /* errors : request, connect */ |
| 2223 | "<td></td><td>%s</td>" |
| 2224 | /* errors : response */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2225 | "<td><u>%s<div>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2226 | /* warnings: retries, redispatches */ |
| 2227 | "<td>%lld</td><td>%lld</td>" |
| 2228 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2229 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 2230 | U2H(sv->counters.failed_secu), |
| 2231 | U2H(sv->counters.failed_conns), |
| 2232 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2233 | sv->counters.cli_aborts, |
| 2234 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2235 | sv->counters.retries, sv->counters.redispatches); |
| 2236 | |
| 2237 | /* status, lest check */ |
| 2238 | chunk_appendf(&trash, "<td class=ac>"); |
| 2239 | |
| 2240 | if (sv->state & SRV_MAINTAIN) { |
| 2241 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 2242 | chunk_appendf(&trash, "MAINT"); |
| 2243 | } |
| 2244 | else if (ref != sv && ref->state & SRV_MAINTAIN) { |
| 2245 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2246 | chunk_appendf(&trash, "MAINT(via)"); |
| 2247 | } |
| 2248 | else if (ref->state & SRV_CHECKED) { |
| 2249 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 2250 | chunk_appendf(&trash, |
| 2251 | srv_hlt_st[state], |
| 2252 | (ref->state & SRV_RUNNING) ? (ref->health - ref->rise + 1) : (ref->health), |
| 2253 | (ref->state & SRV_RUNNING) ? (ref->fall) : (ref->rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2254 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2255 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2256 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2257 | chunk_appendf(&trash, |
| 2258 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2259 | (sv->state & SRV_CHK_RUNNING) ? "* " : "", |
| 2260 | get_check_status_info(sv->check.status)); |
| 2261 | |
| 2262 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2263 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 2264 | |
| 2265 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2266 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 2267 | |
| 2268 | chunk_appendf(&trash, "<div>%s", |
| 2269 | get_check_status_description(sv->check.status)); |
| 2270 | if (*sv->check.desc) { |
| 2271 | chunk_appendf(&trash, ": "); |
| 2272 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 2273 | chunk_htmlencode(&trash, &src); |
| 2274 | } |
| 2275 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2276 | } |
| 2277 | else |
| 2278 | chunk_appendf(&trash, "</td><td>"); |
| 2279 | |
| 2280 | chunk_appendf(&trash, |
| 2281 | /* weight */ |
| 2282 | "</td><td class=ac>%d</td>" |
| 2283 | /* act, bck */ |
| 2284 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 2285 | "", |
| 2286 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2287 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2288 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2289 | |
| 2290 | /* check failures: unique, fatal, down time */ |
| 2291 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2292 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2293 | |
| 2294 | if (ref->observe) |
| 2295 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 2296 | |
| 2297 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2298 | "<div>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2299 | "<td>%lld</td><td>%s</td>" |
| 2300 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2301 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2302 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 2303 | } |
| 2304 | else if (sv != ref) |
| 2305 | chunk_appendf(&trash, |
| 2306 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2307 | ref->proxy->id, ref->id, ref->proxy->id, ref->id); |
| 2308 | else |
| 2309 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 2310 | |
| 2311 | /* throttle */ |
| 2312 | if ((sv->state & SRV_WARMINGUP) && |
| 2313 | now.tv_sec < sv->last_change + sv->slowstart && |
| 2314 | now.tv_sec >= sv->last_change) { |
| 2315 | chunk_appendf(&trash, "<td class=ac>%d %%</td></tr>\n", |
| 2316 | (int)MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart)); |
| 2317 | } |
| 2318 | else |
| 2319 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 2320 | } |
| 2321 | else { /* CSV mode */ |
| 2322 | static char *srv_hlt_st[7] = { |
| 2323 | "DOWN,", |
| 2324 | "DOWN %d/%d,", |
| 2325 | "UP %d/%d,", |
| 2326 | "UP,", |
| 2327 | "NOLB %d/%d,", |
| 2328 | "NOLB,", |
| 2329 | "no check," |
| 2330 | }; |
| 2331 | |
| 2332 | chunk_appendf(&trash, |
| 2333 | /* pxid, name */ |
| 2334 | "%s,%s," |
| 2335 | /* queue : current, max */ |
| 2336 | "%d,%d," |
| 2337 | /* sessions : current, max, limit, total */ |
| 2338 | "%d,%d,%s,%lld," |
| 2339 | /* bytes : in, out */ |
| 2340 | "%lld,%lld," |
| 2341 | /* denied: req, resp */ |
| 2342 | ",%lld," |
| 2343 | /* errors : request, connect, response */ |
| 2344 | ",%lld,%lld," |
| 2345 | /* warnings: retries, redispatches */ |
| 2346 | "%lld,%lld," |
| 2347 | "", |
| 2348 | px->id, sv->id, |
| 2349 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2350 | 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] | 2351 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2352 | sv->counters.failed_secu, |
| 2353 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2354 | sv->counters.retries, sv->counters.redispatches); |
| 2355 | |
| 2356 | /* status */ |
| 2357 | if (sv->state & SRV_MAINTAIN) |
| 2358 | chunk_appendf(&trash, "MAINT,"); |
| 2359 | else if (ref != sv && ref->state & SRV_MAINTAIN) |
| 2360 | chunk_appendf(&trash, "MAINT(via),"); |
| 2361 | else |
| 2362 | chunk_appendf(&trash, |
| 2363 | srv_hlt_st[state], |
| 2364 | (ref->state & SRV_RUNNING) ? (ref->health - ref->rise + 1) : (ref->health), |
| 2365 | (ref->state & SRV_RUNNING) ? (ref->fall) : (ref->rise)); |
| 2366 | |
| 2367 | chunk_appendf(&trash, |
| 2368 | /* weight, active, backup */ |
| 2369 | "%d,%d,%d," |
| 2370 | "", |
| 2371 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2372 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2373 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2374 | |
| 2375 | /* check failures: unique, fatal; last change, total downtime */ |
| 2376 | if (sv->state & SRV_CHECKED) |
| 2377 | chunk_appendf(&trash, |
| 2378 | "%lld,%lld,%d,%d,", |
| 2379 | sv->counters.failed_checks, sv->counters.down_trans, |
| 2380 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 2381 | else |
| 2382 | chunk_appendf(&trash, ",,,,"); |
| 2383 | |
| 2384 | /* queue limit, pid, iid, sid, */ |
| 2385 | chunk_appendf(&trash, |
| 2386 | "%s," |
| 2387 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2388 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2389 | relative_pid, px->uuid, sv->puid); |
| 2390 | |
| 2391 | /* throttle */ |
| 2392 | if ((sv->state & SRV_WARMINGUP) && |
| 2393 | now.tv_sec < sv->last_change + sv->slowstart && |
| 2394 | now.tv_sec >= sv->last_change) |
| 2395 | chunk_appendf(&trash, "%d", (int)MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart)); |
| 2396 | |
| 2397 | /* sessions: lbtot */ |
| 2398 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 2399 | |
| 2400 | /* tracked */ |
| 2401 | if (sv->track) |
| 2402 | chunk_appendf(&trash, "%s/%s,", |
| 2403 | sv->track->proxy->id, sv->track->id); |
| 2404 | else |
| 2405 | chunk_appendf(&trash, ","); |
| 2406 | |
| 2407 | /* type */ |
| 2408 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 2409 | |
| 2410 | /* rate */ |
| 2411 | chunk_appendf(&trash, "%u,,%u,", |
| 2412 | read_freq_ctr(&sv->sess_per_sec), |
| 2413 | sv->counters.sps_max); |
| 2414 | |
| 2415 | if (sv->state & SRV_CHECKED) { |
| 2416 | /* check_status */ |
| 2417 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
| 2418 | |
| 2419 | /* check_code */ |
| 2420 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2421 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 2422 | else |
| 2423 | chunk_appendf(&trash, ","); |
| 2424 | |
| 2425 | /* check_duration */ |
| 2426 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 2427 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 2428 | else |
| 2429 | chunk_appendf(&trash, ","); |
| 2430 | |
| 2431 | } |
| 2432 | else |
| 2433 | chunk_appendf(&trash, ",,,"); |
| 2434 | |
| 2435 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2436 | if (px->mode == PR_MODE_HTTP) { |
| 2437 | for (i=1; i<6; i++) |
| 2438 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 2439 | |
| 2440 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 2441 | } |
| 2442 | else |
| 2443 | chunk_appendf(&trash, ",,,,,,"); |
| 2444 | |
| 2445 | /* failed health analyses */ |
| 2446 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 2447 | |
| 2448 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2449 | chunk_appendf(&trash, ",,,"); |
| 2450 | |
| 2451 | /* errors: cli_aborts, srv_aborts */ |
| 2452 | chunk_appendf(&trash, "%lld,%lld,", |
| 2453 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 2454 | |
| 2455 | /* compression: in, out, bypassed, comp_rsp */ |
| 2456 | chunk_appendf(&trash, ",,,,"); |
| 2457 | |
| 2458 | /* finish with EOL */ |
| 2459 | chunk_appendf(&trash, "\n"); |
| 2460 | } |
| 2461 | return 1; |
| 2462 | } |
| 2463 | |
| 2464 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 2465 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 2466 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 2467 | */ |
| 2468 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 2469 | { |
| 2470 | struct chunk src; |
| 2471 | int i; |
| 2472 | |
| 2473 | if (!(px->cap & PR_CAP_BE)) |
| 2474 | return 0; |
| 2475 | |
| 2476 | if ((si->applet.ctx.stats.flags & STAT_BOUND) && !(si->applet.ctx.stats.type & (1 << STATS_TYPE_BE))) |
| 2477 | return 0; |
| 2478 | |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 2479 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2480 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
| 2481 | if (px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 2482 | /* Column sub-heading for Enable or Disable server */ |
| 2483 | chunk_appendf(&trash, "<td></td>"); |
| 2484 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2485 | chunk_appendf(&trash, |
| 2486 | "<td class=ac>" |
| 2487 | /* name */ |
| 2488 | "%s<a name=\"%s/Backend\"></a>" |
| 2489 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 2490 | "", |
| 2491 | (flags & ST_SHLGNDS)?"<u>":"", |
| 2492 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2493 | |
| 2494 | if (flags & ST_SHLGNDS) { |
| 2495 | /* balancing */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2496 | chunk_appendf(&trash, "<div>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2497 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 2498 | |
| 2499 | /* cookie */ |
| 2500 | if (px->cookie_name) { |
| 2501 | chunk_appendf(&trash, ", cookie: '"); |
| 2502 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 2503 | chunk_htmlencode(&trash, &src); |
| 2504 | chunk_appendf(&trash, "'"); |
| 2505 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2506 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2510 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2511 | /* queue : current, max */ |
| 2512 | "<td>%s</td><td>%s</td><td></td>" |
| 2513 | /* sessions rate : current, max, limit */ |
| 2514 | "<td>%s</td><td>%s</td><td></td>" |
| 2515 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2516 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2517 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 2518 | 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] | 2519 | |
| 2520 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2521 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2522 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2523 | "<td><u>%s<div><table class=det>" |
| 2524 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2525 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2526 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 2527 | U2H(px->be_counters.cum_conn), |
| 2528 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2529 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2530 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2531 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2532 | chunk_appendf(&trash, |
| 2533 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 2534 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 2535 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 2536 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 2537 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 2538 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 2539 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 2540 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 2541 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 2542 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2543 | U2H(px->be_counters.p.http.cum_req), |
| 2544 | U2H(px->be_counters.p.http.rsp[1]), |
| 2545 | U2H(px->be_counters.p.http.rsp[2]), |
| 2546 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2547 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2548 | (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] | 2549 | U2H(px->be_counters.p.http.rsp[3]), |
| 2550 | U2H(px->be_counters.p.http.rsp[4]), |
| 2551 | U2H(px->be_counters.p.http.rsp[5]), |
| 2552 | U2H(px->be_counters.p.http.rsp[0]), |
| 2553 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2557 | "</table></div></u></td>" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2558 | /* sessions: lbtot */ |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 2559 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2560 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2561 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2562 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2563 | U2H(px->be_counters.cum_lbconn), |
| 2564 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2565 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2566 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2567 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 2568 | "<td>%s%s<div>compression: in=%lld out=%lld bypassed=%lld savings=%d%%</div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2569 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2570 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2571 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 2572 | px->be_counters.comp_in ? |
| 2573 | (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] | 2574 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 2575 | |
| 2576 | chunk_appendf(&trash, |
| 2577 | /* denied: req, resp */ |
| 2578 | "<td>%s</td><td>%s</td>" |
| 2579 | /* errors : request, connect */ |
| 2580 | "<td></td><td>%s</td>" |
| 2581 | /* errors : response */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2582 | "<td><u>%s<div>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2583 | /* warnings: retries, redispatches */ |
| 2584 | "<td>%lld</td><td>%lld</td>" |
| 2585 | /* backend status: reflect backend status (up/down): we display UP |
| 2586 | * if the backend has known working servers or if it has no server at |
| 2587 | * all (eg: for stats). Then we display the total weight, number of |
| 2588 | * active and backups. */ |
| 2589 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 2590 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 2591 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 2592 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 2593 | U2H(px->be_counters.failed_conns), |
| 2594 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2595 | px->be_counters.cli_aborts, |
| 2596 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2597 | px->be_counters.retries, px->be_counters.redispatches, |
| 2598 | human_time(now.tv_sec - px->last_change, 1), |
| 2599 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 2600 | "<font color=\"red\"><b>DOWN</b></font>", |
| 2601 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2602 | px->srv_act, px->srv_bck); |
| 2603 | |
| 2604 | chunk_appendf(&trash, |
| 2605 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 2606 | "<td class=ac> </td><td>%d</td>" |
| 2607 | "<td>%s</td>" |
| 2608 | "<td></td>" |
| 2609 | "</tr>", |
| 2610 | px->down_trans, |
| 2611 | px->srv?human_time(be_downtime(px), 1):" "); |
| 2612 | } |
| 2613 | else { /* CSV mode */ |
| 2614 | chunk_appendf(&trash, |
| 2615 | /* pxid, name */ |
| 2616 | "%s,BACKEND," |
| 2617 | /* queue : current, max */ |
| 2618 | "%d,%d," |
| 2619 | /* sessions : current, max, limit, total */ |
| 2620 | "%d,%d,%d,%lld," |
| 2621 | /* bytes : in, out */ |
| 2622 | "%lld,%lld," |
| 2623 | /* denied: req, resp */ |
| 2624 | "%lld,%lld," |
| 2625 | /* errors : request, connect, response */ |
| 2626 | ",%lld,%lld," |
| 2627 | /* warnings: retries, redispatches */ |
| 2628 | "%lld,%lld," |
| 2629 | /* backend status: reflect backend status (up/down): we display UP |
| 2630 | * if the backend has known working servers or if it has no server at |
| 2631 | * all (eg: for stats). Then we display the total weight, number of |
| 2632 | * active and backups. */ |
| 2633 | "%s," |
| 2634 | "%d,%d,%d," |
| 2635 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 2636 | ",%d,%d,%d,," |
| 2637 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2638 | "%d,%d,0,,%lld,,%d," |
| 2639 | /* rate, rate_lim, rate_max, */ |
| 2640 | "%u,,%u," |
| 2641 | /* check_status, check_code, check_duration */ |
| 2642 | ",,,", |
| 2643 | px->id, |
| 2644 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 2645 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 2646 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 2647 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 2648 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 2649 | px->be_counters.retries, px->be_counters.redispatches, |
| 2650 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 2651 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 2652 | px->srv_act, px->srv_bck, |
| 2653 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 2654 | px->srv?be_downtime(px):0, |
| 2655 | relative_pid, px->uuid, |
| 2656 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 2657 | read_freq_ctr(&px->be_sess_per_sec), |
| 2658 | px->be_counters.sps_max); |
| 2659 | |
| 2660 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2661 | if (px->mode == PR_MODE_HTTP) { |
| 2662 | for (i=1; i<6; i++) |
| 2663 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 2664 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 2665 | } |
| 2666 | else |
| 2667 | chunk_appendf(&trash, ",,,,,,"); |
| 2668 | |
| 2669 | /* failed health analyses */ |
| 2670 | chunk_appendf(&trash, ","); |
| 2671 | |
| 2672 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2673 | chunk_appendf(&trash, ",,,"); |
| 2674 | |
| 2675 | /* errors: cli_aborts, srv_aborts */ |
| 2676 | chunk_appendf(&trash, "%lld,%lld,", |
| 2677 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 2678 | |
| 2679 | /* compression: in, out, bypassed */ |
| 2680 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2681 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 2682 | |
| 2683 | /* compression: comp_rsp */ |
| 2684 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 2685 | |
| 2686 | /* finish with EOL */ |
| 2687 | chunk_appendf(&trash, "\n"); |
| 2688 | } |
| 2689 | return 1; |
| 2690 | } |
| 2691 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2692 | /* 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] | 2693 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2694 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2695 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2696 | 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] | 2697 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2698 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 2699 | /* A form to enable/disable this proxy servers */ |
| 2700 | chunk_appendf(&trash, |
| 2701 | "<form action=\"%s\" method=\"post\">", |
| 2702 | uri->uri_prefix); |
| 2703 | } |
| 2704 | |
| 2705 | /* print a new table */ |
| 2706 | chunk_appendf(&trash, |
| 2707 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2708 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2709 | "<th class=\"pxname\" width=\"10%%\">"); |
| 2710 | |
| 2711 | chunk_appendf(&trash, |
| 2712 | "<a name=\"%s\"></a>%s" |
| 2713 | "<a class=px href=\"#%s\">%s</a>", |
| 2714 | px->id, |
| 2715 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 2716 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2717 | |
| 2718 | if (uri->flags & ST_SHLGNDS) { |
| 2719 | /* cap, mode, id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2720 | chunk_appendf(&trash, "<div>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2721 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 2722 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2723 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 2727 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2728 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 2729 | "</tr>\n" |
| 2730 | "</table>\n" |
| 2731 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2732 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2733 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 2734 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 2735 | |
| 2736 | if ((px->cap & PR_CAP_BE) && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 2737 | /* Column heading for Enable or Disable server */ |
| 2738 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2739 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2740 | |
| 2741 | chunk_appendf(&trash, |
| 2742 | "<th rowspan=2></th>" |
| 2743 | "<th colspan=3>Queue</th>" |
| 2744 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
| 2745 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 2746 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 2747 | "<th colspan=9>Server</th>" |
| 2748 | "</tr>\n" |
| 2749 | "<tr class=\"titre\">" |
| 2750 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 2751 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 2752 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>" |
| 2753 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 2754 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 2755 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 2756 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 2757 | "<th>Thrtle</th>\n" |
| 2758 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2759 | } |
| 2760 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2761 | /* 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] | 2762 | * 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] | 2763 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2764 | 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] | 2765 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2766 | chunk_appendf(&trash, "</table>"); |
| 2767 | |
| 2768 | if ((px->cap & PR_CAP_BE) && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
| 2769 | /* close the form used to enable/disable this proxy servers */ |
| 2770 | chunk_appendf(&trash, |
| 2771 | "Choose the action to perform on the checked servers : " |
| 2772 | "<select name=action>" |
| 2773 | "<option value=\"\"></option>" |
| 2774 | "<option value=\"disable\">Disable</option>" |
| 2775 | "<option value=\"enable\">Enable</option>" |
| 2776 | "<option value=\"stop\">Soft Stop</option>" |
| 2777 | "<option value=\"start\">Soft Start</option>" |
| 2778 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 2779 | "</select>" |
| 2780 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 2781 | " <input type=\"submit\" value=\"Apply\">" |
| 2782 | "</form>", |
| 2783 | px->uuid); |
| 2784 | } |
| 2785 | |
| 2786 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2787 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2788 | |
| 2789 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2790 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 2791 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 2792 | * buffer space, or non-zero if everything completed. This function is used |
| 2793 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 2794 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2795 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2796 | 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] | 2797 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 2798 | struct session *s = si->conn->xprt_ctx; |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2799 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2800 | 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] | 2801 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2802 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2803 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2804 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2805 | switch (si->applet.ctx.stats.px_st) { |
| 2806 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2807 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2808 | if (uri && uri->scope) { |
| 2809 | /* we have a limited scope, we have to check the proxy name */ |
| 2810 | struct stat_scope *scope; |
| 2811 | int len; |
| 2812 | |
| 2813 | len = strlen(px->id); |
| 2814 | scope = uri->scope; |
| 2815 | |
| 2816 | while (scope) { |
| 2817 | /* match exact proxy name */ |
| 2818 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 2819 | break; |
| 2820 | |
| 2821 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 2822 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2823 | break; |
| 2824 | scope = scope->next; |
| 2825 | } |
| 2826 | |
| 2827 | /* proxy name not found : don't dump anything */ |
| 2828 | if (scope == NULL) |
| 2829 | return 1; |
| 2830 | } |
| 2831 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2832 | if ((si->applet.ctx.stats.flags & STAT_BOUND) && |
| 2833 | (si->applet.ctx.stats.iid != -1) && |
| 2834 | (px->uuid != si->applet.ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2835 | return 1; |
| 2836 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2837 | si->applet.ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2838 | /* fall through */ |
| 2839 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2840 | case STAT_PX_ST_TH: |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 2841 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2842 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2843 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2844 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2845 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2846 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2847 | si->applet.ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2848 | /* fall through */ |
| 2849 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2850 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2851 | /* print the frontend */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2852 | if (stats_dump_fe_stats(si, px)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2853 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2854 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2855 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2856 | si->applet.ctx.stats.l = px->conf.listeners.n; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2857 | si->applet.ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2858 | /* fall through */ |
| 2859 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2860 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2861 | /* stats.l has been initialized above */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2862 | 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] | 2863 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2864 | return 0; |
| 2865 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2866 | 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] | 2867 | if (!l->counters) |
| 2868 | continue; |
| 2869 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2870 | if (si->applet.ctx.stats.flags & STAT_BOUND) { |
| 2871 | if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2872 | break; |
| 2873 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2874 | 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] | 2875 | continue; |
| 2876 | } |
| 2877 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2878 | /* print the frontend */ |
| 2879 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) |
| 2880 | if (bi_putchk(rep, &trash) == -1) |
| 2881 | return 0; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2882 | } |
| 2883 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2884 | si->applet.ctx.stats.sv = px->srv; /* may be NULL */ |
| 2885 | si->applet.ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2886 | /* fall through */ |
| 2887 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2888 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2889 | /* stats.sv has been initialized above */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2890 | 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] | 2891 | 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] | 2892 | |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2893 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2894 | return 0; |
| 2895 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2896 | sv = si->applet.ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2897 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2898 | if (si->applet.ctx.stats.flags & STAT_BOUND) { |
| 2899 | if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2900 | break; |
| 2901 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2902 | 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] | 2903 | continue; |
| 2904 | } |
| 2905 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2906 | if (sv->track) |
| 2907 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2908 | else |
| 2909 | svs = sv; |
| 2910 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2911 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2912 | if (!(svs->state & SRV_CHECKED)) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2913 | sv_state = 6; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2914 | else if (svs->state & SRV_RUNNING) { |
| 2915 | if (svs->health == svs->rise + svs->fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2916 | sv_state = 3; /* UP */ |
| 2917 | else |
| 2918 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2919 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2920 | if (svs->state & SRV_GOINGDOWN) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2921 | sv_state += 2; |
| 2922 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2923 | else |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2924 | if (svs->health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2925 | sv_state = 1; /* going up */ |
| 2926 | else |
| 2927 | sv_state = 0; /* DOWN */ |
| 2928 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2929 | 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] | 2930 | /* do not report servers which are DOWN */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2931 | si->applet.ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2932 | continue; |
| 2933 | } |
| 2934 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2935 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state)) |
| 2936 | if (bi_putchk(rep, &trash) == -1) |
| 2937 | return 0; |
| 2938 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 2939 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2940 | si->applet.ctx.stats.px_st = STAT_PX_ST_BE; |
| 2941 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2942 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2943 | case STAT_PX_ST_BE: |
| 2944 | /* print the backend */ |
| 2945 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) |
| 2946 | if (bi_putchk(rep, &trash) == -1) |
| 2947 | return 0; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2948 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2949 | si->applet.ctx.stats.px_st = STAT_PX_ST_END; |
| 2950 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2951 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2952 | case STAT_PX_ST_END: |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 2953 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2954 | stats_dump_html_px_end(si, px); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2955 | if (bi_putchk(rep, &trash) == -1) |
| 2956 | return 0; |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2957 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2958 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2959 | si->applet.ctx.stats.px_st = STAT_PX_ST_FIN; |
| 2960 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2961 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2962 | case STAT_PX_ST_FIN: |
| 2963 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2964 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2965 | default: |
| 2966 | /* unknown state, we should put an abort() here ! */ |
| 2967 | return 1; |
| 2968 | } |
| 2969 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2970 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2971 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 2972 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2973 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2974 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2975 | { |
| 2976 | /* WARNING! This must fit in the first buffer !!! */ |
| 2977 | chunk_appendf(&trash, |
| 2978 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 2979 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 2980 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 2981 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 2982 | "<style type=\"text/css\"><!--\n" |
| 2983 | "body {" |
| 2984 | " font-family: arial, helvetica, sans-serif;" |
| 2985 | " font-size: 12px;" |
| 2986 | " font-weight: normal;" |
| 2987 | " color: black;" |
| 2988 | " background: white;" |
| 2989 | "}\n" |
| 2990 | "th,td {" |
| 2991 | " font-size: 10px;" |
| 2992 | "}\n" |
| 2993 | "h1 {" |
| 2994 | " font-size: x-large;" |
| 2995 | " margin-bottom: 0.5em;" |
| 2996 | "}\n" |
| 2997 | "h2 {" |
| 2998 | " font-family: helvetica, arial;" |
| 2999 | " font-size: x-large;" |
| 3000 | " font-weight: bold;" |
| 3001 | " font-style: italic;" |
| 3002 | " color: #6020a0;" |
| 3003 | " margin-top: 0em;" |
| 3004 | " margin-bottom: 0em;" |
| 3005 | "}\n" |
| 3006 | "h3 {" |
| 3007 | " font-family: helvetica, arial;" |
| 3008 | " font-size: 16px;" |
| 3009 | " font-weight: bold;" |
| 3010 | " color: #b00040;" |
| 3011 | " background: #e8e8d0;" |
| 3012 | " margin-top: 0em;" |
| 3013 | " margin-bottom: 0em;" |
| 3014 | "}\n" |
| 3015 | "li {" |
| 3016 | " margin-top: 0.25em;" |
| 3017 | " margin-right: 2em;" |
| 3018 | "}\n" |
| 3019 | ".hr {margin-top: 0.25em;" |
| 3020 | " border-color: black;" |
| 3021 | " border-bottom-style: solid;" |
| 3022 | "}\n" |
| 3023 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3024 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3025 | ".frontend {background: #e8e8d0;}\n" |
| 3026 | ".socket {background: #d0d0d0;}\n" |
| 3027 | ".backend {background: #e8e8d0;}\n" |
| 3028 | ".active0 {background: #ff9090;}\n" |
| 3029 | ".active1 {background: #ffd020;}\n" |
| 3030 | ".active2 {background: #ffffa0;}\n" |
| 3031 | ".active3 {background: #c0ffc0;}\n" |
| 3032 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 3033 | ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */ |
| 3034 | ".active6 {background: #e0e0e0;}\n" |
| 3035 | ".backup0 {background: #ff9090;}\n" |
| 3036 | ".backup1 {background: #ff80ff;}\n" |
| 3037 | ".backup2 {background: #c060ff;}\n" |
| 3038 | ".backup3 {background: #b0d0ff;}\n" |
| 3039 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 3040 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 3041 | ".backup6 {background: #e0e0e0;}\n" |
| 3042 | ".maintain {background: #c07820;}\n" |
| 3043 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3044 | "\n" |
| 3045 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3046 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3047 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3048 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3049 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3050 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3051 | "\n" |
| 3052 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3053 | "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" |
| 3054 | "table.tbl td.ac { text-align: center;}\n" |
| 3055 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3056 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3057 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3058 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3059 | "\n" |
| 3060 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3061 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3062 | "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] | 3063 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3064 | "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" |
| 3065 | "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] | 3066 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3067 | "div {\n" |
| 3068 | " display:block;\n" |
| 3069 | " visibility:hidden;\n" |
| 3070 | " z-index:2147483647;\n" |
| 3071 | " position:absolute;\n" |
| 3072 | " padding:2px 4px 3px;\n" |
| 3073 | " background:#f0f060; color:#000000;\n" |
| 3074 | " border:1px solid #7040c0;\n" |
| 3075 | " white-space:nowrap;\n" |
| 3076 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3077 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3078 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3079 | "}\n" |
| 3080 | "u:hover div {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3081 | "-->\n" |
| 3082 | "</style></head>\n", |
| 3083 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 3084 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 3085 | ); |
| 3086 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3087 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3088 | /* 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] | 3089 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3090 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3091 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3092 | 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] | 3093 | { |
| 3094 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3095 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3096 | /* WARNING! this has to fit the first packet too. |
| 3097 | * We are around 3.5 kB, add adding entries will |
| 3098 | * become tricky if we want to support 4kB buffers ! |
| 3099 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3100 | chunk_appendf(&trash, |
| 3101 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3102 | PRODUCT_NAME "%s</a></h1>\n" |
| 3103 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3104 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3105 | "<h3>> General process information</h3>\n" |
| 3106 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 3107 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 3108 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3109 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3110 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 3111 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 3112 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3113 | "</td><td align=\"center\" nowrap>\n" |
| 3114 | "<table class=\"lgd\"><tr>\n" |
| 3115 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 3116 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 3117 | "</tr><tr>\n" |
| 3118 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3119 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3120 | "</tr><tr>\n" |
| 3121 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3122 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3123 | "</tr><tr>\n" |
| 3124 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 3125 | "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>" |
| 3126 | "</tr><tr>\n" |
| 3127 | "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) </td>" |
| 3128 | "</tr></table>\n" |
| 3129 | "Note: UP with load-balancing disabled is reported as \"NOLB\"." |
| 3130 | "</td>" |
| 3131 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3132 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3133 | "", |
| 3134 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 3135 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 3136 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3137 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 3138 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 3139 | pid, relative_pid, global.nbproc, |
| 3140 | up / 86400, (up % 86400) / 3600, |
| 3141 | (up % 3600) / 60, (up % 60), |
| 3142 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3143 | global.rlimit_memmax ? " MB" : "", |
| 3144 | global.rlimit_nofile, |
| 3145 | global.maxsock, global.maxconn, global.maxpipes, |
| 3146 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 3147 | run_queue_cur, nb_tasks_cur, idle_pct |
| 3148 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3149 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3150 | if (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) |
| 3151 | chunk_appendf(&trash, |
| 3152 | "<li><a href=\"%s%s%s\">Show all servers</a><br>\n", |
| 3153 | uri->uri_prefix, |
| 3154 | "", |
| 3155 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
| 3156 | else |
| 3157 | chunk_appendf(&trash, |
| 3158 | "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 3159 | uri->uri_prefix, |
| 3160 | ";up", |
| 3161 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3162 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3163 | if (uri->refresh > 0) { |
| 3164 | if (si->applet.ctx.stats.flags & STAT_NO_REFRESH) |
| 3165 | chunk_appendf(&trash, |
| 3166 | "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n", |
| 3167 | uri->uri_prefix, |
| 3168 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3169 | ""); |
| 3170 | else |
| 3171 | chunk_appendf(&trash, |
| 3172 | "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n", |
| 3173 | uri->uri_prefix, |
| 3174 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3175 | ";norefresh"); |
| 3176 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3177 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3178 | chunk_appendf(&trash, |
| 3179 | "<li><a href=\"%s%s%s\">Refresh now</a><br>\n", |
| 3180 | uri->uri_prefix, |
| 3181 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3182 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3183 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3184 | chunk_appendf(&trash, |
| 3185 | "<li><a href=\"%s;csv%s\">CSV export</a><br>\n", |
| 3186 | uri->uri_prefix, |
| 3187 | (uri->refresh > 0) ? ";norefresh" : ""); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3188 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3189 | chunk_appendf(&trash, |
| 3190 | "</ul></td>" |
| 3191 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3192 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3193 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3194 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3195 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3196 | "</ul>" |
| 3197 | "</td>" |
| 3198 | "</tr></table>\n" |
| 3199 | "" |
| 3200 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3201 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3202 | if (si->applet.ctx.stats.st_code) { |
| 3203 | switch (si->applet.ctx.stats.st_code) { |
| 3204 | case STAT_STATUS_DONE: |
| 3205 | chunk_appendf(&trash, |
| 3206 | "<p><div class=active3>" |
| 3207 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 3208 | "Action processed successfully." |
| 3209 | "</div>\n", uri->uri_prefix); |
| 3210 | break; |
| 3211 | case STAT_STATUS_NONE: |
| 3212 | chunk_appendf(&trash, |
| 3213 | "<p><div class=active2>" |
| 3214 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 3215 | "Nothing has changed." |
| 3216 | "</div>\n", uri->uri_prefix); |
| 3217 | break; |
| 3218 | case STAT_STATUS_PART: |
| 3219 | chunk_appendf(&trash, |
| 3220 | "<p><div class=active2>" |
| 3221 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 3222 | "Action partially processed.<br>" |
| 3223 | "Some server names are probably unknown or ambiguous (duplicated names in the backend)." |
| 3224 | "</div>\n", uri->uri_prefix); |
| 3225 | break; |
| 3226 | case STAT_STATUS_ERRP: |
| 3227 | chunk_appendf(&trash, |
| 3228 | "<p><div class=active0>" |
| 3229 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 3230 | "Action not processed because of invalid parameters." |
| 3231 | "<ul>" |
| 3232 | "<li>The action is maybe unknown.</li>" |
| 3233 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3234 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3235 | "</ul>" |
| 3236 | "</div>\n", uri->uri_prefix); |
| 3237 | break; |
| 3238 | case STAT_STATUS_EXCD: |
| 3239 | chunk_appendf(&trash, |
| 3240 | "<p><div class=active0>" |
| 3241 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 3242 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3243 | "You should retry with less servers at a time.</b>" |
| 3244 | "</div>\n", uri->uri_prefix); |
| 3245 | break; |
| 3246 | case STAT_STATUS_DENY: |
| 3247 | chunk_appendf(&trash, |
| 3248 | "<p><div class=active0>" |
| 3249 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 3250 | "<b>Action denied.</b>" |
| 3251 | "</div>\n", uri->uri_prefix); |
| 3252 | break; |
| 3253 | default: |
| 3254 | chunk_appendf(&trash, |
| 3255 | "<p><div class=active6>" |
| 3256 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 3257 | "Unexpected result." |
| 3258 | "</div>\n", uri->uri_prefix); |
| 3259 | } |
| 3260 | chunk_appendf(&trash, "<p>\n"); |
| 3261 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3262 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3263 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3264 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3265 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3266 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3267 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3268 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3269 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3270 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3271 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3272 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3273 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
| 3274 | * are ignored for CSV format (hence <uri> may be NULL there). The xprt_ctx must |
| 3275 | * have been zeroed first, and the flags properly set. It returns 0 if it had to |
| 3276 | * stop writing data and an I/O is needed, 1 if the dump is finished and the |
| 3277 | * session must be closed, or -1 in case of any error. This function is used by |
| 3278 | * both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3279 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3280 | 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] | 3281 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3282 | struct channel *rep = si->ib; |
| 3283 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3284 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3285 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3286 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3287 | switch (si->conn->xprt_st) { |
| 3288 | case STAT_ST_INIT: |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3289 | si->conn->xprt_st = STAT_ST_HEAD; /* let's start producing data */ |
| 3290 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3291 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3292 | case STAT_ST_HEAD: |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3293 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3294 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3295 | else |
| 3296 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3297 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3298 | if (bi_putchk(rep, &trash) == -1) |
| 3299 | return 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3300 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3301 | si->conn->xprt_st = STAT_ST_INFO; |
| 3302 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3303 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3304 | case STAT_ST_INFO: |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3305 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3306 | stats_dump_html_info(si, uri); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3307 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3308 | return 0; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3309 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3310 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3311 | si->applet.ctx.stats.px = proxy; |
| 3312 | si->applet.ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3313 | si->conn->xprt_st = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3314 | /* fall through */ |
| 3315 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3316 | case STAT_ST_LIST: |
| 3317 | /* dump proxies */ |
| 3318 | while (si->applet.ctx.stats.px) { |
| 3319 | if (buffer_almost_full(rep->buf)) |
| 3320 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3321 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3322 | px = si->applet.ctx.stats.px; |
| 3323 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 3324 | 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] | 3325 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3326 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3327 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3328 | si->applet.ctx.stats.px = px->next; |
| 3329 | si->applet.ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3330 | } |
| 3331 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3332 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3333 | si->conn->xprt_st = STAT_ST_END; |
| 3334 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3335 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3336 | case STAT_ST_END: |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 3337 | if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3338 | stats_dump_html_end(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3339 | if (bi_putchk(rep, &trash) == -1) |
| 3340 | return 0; |
| 3341 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3342 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3343 | si->conn->xprt_st = STAT_ST_FIN; |
| 3344 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 3345 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3346 | case STAT_ST_FIN: |
| 3347 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3348 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3349 | default: |
| 3350 | /* unknown state ! */ |
| 3351 | si->conn->xprt_st = STAT_ST_FIN; |
| 3352 | return -1; |
| 3353 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3354 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3355 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3356 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 3357 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
| 3358 | * si->applet.st0 becomes non-zero once the transfer is finished. The handler |
| 3359 | * automatically unregisters itself once transfer is complete. |
| 3360 | */ |
| 3361 | static void http_stats_io_handler(struct stream_interface *si) |
| 3362 | { |
| 3363 | struct session *s = si->conn->xprt_ctx; |
| 3364 | struct channel *req = si->ob; |
| 3365 | struct channel *res = si->ib; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3366 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3367 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 3368 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3369 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3370 | /* check that the output is not closed */ |
| 3371 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
| 3372 | si->applet.st0 = 1; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3373 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3374 | if (!si->applet.st0) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3375 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) { |
Willy Tarreau | 1facd6d | 2012-12-22 22:03:39 +0100 | [diff] [blame] | 3376 | si->applet.st0 = 1; |
| 3377 | si_shutw(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3378 | } |
| 3379 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3380 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3381 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 3382 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3383 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3384 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && si->applet.st0) { |
| 3385 | si_shutr(si); |
| 3386 | res->flags |= CF_READ_NULL; |
| 3387 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3388 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3389 | /* update all other flags and resync with the other side */ |
| 3390 | si_update(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3391 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3392 | /* we don't want to expire timeouts while we're processing requests */ |
| 3393 | si->ib->rex = TICK_ETERNITY; |
| 3394 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3395 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3396 | out: |
| 3397 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 3398 | /* check that we have released everything then unregister */ |
| 3399 | stream_int_unregister_handler(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3400 | } |
| 3401 | } |
| 3402 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3403 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3404 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 3405 | { |
| 3406 | if (!conn->ctrl) |
| 3407 | return "NONE"; |
| 3408 | return conn->ctrl->name; |
| 3409 | } |
| 3410 | |
| 3411 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 3412 | { |
| 3413 | static char ptr[17]; |
| 3414 | |
| 3415 | if (!conn->xprt) |
| 3416 | return "NONE"; |
| 3417 | |
| 3418 | if (conn->xprt == &raw_sock) |
| 3419 | return "RAW"; |
| 3420 | |
| 3421 | #ifdef USE_OPENSSL |
| 3422 | if (conn->xprt == &ssl_sock) |
| 3423 | return "SSL"; |
| 3424 | #endif |
| 3425 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 3426 | return ptr; |
| 3427 | } |
| 3428 | |
| 3429 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 3430 | { |
| 3431 | static char ptr[17]; |
| 3432 | |
| 3433 | if (!conn->data) |
| 3434 | return "NONE"; |
| 3435 | |
| 3436 | if (conn->data == &sess_conn_cb) |
| 3437 | return "SESS"; |
| 3438 | |
| 3439 | if (conn->data == &si_conn_cb) |
| 3440 | return "STRM"; |
| 3441 | |
| 3442 | if (conn->data == &check_conn_cb) |
| 3443 | return "CHCK"; |
| 3444 | |
| 3445 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 3446 | return ptr; |
| 3447 | } |
| 3448 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 3449 | /* This function dumps a complete session state onto the stream interface's |
| 3450 | * read buffer. The xprt_ctx must have been zeroed first, and the flags |
| 3451 | * 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] | 3452 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 3453 | * 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] | 3454 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3455 | 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] | 3456 | { |
| 3457 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3458 | extern const char *monthname[12]; |
| 3459 | char pn[INET6_ADDRSTRLEN]; |
| 3460 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3461 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3462 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3463 | 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] | 3464 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3465 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 3466 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3467 | return 0; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3468 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3469 | si->applet.ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3470 | return 1; |
| 3471 | } |
| 3472 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3473 | switch (si->applet.ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3474 | case 0: /* main status of the session */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3475 | si->applet.ctx.sess.uid = sess->uniq_id; |
| 3476 | si->applet.ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3477 | /* fall through */ |
| 3478 | |
| 3479 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3480 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3481 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3482 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3483 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3484 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 3485 | 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] | 3486 | sess->uniq_id, |
Willy Tarreau | e95c4ce | 2013-01-24 00:48:39 +0100 | [diff] [blame] | 3487 | sess->listener && sess->listener->proto->name ? sess->listener->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3488 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3489 | 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] | 3490 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3491 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3492 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3493 | pn, get_host_port(&sess->si[0].conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3494 | break; |
| 3495 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3496 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3497 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3498 | default: |
| 3499 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3500 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3501 | break; |
| 3502 | } |
| 3503 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3504 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3505 | " 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] | 3506 | 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] | 3507 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3508 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3509 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3510 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 3511 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 3512 | sess->listener ? sess->listener->luid : 0); |
| 3513 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3514 | conn_get_to_addr(sess->si[0].conn); |
| 3515 | 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] | 3516 | case AF_INET: |
| 3517 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3518 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3519 | pn, get_host_port(&sess->si[0].conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3520 | break; |
| 3521 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3522 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3523 | break; |
| 3524 | default: |
| 3525 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3526 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3527 | break; |
| 3528 | } |
| 3529 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3530 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3531 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3532 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3533 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3534 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 3535 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3536 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3537 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3538 | conn_get_from_addr(sess->si[1].conn); |
| 3539 | 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] | 3540 | case AF_INET: |
| 3541 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3542 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3543 | pn, get_host_port(&sess->si[1].conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3544 | break; |
| 3545 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3546 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3547 | break; |
| 3548 | default: |
| 3549 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3550 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3551 | break; |
| 3552 | } |
| 3553 | |
| 3554 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3555 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3556 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 3557 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 3558 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3559 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3560 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3561 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3562 | conn_get_to_addr(sess->si[1].conn); |
| 3563 | 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] | 3564 | case AF_INET: |
| 3565 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3566 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3567 | pn, get_host_port(&sess->si[1].conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3568 | break; |
| 3569 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3570 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3571 | break; |
| 3572 | default: |
| 3573 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3574 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3575 | break; |
| 3576 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3577 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3578 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3579 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3580 | sess->task, |
| 3581 | sess->task->state, |
| 3582 | sess->task->nice, sess->task->calls, |
| 3583 | sess->task->expire ? |
| 3584 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 3585 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 3586 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3587 | task_in_rq(sess->task) ? ", running" : ""); |
| 3588 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3589 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3590 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3591 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 3592 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3593 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3594 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
| 3595 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 3596 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
| 3597 | |
| 3598 | chunk_appendf(&trash, |
| 3599 | " 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] | 3600 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3601 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3602 | sess->si[0].flags, |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3603 | sess->si[0].conn, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3604 | sess->si[0].exp ? |
| 3605 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 3606 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 3607 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3608 | sess->si[0].err_type); |
| 3609 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3610 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3611 | " 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] | 3612 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3613 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3614 | sess->si[1].flags, |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3615 | sess->si[1].conn, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3616 | sess->si[1].exp ? |
| 3617 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 3618 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 3619 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3620 | sess->si[1].err_type); |
| 3621 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3622 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3623 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3624 | sess->si[0].conn, |
| 3625 | get_conn_ctrl_name(sess->si[0].conn), |
| 3626 | get_conn_xprt_name(sess->si[0].conn), |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3627 | get_conn_data_name(sess->si[0].conn), |
| 3628 | obj_type_name(sess->si[0].conn->target), |
| 3629 | obj_base_ptr(sess->si[0].conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3630 | |
| 3631 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3632 | " 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] | 3633 | sess->si[0].conn->flags, |
| 3634 | sess->si[0].conn->t.sock.fd, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3635 | sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].spec_e : 0, |
| 3636 | sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].spec_p : 0, |
| 3637 | 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] | 3638 | |
| 3639 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3640 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3641 | sess->si[1].conn, |
| 3642 | get_conn_ctrl_name(sess->si[1].conn), |
| 3643 | get_conn_xprt_name(sess->si[1].conn), |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3644 | get_conn_data_name(sess->si[1].conn), |
| 3645 | obj_type_name(sess->si[1].conn->target), |
| 3646 | obj_base_ptr(sess->si[1].conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3647 | |
| 3648 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3649 | " 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] | 3650 | sess->si[1].conn->flags, |
| 3651 | sess->si[1].conn->t.sock.fd, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 3652 | sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].spec_e : 0, |
| 3653 | sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].spec_p : 0, |
| 3654 | 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] | 3655 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3656 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3657 | " 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] | 3658 | " an_exp=%s", |
| 3659 | sess->req, |
| 3660 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3661 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3662 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3663 | sess->req->analyse_exp ? |
| 3664 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 3665 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3666 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3667 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3668 | " rex=%s", |
| 3669 | sess->req->rex ? |
| 3670 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 3671 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3672 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3673 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3674 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3675 | " 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] | 3676 | sess->req->wex ? |
| 3677 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 3678 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3679 | sess->req->buf, |
| 3680 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3681 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3682 | sess->txn.req.next, sess->req->buf->i, |
| 3683 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3684 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3685 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3686 | " 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] | 3687 | " an_exp=%s", |
| 3688 | sess->rep, |
| 3689 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3690 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3691 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3692 | sess->rep->analyse_exp ? |
| 3693 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 3694 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3695 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3696 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3697 | " rex=%s", |
| 3698 | sess->rep->rex ? |
| 3699 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 3700 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3701 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3702 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3703 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3704 | " 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] | 3705 | sess->rep->wex ? |
| 3706 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 3707 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3708 | sess->rep->buf, |
| 3709 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3710 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3711 | sess->txn.rsp.next, sess->rep->buf->i, |
| 3712 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3713 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3714 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3715 | return 0; |
| 3716 | |
| 3717 | /* use other states to dump the contents */ |
| 3718 | } |
| 3719 | /* end of dump */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3720 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3721 | si->applet.ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3722 | return 1; |
| 3723 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3724 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 3725 | /* This function dumps all sessions' states onto the stream interface's |
| 3726 | * 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] | 3727 | * properly set. It returns 0 if the output buffer is full and it needs |
| 3728 | * to be called again, otherwise non-zero. It is designed to be called |
| 3729 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3730 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 3731 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3732 | { |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 3733 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3734 | /* If we're forced to shut down, we might have to remove our |
| 3735 | * reference to the last session being dumped. |
| 3736 | */ |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3737 | if (si->conn->xprt_st == STAT_ST_LIST) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3738 | if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) { |
| 3739 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3740 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3741 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3742 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 3743 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3744 | } |
| 3745 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3746 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3747 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3748 | switch (si->conn->xprt_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3749 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3750 | /* the function had not been called yet, let's prepare the |
| 3751 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3752 | * pointer to the first in the global list. When a target |
| 3753 | * session is being destroyed, it is responsible for updating |
| 3754 | * this pointer. We know we have reached the end when this |
| 3755 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3756 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3757 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
| 3758 | si->applet.ctx.sess.bref.ref = sessions.n; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3759 | si->conn->xprt_st = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3760 | /* fall through */ |
| 3761 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3762 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3763 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3764 | if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) { |
| 3765 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3766 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | /* and start from where we stopped */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3770 | while (si->applet.ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 3771 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3772 | struct session *curr_sess; |
| 3773 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3774 | 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] | 3775 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3776 | if (si->applet.ctx.sess.target) { |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3777 | 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] | 3778 | goto next_sess; |
| 3779 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3780 | LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3781 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3782 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3783 | return 0; |
| 3784 | |
| 3785 | /* session dump complete */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3786 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3787 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3788 | if (si->applet.ctx.sess.target != (void *)-1) { |
| 3789 | si->applet.ctx.sess.target = NULL; |
| 3790 | break; |
| 3791 | } |
| 3792 | else |
| 3793 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3794 | } |
| 3795 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3796 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3797 | "%p: proto=%s", |
| 3798 | curr_sess, |
| 3799 | curr_sess->listener->proto->name); |
| 3800 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3801 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3802 | 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] | 3803 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3804 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3805 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3806 | " src=%s:%d fe=%s be=%s srv=%s", |
| 3807 | pn, |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3808 | get_host_port(&curr_sess->si[0].conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3809 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3810 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 3811 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3812 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3813 | break; |
| 3814 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3815 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3816 | " src=unix:%d fe=%s be=%s srv=%s", |
| 3817 | curr_sess->listener->luid, |
| 3818 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3819 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 3820 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3821 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3822 | break; |
| 3823 | } |
| 3824 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3825 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 3826 | " ts=%02x age=%s calls=%d", |
| 3827 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 3828 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 3829 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3830 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3831 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 3832 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3833 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3834 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3835 | curr_sess->req->analysers, |
| 3836 | curr_sess->req->rex ? |
| 3837 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 3838 | TICKS_TO_MS(1000)) : ""); |
| 3839 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3840 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3841 | ",wx=%s", |
| 3842 | curr_sess->req->wex ? |
| 3843 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 3844 | TICKS_TO_MS(1000)) : ""); |
| 3845 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3846 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3847 | ",ax=%s]", |
| 3848 | curr_sess->req->analyse_exp ? |
| 3849 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 3850 | TICKS_TO_MS(1000)) : ""); |
| 3851 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3852 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 3853 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3854 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3855 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3856 | curr_sess->rep->analysers, |
| 3857 | curr_sess->rep->rex ? |
| 3858 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 3859 | TICKS_TO_MS(1000)) : ""); |
| 3860 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3861 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3862 | ",wx=%s", |
| 3863 | curr_sess->rep->wex ? |
| 3864 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 3865 | TICKS_TO_MS(1000)) : ""); |
| 3866 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3867 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3868 | ",ax=%s]", |
| 3869 | curr_sess->rep->analyse_exp ? |
| 3870 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 3871 | TICKS_TO_MS(1000)) : ""); |
| 3872 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3873 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3874 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 3875 | curr_sess->si[0].state, |
| 3876 | curr_sess->si[0].flags, |
Willy Tarreau | 7f7ad91 | 2012-11-11 19:27:15 +0100 | [diff] [blame] | 3877 | curr_sess->si[0].conn->t.sock.fd, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3878 | curr_sess->si[0].exp ? |
| 3879 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 3880 | TICKS_TO_MS(1000)) : ""); |
| 3881 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3882 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3883 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 3884 | curr_sess->si[1].state, |
| 3885 | curr_sess->si[1].flags, |
Willy Tarreau | 7f7ad91 | 2012-11-11 19:27:15 +0100 | [diff] [blame] | 3886 | curr_sess->si[1].conn->t.sock.fd, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3887 | curr_sess->si[1].exp ? |
| 3888 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 3889 | TICKS_TO_MS(1000)) : ""); |
| 3890 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3891 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3892 | " exp=%s", |
| 3893 | curr_sess->task->expire ? |
| 3894 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 3895 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 3896 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3897 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3898 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3899 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3900 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3901 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3902 | /* let's try again later from this session. We add ourselves into |
| 3903 | * this session's users so that it can remove us upon termination. |
| 3904 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3905 | LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 3906 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3907 | } |
| 3908 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3909 | next_sess: |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3910 | si->applet.ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3911 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3912 | |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3913 | 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] | 3914 | /* specified session not found */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3915 | if (si->applet.ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3916 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3917 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3918 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3919 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3920 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3921 | return 0; |
| 3922 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3923 | si->applet.ctx.sess.target = NULL; |
| 3924 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3925 | return 1; |
| 3926 | } |
| 3927 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3928 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3929 | /* fall through */ |
| 3930 | |
| 3931 | default: |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3932 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 3933 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3934 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 3935 | } |
| 3936 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 3937 | /* This is called when the stream interface is closed. For instance, upon an |
| 3938 | * external abort, we won't call the i/o handler anymore so we may need to |
| 3939 | * remove back references to the session currently being dumped. |
| 3940 | */ |
Simon Horman | 74d8831 | 2013-02-12 10:45:50 +0900 | [diff] [blame] | 3941 | static void cli_release_handler(struct stream_interface *si) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 3942 | { |
| 3943 | if (si->applet.st0 == STAT_CLI_O_SESS && si->conn->xprt_st == STAT_ST_LIST) { |
| 3944 | if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) |
| 3945 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3946 | } |
| 3947 | } |
| 3948 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame^] | 3949 | /* This function is used to either dump tables states (when action is set |
| 3950 | * to STAT_CLI_O_TAB) or clear tables (when action is STAT_CLI_O_CLR). |
| 3951 | * The xprt_ctx must have been zeroed first, and the flags properly set. |
| 3952 | * It returns 0 if the output buffer is full and it needs to be called |
| 3953 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3954 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame^] | 3955 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3956 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3957 | struct session *s = si->conn->xprt_ctx; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3958 | struct ebmb_node *eb; |
| 3959 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 3960 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame^] | 3961 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3962 | |
| 3963 | /* |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3964 | * We have 3 possible states in si->conn->xprt_st : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3965 | * - STAT_ST_INIT : the first call |
| 3966 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3967 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3968 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3969 | * and the entry pointer points to the next entry to be dumped, |
| 3970 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3971 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3972 | * data though. |
| 3973 | */ |
| 3974 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 3975 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3976 | /* 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] | 3977 | if (si->conn->xprt_st == STAT_ST_LIST) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3978 | si->applet.ctx.table.entry->ref_cnt--; |
| 3979 | 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] | 3980 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3981 | return 1; |
| 3982 | } |
| 3983 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3984 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3985 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3986 | while (si->conn->xprt_st != STAT_ST_FIN) { |
| 3987 | switch (si->conn->xprt_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3988 | case STAT_ST_INIT: |
| 3989 | si->applet.ctx.table.proxy = si->applet.ctx.table.target; |
| 3990 | if (!si->applet.ctx.table.proxy) |
| 3991 | si->applet.ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3992 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3993 | si->applet.ctx.table.entry = NULL; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3994 | si->conn->xprt_st = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3995 | break; |
| 3996 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3997 | case STAT_ST_INFO: |
| 3998 | if (!si->applet.ctx.table.proxy || |
| 3999 | (si->applet.ctx.table.target && |
| 4000 | si->applet.ctx.table.proxy != si->applet.ctx.table.target)) { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4001 | si->conn->xprt_st = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4002 | break; |
| 4003 | } |
| 4004 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4005 | if (si->applet.ctx.table.proxy->table.size) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4006 | 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] | 4007 | si->applet.ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4008 | return 0; |
| 4009 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4010 | if (si->applet.ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 4011 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4012 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4013 | eb = ebmb_first(&si->applet.ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4014 | if (eb) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4015 | si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 4016 | si->applet.ctx.table.entry->ref_cnt++; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4017 | si->conn->xprt_st = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4018 | break; |
| 4019 | } |
| 4020 | } |
| 4021 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4022 | si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4023 | break; |
| 4024 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4025 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4026 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4027 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4028 | if (si->applet.ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4029 | /* we're filtering on some data contents */ |
| 4030 | void *ptr; |
| 4031 | long long data; |
| 4032 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4033 | dt = si->applet.ctx.table.data_type; |
| 4034 | ptr = stktable_data_ptr(&si->applet.ctx.table.proxy->table, |
| 4035 | si->applet.ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4036 | dt); |
| 4037 | |
| 4038 | data = 0; |
| 4039 | switch (stktable_data_types[dt].std_type) { |
| 4040 | case STD_T_SINT: |
| 4041 | data = stktable_data_cast(ptr, std_t_sint); |
| 4042 | break; |
| 4043 | case STD_T_UINT: |
| 4044 | data = stktable_data_cast(ptr, std_t_uint); |
| 4045 | break; |
| 4046 | case STD_T_ULL: |
| 4047 | data = stktable_data_cast(ptr, std_t_ull); |
| 4048 | break; |
| 4049 | case STD_T_FRQP: |
| 4050 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4051 | si->applet.ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4052 | break; |
| 4053 | } |
| 4054 | |
| 4055 | /* 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] | 4056 | if ((data < si->applet.ctx.table.value && |
| 4057 | (si->applet.ctx.table.data_op == STD_OP_EQ || |
| 4058 | si->applet.ctx.table.data_op == STD_OP_GT || |
| 4059 | si->applet.ctx.table.data_op == STD_OP_GE)) || |
| 4060 | (data == si->applet.ctx.table.value && |
| 4061 | (si->applet.ctx.table.data_op == STD_OP_NE || |
| 4062 | si->applet.ctx.table.data_op == STD_OP_GT || |
| 4063 | si->applet.ctx.table.data_op == STD_OP_LT)) || |
| 4064 | (data > si->applet.ctx.table.value && |
| 4065 | (si->applet.ctx.table.data_op == STD_OP_EQ || |
| 4066 | si->applet.ctx.table.data_op == STD_OP_LT || |
| 4067 | si->applet.ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 4068 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4069 | } |
| 4070 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4071 | if (show && !skip_entry && |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4072 | !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] | 4073 | si->applet.ctx.table.entry)) |
| 4074 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4075 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4076 | si->applet.ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4077 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4078 | eb = ebmb_next(&si->applet.ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4079 | if (eb) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4080 | struct stksess *old = si->applet.ctx.table.entry; |
| 4081 | si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 4082 | if (show) |
| 4083 | stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, old); |
| 4084 | else |
| 4085 | stksess_kill(&si->applet.ctx.table.proxy->table, old); |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4086 | si->applet.ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4087 | break; |
| 4088 | } |
| 4089 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4090 | |
| 4091 | if (show) |
| 4092 | stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry); |
| 4093 | else if (!skip_entry && !si->applet.ctx.table.entry->ref_cnt) |
| 4094 | stksess_kill(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry); |
| 4095 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4096 | si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4097 | si->conn->xprt_st = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4098 | break; |
| 4099 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4100 | case STAT_ST_END: |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4101 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4102 | break; |
| 4103 | } |
| 4104 | } |
| 4105 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4106 | } |
| 4107 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4108 | /* 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] | 4109 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 4110 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 4111 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 4112 | * lines are respected within the limit of 70 output chars. Lines that are |
| 4113 | * continuation of a previous truncated line begin with "+" instead of " " |
| 4114 | * after the offset. The new pointer is returned. |
| 4115 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4116 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 4117 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4118 | { |
| 4119 | int end; |
| 4120 | unsigned char c; |
| 4121 | |
| 4122 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4123 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4124 | return ptr; |
| 4125 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 4126 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4127 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4128 | while (ptr < len && ptr < bsize) { |
| 4129 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4130 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4131 | if (out->len > end - 2) |
| 4132 | break; |
| 4133 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4134 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4135 | if (out->len > end - 3) |
| 4136 | break; |
| 4137 | out->str[out->len++] = '\\'; |
| 4138 | switch (c) { |
| 4139 | case '\t': c = 't'; break; |
| 4140 | case '\n': c = 'n'; break; |
| 4141 | case '\r': c = 'r'; break; |
| 4142 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4143 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4144 | } |
| 4145 | out->str[out->len++] = c; |
| 4146 | } else { |
| 4147 | if (out->len > end - 5) |
| 4148 | break; |
| 4149 | out->str[out->len++] = '\\'; |
| 4150 | out->str[out->len++] = 'x'; |
| 4151 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 4152 | out->str[out->len++] = hextab[c & 0xF]; |
| 4153 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4154 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4155 | /* we had a line break, let's return now */ |
| 4156 | out->str[out->len++] = '\n'; |
| 4157 | *line = ptr; |
| 4158 | return ptr; |
| 4159 | } |
| 4160 | } |
| 4161 | /* we have an incomplete line, we return it as-is */ |
| 4162 | out->str[out->len++] = '\n'; |
| 4163 | return ptr; |
| 4164 | } |
| 4165 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4166 | /* This function dumps all captured errors onto the stream interface's |
| 4167 | * 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] | 4168 | * properly set. It returns 0 if the output buffer is full and it needs |
| 4169 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4170 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4171 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4172 | { |
| 4173 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4174 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4175 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4176 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4177 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4178 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4179 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4180 | if (!si->applet.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4181 | /* the function had not been called yet, let's prepare the |
| 4182 | * buffer for a response. |
| 4183 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4184 | struct tm tm; |
| 4185 | |
| 4186 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4187 | 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] | 4188 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4189 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 4190 | error_snapshot_id); |
| 4191 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4192 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4193 | /* Socket buffer full. Let's try again later from the same point */ |
| 4194 | return 0; |
| 4195 | } |
| 4196 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4197 | si->applet.ctx.errors.px = proxy; |
| 4198 | si->applet.ctx.errors.buf = 0; |
| 4199 | si->applet.ctx.errors.bol = 0; |
| 4200 | si->applet.ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | /* we have two inner loops here, one for the proxy, the other one for |
| 4204 | * the buffer. |
| 4205 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4206 | while (si->applet.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4207 | struct error_snapshot *es; |
| 4208 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4209 | if (si->applet.ctx.errors.buf == 0) |
| 4210 | es = &si->applet.ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4211 | else |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4212 | es = &si->applet.ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4213 | |
| 4214 | if (!es->when.tv_sec) |
| 4215 | goto next; |
| 4216 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4217 | if (si->applet.ctx.errors.iid >= 0 && |
| 4218 | si->applet.ctx.errors.px->uuid != si->applet.ctx.errors.iid && |
| 4219 | es->oe->uuid != si->applet.ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4220 | goto next; |
| 4221 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4222 | if (si->applet.ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4223 | /* just print headers now */ |
| 4224 | |
| 4225 | char pn[INET6_ADDRSTRLEN]; |
| 4226 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4227 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4228 | |
| 4229 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4230 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4231 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4232 | 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] | 4233 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4234 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 4235 | case AF_INET: |
| 4236 | case AF_INET6: |
| 4237 | port = get_host_port(&es->src); |
| 4238 | break; |
| 4239 | default: |
| 4240 | port = 0; |
| 4241 | } |
| 4242 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4243 | switch (si->applet.ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4244 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4245 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4246 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4247 | " backend %s (#%d)", |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4248 | si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4249 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 4250 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4251 | break; |
| 4252 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4253 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4254 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4255 | " frontend %s (#%d)", |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4256 | si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4257 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4258 | break; |
| 4259 | } |
| 4260 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4261 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4262 | ", server %s (#%d), event #%u\n" |
| 4263 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 4264 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 4265 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 4266 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 4267 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 4268 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 4269 | es->ev_id, |
| 4270 | pn, port, es->sid, es->s_flags, |
| 4271 | es->state, es->m_flags, es->t_flags, |
| 4272 | es->m_clen, es->m_blen, |
| 4273 | es->b_flags, es->b_out, es->b_tot, |
| 4274 | es->len, es->b_wrap, es->pos); |
| 4275 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4276 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4277 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4278 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4279 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4280 | si->applet.ctx.errors.ptr = 0; |
| 4281 | si->applet.ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4282 | } |
| 4283 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4284 | if (si->applet.ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4285 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4286 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4287 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4288 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4289 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4290 | goto next; |
| 4291 | } |
| 4292 | |
| 4293 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4294 | 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] | 4295 | int newptr; |
| 4296 | int newline; |
| 4297 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4298 | newline = si->applet.ctx.errors.bol; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4299 | 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] | 4300 | if (newptr == si->applet.ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4301 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4302 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4303 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4304 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4305 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4306 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4307 | si->applet.ctx.errors.ptr = newptr; |
| 4308 | si->applet.ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4309 | }; |
| 4310 | next: |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4311 | si->applet.ctx.errors.bol = 0; |
| 4312 | si->applet.ctx.errors.ptr = -1; |
| 4313 | si->applet.ctx.errors.buf++; |
| 4314 | if (si->applet.ctx.errors.buf > 1) { |
| 4315 | si->applet.ctx.errors.buf = 0; |
| 4316 | si->applet.ctx.errors.px = si->applet.ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4317 | } |
| 4318 | } |
| 4319 | |
| 4320 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4321 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4322 | } |
| 4323 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4324 | /* parse the "level" argument on the bind lines */ |
| 4325 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 4326 | { |
| 4327 | if (!*args[cur_arg + 1]) { |
| 4328 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 4329 | return ERR_ALERT | ERR_FATAL; |
| 4330 | } |
| 4331 | |
| 4332 | if (!strcmp(args[cur_arg+1], "user")) |
| 4333 | conf->level = ACCESS_LVL_USER; |
| 4334 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 4335 | conf->level = ACCESS_LVL_OPER; |
| 4336 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 4337 | conf->level = ACCESS_LVL_ADMIN; |
| 4338 | else { |
| 4339 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 4340 | args[cur_arg], args[cur_arg+1]); |
| 4341 | return ERR_ALERT | ERR_FATAL; |
| 4342 | } |
| 4343 | |
| 4344 | return 0; |
| 4345 | } |
| 4346 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4347 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4348 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4349 | .name = "<STATS>", /* used for logging */ |
| 4350 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 4351 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4352 | }; |
| 4353 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4354 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4355 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4356 | .name = "<CLI>", /* used for logging */ |
| 4357 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4358 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4359 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4360 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4361 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 4362 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 4363 | { 0, NULL, NULL }, |
| 4364 | }}; |
| 4365 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4366 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 4367 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 4368 | { NULL, NULL, 0 }, |
| 4369 | }}; |
| 4370 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4371 | __attribute__((constructor)) |
| 4372 | static void __dumpstats_module_init(void) |
| 4373 | { |
| 4374 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4375 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4376 | } |
| 4377 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4378 | /* |
| 4379 | * Local variables: |
| 4380 | * c-indent-level: 8 |
| 4381 | * c-basic-offset: 8 |
| 4382 | * End: |
| 4383 | */ |