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