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 | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 4 | * Copyright 2000-2010 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> |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 17 | #include <stdbool.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 21 | #include <pwd.h> |
| 22 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 23 | |
| 24 | #include <sys/socket.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <sys/types.h> |
| 27 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 28 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 29 | #include <common/compat.h> |
| 30 | #include <common/config.h> |
| 31 | #include <common/debug.h> |
| 32 | #include <common/memory.h> |
| 33 | #include <common/mini-clist.h> |
| 34 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 35 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 36 | #include <common/time.h> |
| 37 | #include <common/uri_auth.h> |
| 38 | #include <common/version.h> |
| 39 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 41 | |
| 42 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 43 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 44 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 45 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 46 | #include <proto/dumpstats.h> |
| 47 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 48 | #include <proto/freq_ctr.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 49 | #include <proto/log.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 50 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 51 | #include <proto/listener.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 52 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 53 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 54 | #include <proto/proxy.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 55 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 56 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 57 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 58 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 59 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 60 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 61 | #ifdef USE_OPENSSL |
| 62 | #include <proto/ssl_sock.h> |
| 63 | #endif |
| 64 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 65 | static int stats_dump_raw_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); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 69 | static int stats_table_request(struct stream_interface *si, bool 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 | |
| 73 | static struct si_applet cli_applet; |
| 74 | |
| 75 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 76 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 77 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 78 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 79 | " help : this message\n" |
| 80 | " prompt : toggle interactive mode with prompt\n" |
| 81 | " quit : disconnect\n" |
| 82 | " show info : report information about the running process\n" |
| 83 | " show stat : report counters for each proxy and server\n" |
| 84 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 85 | " 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] | 86 | " 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] | 87 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 88 | " set weight : change a server's weight\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 89 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 90 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 91 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 92 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 93 | " disable : put a server or frontend in maintenance mode\n" |
| 94 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 95 | " 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] | 96 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 97 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 98 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 99 | "Permission denied\n" |
| 100 | ""; |
| 101 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 102 | /* data transmission states for the stats responses */ |
| 103 | enum { |
| 104 | STAT_ST_INIT = 0, |
| 105 | STAT_ST_HEAD, |
| 106 | STAT_ST_INFO, |
| 107 | STAT_ST_LIST, |
| 108 | STAT_ST_END, |
| 109 | STAT_ST_FIN, |
| 110 | }; |
| 111 | |
| 112 | /* data transmission states for the stats responses inside a proxy */ |
| 113 | enum { |
| 114 | STAT_PX_ST_INIT = 0, |
| 115 | STAT_PX_ST_TH, |
| 116 | STAT_PX_ST_FE, |
| 117 | STAT_PX_ST_LI, |
| 118 | STAT_PX_ST_SV, |
| 119 | STAT_PX_ST_BE, |
| 120 | STAT_PX_ST_END, |
| 121 | STAT_PX_ST_FIN, |
| 122 | }; |
| 123 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 124 | extern const char *stat_status_codes[]; |
| 125 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 126 | /* 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] | 127 | * a new stats socket. It returns a positive value upon success, 0 if the connection |
| 128 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 129 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 130 | static int stats_accept(struct session *s) |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 131 | { |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 132 | /* we have a dedicated I/O handler for the stats */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 133 | stream_int_register_handler(&s->si[1], &cli_applet); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 134 | s->target = s->si[1].conn->target; // for logging only |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 135 | s->si[1].conn->xprt_ctx = s; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 136 | s->si[1].applet.st1 = 0; |
| 137 | s->si[1].applet.st0 = STAT_CLI_INIT; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 138 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 139 | tv_zero(&s->logs.tv_request); |
| 140 | s->logs.t_queue = 0; |
| 141 | s->logs.t_connect = 0; |
| 142 | s->logs.t_data = 0; |
| 143 | s->logs.t_close = 0; |
| 144 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 145 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 146 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 147 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 148 | s->req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 149 | |
Willy Tarreau | decd14d | 2010-06-01 18:03:19 +0200 | [diff] [blame] | 150 | if (s->listener->timeout) { |
| 151 | s->req->rto = *s->listener->timeout; |
| 152 | s->rep->wto = *s->listener->timeout; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 153 | } |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 154 | return 1; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 157 | /* allocate a new stats frontend named <name>, and return it |
| 158 | * (or NULL in case of lack of memory). |
| 159 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 160 | 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] | 161 | { |
| 162 | struct proxy *fe; |
| 163 | |
| 164 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 165 | if (!fe) |
| 166 | return NULL; |
| 167 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 168 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 169 | fe->next = proxy; |
| 170 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 171 | fe->last_change = now.tv_sec; |
| 172 | fe->id = strdup("GLOBAL"); |
| 173 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 174 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 175 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 176 | fe->conf.file = strdup(file); |
| 177 | fe->conf.line = line; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 178 | fe->accept = stats_accept; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 179 | |
| 180 | /* the stats frontend is the only one able to assign ID #0 */ |
| 181 | fe->conf.id.key = fe->uuid = 0; |
| 182 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 183 | return fe; |
| 184 | } |
| 185 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 186 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 187 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 188 | * error message into the <err> buffer which will be preallocated. The trailing |
| 189 | * '\n' must not be written. The function must be called with <args> pointing to |
| 190 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 191 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 192 | 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] | 193 | struct proxy *defpx, const char *file, int line, |
| 194 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 195 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 196 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 197 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 198 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 199 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 200 | int cur_arg; |
| 201 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 202 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 203 | 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] | 204 | return -1; |
| 205 | } |
| 206 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 207 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 208 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 209 | 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] | 210 | return -1; |
| 211 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 212 | } |
| 213 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 214 | 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] | 215 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 216 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 217 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 218 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 219 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 220 | return -1; |
| 221 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 222 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 223 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 224 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 225 | static int bind_dumped; |
| 226 | struct bind_kw *kw; |
| 227 | |
| 228 | kw = bind_find_kw(args[cur_arg]); |
| 229 | if (kw) { |
| 230 | if (!kw->parse) { |
| 231 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 232 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 233 | return -1; |
| 234 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 235 | |
| 236 | if (kw->parse(args, cur_arg, curpx, bind_conf, err) != 0) { |
| 237 | if (err && *err) |
| 238 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 239 | else |
| 240 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 241 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 242 | return -1; |
| 243 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 244 | |
| 245 | cur_arg += 1 + kw->skip; |
| 246 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 247 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 248 | |
| 249 | if (!bind_dumped) { |
| 250 | bind_dump_kws(err); |
| 251 | indent_msg(err, 4); |
| 252 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 253 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 254 | |
| 255 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 256 | args[0], args[1], args[cur_arg], |
| 257 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 258 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 259 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 260 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 261 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 262 | l->maxconn = global.stats_fe->maxconn; |
| 263 | l->backlog = global.stats_fe->backlog; |
| 264 | l->timeout = &global.stats_fe->timeout.client; |
| 265 | l->accept = session_accept; |
| 266 | l->handler = process_session; |
| 267 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 268 | l->nice = -64; /* we want to boost priority for local stats */ |
| 269 | global.maxsock += l->maxconn; |
| 270 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 271 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 272 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 273 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 274 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 275 | |
| 276 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 277 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 278 | return -1; |
| 279 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 280 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 281 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 282 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 283 | return -1; |
| 284 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 285 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 286 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 287 | 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] | 288 | return -1; |
| 289 | } |
| 290 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 291 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 292 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 293 | else if (!strcmp(args[1], "maxconn")) { |
| 294 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 295 | |
| 296 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 297 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 298 | return -1; |
| 299 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 300 | |
| 301 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 302 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 303 | 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] | 304 | return -1; |
| 305 | } |
| 306 | } |
| 307 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 308 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 309 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 310 | int cur_arg = 2; |
| 311 | unsigned int set = 0; |
| 312 | |
| 313 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 314 | unsigned int low, high; |
| 315 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 316 | if (strcmp(args[cur_arg], "all") == 0) { |
| 317 | set = 0; |
| 318 | break; |
| 319 | } |
| 320 | else if (strcmp(args[cur_arg], "odd") == 0) { |
| 321 | set |= 0x55555555; |
| 322 | } |
| 323 | else if (strcmp(args[cur_arg], "even") == 0) { |
| 324 | set |= 0xAAAAAAAA; |
| 325 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 326 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 327 | char *dash = strchr(args[cur_arg], '-'); |
| 328 | |
| 329 | low = high = str2uic(args[cur_arg]); |
| 330 | if (dash) |
| 331 | high = str2uic(dash + 1); |
| 332 | |
| 333 | if (high < low) { |
| 334 | unsigned int swap = low; |
| 335 | low = high; |
| 336 | high = swap; |
| 337 | } |
| 338 | |
| 339 | if (low < 1 || high > 32) { |
| 340 | memprintf(err, "'%s %s' supports process numbers from 1 to 32.\n", |
| 341 | args[0], args[1]); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 342 | return -1; |
| 343 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 344 | |
| 345 | while (low <= high) |
| 346 | set |= 1 << (low++ - 1); |
| 347 | } |
| 348 | else { |
| 349 | memprintf(err, |
| 350 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to 32.\n", |
| 351 | args[0], args[1]); |
| 352 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 353 | } |
| 354 | cur_arg++; |
| 355 | } |
| 356 | global.stats_fe->bind_proc = set; |
| 357 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 358 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 359 | 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] | 360 | return -1; |
| 361 | } |
| 362 | return 0; |
| 363 | } |
| 364 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 365 | static int print_csv_header(struct chunk *msg) |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 366 | { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 367 | return chunk_appendf(msg, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 368 | "# pxname,svname," |
| 369 | "qcur,qmax," |
| 370 | "scur,smax,slim,stot," |
| 371 | "bin,bout," |
| 372 | "dreq,dresp," |
| 373 | "ereq,econ,eresp," |
| 374 | "wretr,wredis," |
| 375 | "status,weight,act,bck," |
| 376 | "chkfail,chkdown,lastchg,downtime,qlimit," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 377 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 378 | "rate,rate_lim,rate_max," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 379 | "check_status,check_code,check_duration," |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 380 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 381 | "req_rate,req_rate_max,req_tot," |
| 382 | "cli_abrt,srv_abrt," |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 383 | "comp_in,comp_out,comp_byp,comp_rsp," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 384 | "\n"); |
| 385 | } |
| 386 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 387 | /* print a string of text buffer to <out>. The format is : |
| 388 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 389 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 390 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 391 | */ |
| 392 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 393 | { |
| 394 | unsigned char c; |
| 395 | int ptr = 0; |
| 396 | |
| 397 | while (buf[ptr] && ptr < bsize) { |
| 398 | c = buf[ptr]; |
| 399 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 400 | if (out->len > out->size - 1) |
| 401 | break; |
| 402 | out->str[out->len++] = c; |
| 403 | } |
| 404 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 405 | if (out->len > out->size - 2) |
| 406 | break; |
| 407 | out->str[out->len++] = '\\'; |
| 408 | switch (c) { |
| 409 | case ' ': c = ' '; break; |
| 410 | case '\t': c = 't'; break; |
| 411 | case '\n': c = 'n'; break; |
| 412 | case '\r': c = 'r'; break; |
| 413 | case '\e': c = 'e'; break; |
| 414 | case '\\': c = '\\'; break; |
| 415 | } |
| 416 | out->str[out->len++] = c; |
| 417 | } |
| 418 | else { |
| 419 | if (out->len > out->size - 4) |
| 420 | break; |
| 421 | out->str[out->len++] = '\\'; |
| 422 | out->str[out->len++] = 'x'; |
| 423 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 424 | out->str[out->len++] = hextab[c & 0xF]; |
| 425 | } |
| 426 | ptr++; |
| 427 | } |
| 428 | |
| 429 | return ptr; |
| 430 | } |
| 431 | |
| 432 | /* print a buffer in hexa. |
| 433 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 434 | */ |
| 435 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 436 | { |
| 437 | unsigned char c; |
| 438 | int ptr = 0; |
| 439 | |
| 440 | while (ptr < bsize) { |
| 441 | c = buf[ptr]; |
| 442 | |
| 443 | if (out->len > out->size - 2) |
| 444 | break; |
| 445 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 446 | out->str[out->len++] = hextab[c & 0xF]; |
| 447 | |
| 448 | ptr++; |
| 449 | } |
| 450 | return ptr; |
| 451 | } |
| 452 | |
| 453 | /* Dump the status of a table to a stream interface's |
| 454 | * read buffer. It returns 0 if the output buffer is full |
| 455 | * and needs to be called again, otherwise non-zero. |
| 456 | */ |
| 457 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 458 | struct proxy *proxy, struct proxy *target) |
| 459 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 460 | struct session *s = si->conn->xprt_ctx; |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 461 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 462 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 463 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 464 | |
| 465 | /* any other information should be dumped here */ |
| 466 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 467 | if (target && s->listener->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 468 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 469 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 470 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 471 | return 0; |
| 472 | |
| 473 | return 1; |
| 474 | } |
| 475 | |
| 476 | /* Dump the a table entry to a stream interface's |
| 477 | * read buffer. It returns 0 if the output buffer is full |
| 478 | * and needs to be called again, otherwise non-zero. |
| 479 | */ |
| 480 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 481 | struct proxy *proxy, struct stksess *entry) |
| 482 | { |
| 483 | int dt; |
| 484 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 485 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 486 | |
| 487 | if (proxy->table.type == STKTABLE_TYPE_IP) { |
| 488 | char addr[INET_ADDRSTRLEN]; |
| 489 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 490 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 491 | } |
| 492 | else if (proxy->table.type == STKTABLE_TYPE_IPV6) { |
| 493 | char addr[INET6_ADDRSTRLEN]; |
| 494 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 495 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 496 | } |
| 497 | else if (proxy->table.type == STKTABLE_TYPE_INTEGER) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 498 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 499 | } |
| 500 | else if (proxy->table.type == STKTABLE_TYPE_STRING) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 501 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 502 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 503 | } |
| 504 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 505 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 506 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 507 | } |
| 508 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 509 | 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] | 510 | |
| 511 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 512 | void *ptr; |
| 513 | |
| 514 | if (proxy->table.data_ofs[dt] == 0) |
| 515 | continue; |
| 516 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 517 | 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] | 518 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 519 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 520 | |
| 521 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 522 | switch (stktable_data_types[dt].std_type) { |
| 523 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 524 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 525 | break; |
| 526 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 527 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 528 | break; |
| 529 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 530 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 531 | break; |
| 532 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 533 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 534 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 535 | proxy->table.data_arg[dt].u)); |
| 536 | break; |
| 537 | } |
| 538 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 539 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 540 | |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 541 | if (bi_putchk(si->ib, msg) == -1) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 542 | return 0; |
| 543 | |
| 544 | return 1; |
| 545 | } |
| 546 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 547 | 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] | 548 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 549 | struct session *s = si->conn->xprt_ctx; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 550 | struct proxy *px = si->applet.ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 551 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 552 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 553 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 554 | long long value; |
| 555 | int data_type; |
| 556 | void *ptr; |
| 557 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 558 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 559 | si->applet.st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 560 | |
| 561 | if (!*args[4]) { |
| 562 | si->applet.ctx.cli.msg = "Key value expected\n"; |
| 563 | si->applet.st0 = STAT_CLI_PRINT; |
| 564 | return; |
| 565 | } |
| 566 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 567 | switch (px->table.type) { |
| 568 | case STKTABLE_TYPE_IP: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 569 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 570 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 571 | break; |
| 572 | case STKTABLE_TYPE_IPV6: |
| 573 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 574 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 575 | break; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 576 | case STKTABLE_TYPE_INTEGER: |
| 577 | { |
| 578 | char *endptr; |
| 579 | unsigned long val; |
| 580 | errno = 0; |
| 581 | val = strtoul(args[4], &endptr, 10); |
| 582 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 583 | (errno != 0 && val == 0) || endptr == args[4] || |
| 584 | val > 0xffffffff) { |
| 585 | si->applet.ctx.cli.msg = "Invalid key\n"; |
| 586 | si->applet.st0 = STAT_CLI_PRINT; |
| 587 | return; |
| 588 | } |
| 589 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 590 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 591 | break; |
| 592 | } |
| 593 | break; |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 594 | case STKTABLE_TYPE_STRING: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 595 | static_table_key->key = args[4]; |
| 596 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 597 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 598 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 599 | switch (action) { |
| 600 | case STAT_CLI_O_TAB: |
| 601 | si->applet.ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n"; |
| 602 | break; |
| 603 | case STAT_CLI_O_CLR: |
| 604 | si->applet.ctx.cli.msg = "Removing keys from ip tables of type other than ip, ipv6, string and integer is not supported\n"; |
| 605 | break; |
| 606 | default: |
| 607 | si->applet.ctx.cli.msg = "Unknown action\n"; |
| 608 | break; |
| 609 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 610 | si->applet.st0 = STAT_CLI_PRINT; |
| 611 | return; |
| 612 | } |
| 613 | |
| 614 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 615 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 616 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 617 | si->applet.st0 = STAT_CLI_PRINT; |
| 618 | return; |
| 619 | } |
| 620 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 621 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 622 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 623 | switch (action) { |
| 624 | case STAT_CLI_O_TAB: |
| 625 | if (!ts) |
| 626 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 627 | chunk_reset(&trash); |
| 628 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 629 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 630 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 631 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 632 | |
| 633 | case STAT_CLI_O_CLR: |
| 634 | if (!ts) |
| 635 | return; |
| 636 | if (ts->ref_cnt) { |
| 637 | /* don't delete an entry which is currently referenced */ |
| 638 | si->applet.ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 639 | si->applet.st0 = STAT_CLI_PRINT; |
| 640 | return; |
| 641 | } |
| 642 | stksess_kill(&px->table, ts); |
| 643 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 644 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 645 | case STAT_CLI_O_SET: |
| 646 | if (strncmp(args[5], "data.", 5) != 0) { |
| 647 | si->applet.ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 648 | si->applet.st0 = STAT_CLI_PRINT; |
| 649 | return; |
| 650 | } |
| 651 | |
| 652 | data_type = stktable_get_data_type(args[5] + 5); |
| 653 | if (data_type < 0) { |
| 654 | si->applet.ctx.cli.msg = "Unknown data type\n"; |
| 655 | si->applet.st0 = STAT_CLI_PRINT; |
| 656 | return; |
| 657 | } |
| 658 | |
| 659 | if (!px->table.data_ofs[data_type]) { |
| 660 | si->applet.ctx.cli.msg = "Data type not stored in this table\n"; |
| 661 | si->applet.st0 = STAT_CLI_PRINT; |
| 662 | return; |
| 663 | } |
| 664 | |
| 665 | if (!*args[6] || strl2llrc(args[6], strlen(args[6]), &value) != 0) { |
| 666 | si->applet.ctx.cli.msg = "Require a valid integer value to store\n"; |
| 667 | si->applet.st0 = STAT_CLI_PRINT; |
| 668 | return; |
| 669 | } |
| 670 | |
| 671 | if (ts) |
| 672 | stktable_touch(&px->table, ts, 1); |
| 673 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 674 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 675 | if (!ts) { |
| 676 | /* don't delete an entry which is currently referenced */ |
| 677 | si->applet.ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 678 | si->applet.st0 = STAT_CLI_PRINT; |
| 679 | return; |
| 680 | } |
| 681 | stktable_store(&px->table, ts, 1); |
| 682 | } |
| 683 | |
| 684 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 685 | switch (stktable_data_types[data_type].std_type) { |
| 686 | case STD_T_SINT: |
| 687 | stktable_data_cast(ptr, std_t_sint) = value; |
| 688 | break; |
| 689 | case STD_T_UINT: |
| 690 | stktable_data_cast(ptr, std_t_uint) = value; |
| 691 | break; |
| 692 | case STD_T_ULL: |
| 693 | stktable_data_cast(ptr, std_t_ull) = value; |
| 694 | break; |
| 695 | case STD_T_FRQP: |
| 696 | /* We only reset the previous value so that it slowly fades out */ |
| 697 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 698 | frqp->curr_tick = now_ms; |
| 699 | frqp->prev_ctr = value; |
| 700 | frqp->curr_ctr = 0; |
| 701 | break; |
| 702 | } |
| 703 | break; |
| 704 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 705 | default: |
| 706 | si->applet.ctx.cli.msg = "Unknown action\n"; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 707 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 708 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 709 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 710 | } |
| 711 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 712 | 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] | 713 | { |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 714 | if (action != STAT_CLI_O_TAB) { |
| 715 | si->applet.ctx.cli.msg = "content-based lookup is only supported with the \"show\" action"; |
| 716 | si->applet.st0 = STAT_CLI_PRINT; |
| 717 | return; |
| 718 | } |
| 719 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 720 | /* condition on stored data value */ |
| 721 | si->applet.ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 722 | if (si->applet.ctx.table.data_type < 0) { |
| 723 | si->applet.ctx.cli.msg = "Unknown data type\n"; |
| 724 | si->applet.st0 = STAT_CLI_PRINT; |
| 725 | return; |
| 726 | } |
| 727 | |
| 728 | if (!((struct proxy *)si->applet.ctx.table.target)->table.data_ofs[si->applet.ctx.table.data_type]) { |
| 729 | si->applet.ctx.cli.msg = "Data type not stored in this table\n"; |
| 730 | si->applet.st0 = STAT_CLI_PRINT; |
| 731 | return; |
| 732 | } |
| 733 | |
| 734 | si->applet.ctx.table.data_op = get_std_op(args[4]); |
| 735 | if (si->applet.ctx.table.data_op < 0) { |
| 736 | si->applet.ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 737 | si->applet.st0 = STAT_CLI_PRINT; |
| 738 | return; |
| 739 | } |
| 740 | |
| 741 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &si->applet.ctx.table.value) != 0) { |
| 742 | si->applet.ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 743 | si->applet.st0 = STAT_CLI_PRINT; |
| 744 | return; |
| 745 | } |
| 746 | } |
| 747 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 748 | 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] | 749 | { |
| 750 | si->applet.ctx.table.data_type = -1; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 751 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | e17a8d0 | 2011-08-24 08:23:34 +0200 | [diff] [blame] | 752 | si->applet.ctx.table.target = NULL; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 753 | si->applet.ctx.table.proxy = NULL; |
| 754 | si->applet.ctx.table.entry = NULL; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 755 | si->applet.st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 756 | |
| 757 | if (*args[2]) { |
| 758 | si->applet.ctx.table.target = find_stktable(args[2]); |
| 759 | if (!si->applet.ctx.table.target) { |
| 760 | si->applet.ctx.cli.msg = "No such table\n"; |
| 761 | si->applet.st0 = STAT_CLI_PRINT; |
| 762 | return; |
| 763 | } |
| 764 | } |
| 765 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 766 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 767 | goto err_args; |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 772 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 773 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 774 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 775 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 776 | goto err_args; |
| 777 | |
| 778 | return; |
| 779 | |
| 780 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 781 | switch (action) { |
| 782 | case STAT_CLI_O_TAB: |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 783 | 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] | 784 | break; |
| 785 | case STAT_CLI_O_CLR: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 786 | 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] | 787 | break; |
| 788 | default: |
| 789 | si->applet.ctx.cli.msg = "Unknown action\n"; |
| 790 | break; |
| 791 | } |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 792 | si->applet.st0 = STAT_CLI_PRINT; |
| 793 | } |
| 794 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 795 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
| 796 | * adequate error messages and returns NULL. This function also expects the session |
| 797 | * level to be admin. |
| 798 | */ |
| 799 | static struct proxy *expect_frontend_admin(struct session *s, struct stream_interface *si, const char *arg) |
| 800 | { |
| 801 | struct proxy *px; |
| 802 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 803 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 804 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 805 | si->applet.st0 = STAT_CLI_PRINT; |
| 806 | return NULL; |
| 807 | } |
| 808 | |
| 809 | if (!*arg) { |
| 810 | si->applet.ctx.cli.msg = "A frontend name is expected.\n"; |
| 811 | si->applet.st0 = STAT_CLI_PRINT; |
| 812 | return NULL; |
| 813 | } |
| 814 | |
| 815 | px = findproxy(arg, PR_CAP_FE); |
| 816 | if (!px) { |
| 817 | si->applet.ctx.cli.msg = "No such frontend.\n"; |
| 818 | si->applet.st0 = STAT_CLI_PRINT; |
| 819 | return NULL; |
| 820 | } |
| 821 | return px; |
| 822 | } |
| 823 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 824 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 825 | * and returns the pointer to the server. Otherwise, display adequate error messages |
| 826 | * and returns NULL. This function also expects the session level to be admin. Note: |
| 827 | * the <arg> is modified to remove the '/'. |
| 828 | */ |
| 829 | static struct server *expect_server_admin(struct session *s, struct stream_interface *si, char *arg) |
| 830 | { |
| 831 | struct proxy *px; |
| 832 | struct server *sv; |
| 833 | char *line; |
| 834 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 835 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 836 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 837 | si->applet.st0 = STAT_CLI_PRINT; |
| 838 | return NULL; |
| 839 | } |
| 840 | |
| 841 | /* split "backend/server" and make <line> point to server */ |
| 842 | for (line = arg; *line; line++) |
| 843 | if (*line == '/') { |
| 844 | *line++ = '\0'; |
| 845 | break; |
| 846 | } |
| 847 | |
| 848 | if (!*line || !*arg) { |
| 849 | si->applet.ctx.cli.msg = "Require 'backend/server'.\n"; |
| 850 | si->applet.st0 = STAT_CLI_PRINT; |
| 851 | return NULL; |
| 852 | } |
| 853 | |
| 854 | if (!get_backend_server(arg, line, &px, &sv)) { |
| 855 | si->applet.ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 856 | si->applet.st0 = STAT_CLI_PRINT; |
| 857 | return NULL; |
| 858 | } |
| 859 | |
| 860 | if (px->state == PR_STSTOPPED) { |
| 861 | si->applet.ctx.cli.msg = "Proxy is disabled.\n"; |
| 862 | si->applet.st0 = STAT_CLI_PRINT; |
| 863 | return NULL; |
| 864 | } |
| 865 | |
| 866 | return sv; |
| 867 | } |
| 868 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 869 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 870 | * 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] | 871 | * 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] | 872 | * designating the function which will have to process the request, which can |
| 873 | * 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] | 874 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 875 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 876 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 877 | struct session *s = si->conn->xprt_ctx; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 878 | char *args[MAX_STATS_ARGS + 1]; |
| 879 | int arg; |
| 880 | |
| 881 | while (isspace((unsigned char)*line)) |
| 882 | line++; |
| 883 | |
| 884 | arg = 0; |
| 885 | args[arg] = line; |
| 886 | |
| 887 | while (*line && arg < MAX_STATS_ARGS) { |
| 888 | if (isspace((unsigned char)*line)) { |
| 889 | *line++ = '\0'; |
| 890 | |
| 891 | while (isspace((unsigned char)*line)) |
| 892 | line++; |
| 893 | |
| 894 | args[++arg] = line; |
| 895 | continue; |
| 896 | } |
| 897 | |
| 898 | line++; |
| 899 | } |
| 900 | |
| 901 | while (++arg <= MAX_STATS_ARGS) |
| 902 | args[arg] = line; |
| 903 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 904 | si->applet.ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 905 | if (strcmp(args[0], "show") == 0) { |
| 906 | if (strcmp(args[1], "stat") == 0) { |
| 907 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 908 | si->applet.ctx.stats.flags |= STAT_BOUND; |
| 909 | si->applet.ctx.stats.iid = atoi(args[2]); |
| 910 | si->applet.ctx.stats.type = atoi(args[3]); |
| 911 | si->applet.ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 912 | } |
| 913 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 914 | si->applet.ctx.stats.flags |= STAT_SHOW_STAT; |
| 915 | si->applet.ctx.stats.flags |= STAT_FMT_CSV; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 916 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 917 | si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 918 | } |
| 919 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 920 | si->applet.ctx.stats.flags |= STAT_SHOW_INFO; |
| 921 | si->applet.ctx.stats.flags |= STAT_FMT_CSV; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 922 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 923 | si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 924 | } |
| 925 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 926 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 927 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 928 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 929 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 930 | return 1; |
| 931 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 932 | if (*args[2] && strcmp(args[2], "all") == 0) |
| 933 | si->applet.ctx.sess.target = (void *)-1; |
| 934 | else if (*args[2]) |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 935 | si->applet.ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 936 | else |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 937 | si->applet.ctx.sess.target = NULL; |
| 938 | si->applet.ctx.sess.section = 0; /* start with session status */ |
| 939 | si->applet.ctx.sess.pos = 0; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 940 | si->applet.st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 941 | } |
| 942 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 943 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 944 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 945 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 946 | return 1; |
| 947 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 948 | if (*args[2]) |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 949 | si->applet.ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 950 | else |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 951 | si->applet.ctx.errors.iid = -1; |
| 952 | si->applet.ctx.errors.px = NULL; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 953 | si->conn->xprt_st = STAT_ST_INIT; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 954 | si->applet.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 955 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 956 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 957 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 958 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 959 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 960 | return 0; |
| 961 | } |
| 962 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 963 | else if (strcmp(args[0], "clear") == 0) { |
| 964 | if (strcmp(args[1], "counters") == 0) { |
| 965 | struct proxy *px; |
| 966 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 967 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 968 | int clrall = 0; |
| 969 | |
| 970 | if (strcmp(args[2], "all") == 0) |
| 971 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 972 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 973 | /* check permissions */ |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 974 | if (s->listener->bind_conf->level < ACCESS_LVL_OPER || |
| 975 | (clrall && s->listener->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 976 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 977 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 978 | return 1; |
| 979 | } |
| 980 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 981 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 982 | if (clrall) { |
| 983 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 984 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 985 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 986 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 987 | px->be_counters.conn_max = 0; |
| 988 | px->be_counters.p.http.rps_max = 0; |
| 989 | px->be_counters.sps_max = 0; |
| 990 | px->be_counters.cps_max = 0; |
| 991 | px->be_counters.nbpend_max = 0; |
| 992 | |
| 993 | px->fe_counters.conn_max = 0; |
| 994 | px->fe_counters.p.http.rps_max = 0; |
| 995 | px->fe_counters.sps_max = 0; |
| 996 | px->fe_counters.cps_max = 0; |
| 997 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 998 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 999 | |
| 1000 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1001 | if (clrall) |
| 1002 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1003 | else { |
| 1004 | sv->counters.cur_sess_max = 0; |
| 1005 | sv->counters.nbpend_max = 0; |
| 1006 | sv->counters.sps_max = 0; |
| 1007 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1008 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1009 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1010 | if (li->counters) { |
| 1011 | if (clrall) |
| 1012 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1013 | else |
| 1014 | li->counters->conn_max = 0; |
| 1015 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1016 | } |
| 1017 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1018 | global.cps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1019 | return 1; |
| 1020 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1021 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1022 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1023 | /* end of processing */ |
| 1024 | return 1; |
| 1025 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1026 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1027 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1028 | return 0; |
| 1029 | } |
| 1030 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1031 | else if (strcmp(args[0], "get") == 0) { |
| 1032 | if (strcmp(args[1], "weight") == 0) { |
| 1033 | struct proxy *px; |
| 1034 | struct server *sv; |
| 1035 | |
| 1036 | /* split "backend/server" and make <line> point to server */ |
| 1037 | for (line = args[2]; *line; line++) |
| 1038 | if (*line == '/') { |
| 1039 | *line++ = '\0'; |
| 1040 | break; |
| 1041 | } |
| 1042 | |
| 1043 | if (!*line) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1044 | si->applet.ctx.cli.msg = "Require 'backend/server'.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1045 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1046 | return 1; |
| 1047 | } |
| 1048 | |
| 1049 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1050 | 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] | 1051 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1052 | return 1; |
| 1053 | } |
| 1054 | |
| 1055 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1056 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 1057 | bi_putstr(si->ib, trash.str); |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1058 | return 1; |
| 1059 | } |
| 1060 | else { /* not "get weight" */ |
| 1061 | return 0; |
| 1062 | } |
| 1063 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1064 | else if (strcmp(args[0], "set") == 0) { |
| 1065 | if (strcmp(args[1], "weight") == 0) { |
| 1066 | struct proxy *px; |
| 1067 | struct server *sv; |
| 1068 | int w; |
| 1069 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1070 | sv = expect_server_admin(s, si, args[2]); |
| 1071 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1072 | return 1; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1073 | px = sv->proxy; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1074 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1075 | /* if the weight is terminated with '%', it is set relative to |
| 1076 | * the initial weight, otherwise it is absolute. |
| 1077 | */ |
| 1078 | if (!*args[3]) { |
| 1079 | si->applet.ctx.cli.msg = "Require <weight> or <weight%>.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1080 | si->applet.st0 = STAT_CLI_PRINT; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1081 | return 1; |
| 1082 | } |
| 1083 | |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1084 | w = atoi(args[3]); |
| 1085 | if (strchr(args[3], '%') != NULL) { |
| 1086 | if (w < 0 || w > 100) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1087 | 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] | 1088 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1089 | return 1; |
| 1090 | } |
| 1091 | w = sv->iweight * w / 100; |
| 1092 | } |
| 1093 | else { |
| 1094 | if (w < 0 || w > 256) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1095 | 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] | 1096 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1097 | return 1; |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN)) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1102 | 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] | 1103 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1104 | return 1; |
| 1105 | } |
| 1106 | |
| 1107 | sv->uweight = w; |
| 1108 | |
| 1109 | if (px->lbprm.algo & BE_LB_PROP_DYN) { |
| 1110 | /* we must take care of not pushing the server to full throttle during slow starts */ |
| 1111 | if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN)) |
| 1112 | sv->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - sv->last_change) + sv->slowstart - 1) / sv->slowstart; |
| 1113 | else |
| 1114 | sv->eweight = BE_WEIGHT_SCALE; |
| 1115 | sv->eweight *= sv->uweight; |
| 1116 | } else { |
| 1117 | sv->eweight = sv->uweight; |
| 1118 | } |
| 1119 | |
| 1120 | /* static LB algorithms are a bit harder to update */ |
| 1121 | if (px->lbprm.update_server_eweight) |
| 1122 | px->lbprm.update_server_eweight(sv); |
Willy Tarreau | 9580d16 | 2012-05-19 19:07:40 +0200 | [diff] [blame] | 1123 | else if (sv->eweight) { |
| 1124 | if (px->lbprm.set_server_status_up) |
| 1125 | px->lbprm.set_server_status_up(sv); |
| 1126 | } |
| 1127 | else { |
| 1128 | if (px->lbprm.set_server_status_down) |
| 1129 | px->lbprm.set_server_status_down(sv); |
| 1130 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1131 | |
| 1132 | return 1; |
| 1133 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1134 | else if (strcmp(args[1], "timeout") == 0) { |
| 1135 | if (strcmp(args[2], "cli") == 0) { |
| 1136 | unsigned timeout; |
| 1137 | const char *res; |
| 1138 | |
| 1139 | if (!*args[3]) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1140 | si->applet.ctx.cli.msg = "Expects an integer value.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1141 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1142 | return 1; |
| 1143 | } |
| 1144 | |
| 1145 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1146 | if (res || timeout < 1) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1147 | si->applet.ctx.cli.msg = "Invalid timeout value.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1148 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1149 | return 1; |
| 1150 | } |
| 1151 | |
| 1152 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 1153 | return 1; |
| 1154 | } |
| 1155 | else { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1156 | si->applet.ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1157 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1158 | return 1; |
| 1159 | } |
| 1160 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1161 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1162 | if (strcmp(args[2], "frontend") == 0) { |
| 1163 | struct proxy *px; |
| 1164 | struct listener *l; |
| 1165 | int v; |
| 1166 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1167 | px = expect_frontend_admin(s, si, args[3]); |
| 1168 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1169 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1170 | |
| 1171 | if (!*args[4]) { |
| 1172 | si->applet.ctx.cli.msg = "Integer value expected.\n"; |
| 1173 | si->applet.st0 = STAT_CLI_PRINT; |
| 1174 | return 1; |
| 1175 | } |
| 1176 | |
| 1177 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1178 | if (v < 0) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1179 | si->applet.ctx.cli.msg = "Value out of range.\n"; |
| 1180 | si->applet.st0 = STAT_CLI_PRINT; |
| 1181 | return 1; |
| 1182 | } |
| 1183 | |
| 1184 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1185 | * its listeners. The blocked ones will be dequeued. |
| 1186 | */ |
| 1187 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1188 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1189 | l->maxconn = v; |
| 1190 | if (l->state == LI_FULL) |
| 1191 | resume_listener(l); |
| 1192 | } |
| 1193 | |
| 1194 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue)) |
| 1195 | dequeue_all_listeners(&s->fe->listener_queue); |
| 1196 | |
| 1197 | return 1; |
| 1198 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1199 | else if (strcmp(args[2], "global") == 0) { |
| 1200 | int v; |
| 1201 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1202 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1203 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 1204 | si->applet.st0 = STAT_CLI_PRINT; |
| 1205 | return 1; |
| 1206 | } |
| 1207 | |
| 1208 | if (!*args[3]) { |
| 1209 | si->applet.ctx.cli.msg = "Expects an integer value.\n"; |
| 1210 | si->applet.st0 = STAT_CLI_PRINT; |
| 1211 | return 1; |
| 1212 | } |
| 1213 | |
| 1214 | v = atoi(args[3]); |
| 1215 | if (v > global.hardmaxconn) { |
| 1216 | si->applet.ctx.cli.msg = "Value out of range.\n"; |
| 1217 | si->applet.st0 = STAT_CLI_PRINT; |
| 1218 | return 1; |
| 1219 | } |
| 1220 | |
| 1221 | /* check for unlimited values */ |
| 1222 | if (v <= 0) |
| 1223 | v = global.hardmaxconn; |
| 1224 | |
| 1225 | global.maxconn = v; |
| 1226 | |
| 1227 | /* Dequeues all of the listeners waiting for a resource */ |
| 1228 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1229 | dequeue_all_listeners(&global_listener_queue); |
| 1230 | |
| 1231 | return 1; |
| 1232 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1233 | else { |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1234 | 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] | 1235 | si->applet.st0 = STAT_CLI_PRINT; |
| 1236 | return 1; |
| 1237 | } |
| 1238 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1239 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1240 | if (strcmp(args[2], "connections") == 0) { |
| 1241 | if (strcmp(args[3], "global") == 0) { |
| 1242 | int v; |
| 1243 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1244 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1245 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 1246 | si->applet.st0 = STAT_CLI_PRINT; |
| 1247 | return 1; |
| 1248 | } |
| 1249 | |
| 1250 | if (!*args[4]) { |
| 1251 | si->applet.ctx.cli.msg = "Expects an integer value.\n"; |
| 1252 | si->applet.st0 = STAT_CLI_PRINT; |
| 1253 | return 1; |
| 1254 | } |
| 1255 | |
| 1256 | v = atoi(args[4]); |
| 1257 | if (v < 0) { |
| 1258 | si->applet.ctx.cli.msg = "Value out of range.\n"; |
| 1259 | si->applet.st0 = STAT_CLI_PRINT; |
| 1260 | return 1; |
| 1261 | } |
| 1262 | |
| 1263 | global.cps_lim = v; |
| 1264 | |
| 1265 | /* Dequeues all of the listeners waiting for a resource */ |
| 1266 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1267 | dequeue_all_listeners(&global_listener_queue); |
| 1268 | |
| 1269 | return 1; |
| 1270 | } |
| 1271 | else { |
| 1272 | si->applet.ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1273 | si->applet.st0 = STAT_CLI_PRINT; |
| 1274 | return 1; |
| 1275 | } |
| 1276 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1277 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1278 | if (strcmp(args[3], "global") == 0) { |
| 1279 | int v; |
| 1280 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 1281 | if (!*args[4]) { |
| 1282 | si->applet.ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 1283 | si->applet.st0 = STAT_CLI_PRINT; |
| 1284 | return 1; |
| 1285 | } |
| 1286 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1287 | v = atoi(args[4]); |
| 1288 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 1289 | } |
| 1290 | else { |
| 1291 | si->applet.ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 1292 | si->applet.st0 = STAT_CLI_PRINT; |
| 1293 | return 1; |
| 1294 | } |
| 1295 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1296 | else { |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1297 | 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] | 1298 | si->applet.st0 = STAT_CLI_PRINT; |
| 1299 | return 1; |
| 1300 | } |
| 1301 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1302 | else if (strcmp(args[1], "table") == 0) { |
| 1303 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 1304 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1305 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1306 | return 0; |
| 1307 | } |
| 1308 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1309 | else if (strcmp(args[0], "enable") == 0) { |
| 1310 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1311 | struct server *sv; |
| 1312 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1313 | sv = expect_server_admin(s, si, args[2]); |
| 1314 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1315 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1316 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1317 | if (sv->state & SRV_MAINTAIN) { |
| 1318 | /* The server is really in maintenance, we can change the server state */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1319 | if (sv->track) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1320 | /* If this server tracks the status of another one, |
| 1321 | * we must restore the good status. |
| 1322 | */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 1323 | if (sv->track->state & SRV_RUNNING) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1324 | set_server_up(sv); |
Willy Tarreau | 7046130 | 2010-10-22 14:39:02 +0200 | [diff] [blame] | 1325 | sv->health = sv->rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1326 | } else { |
| 1327 | sv->state &= ~SRV_MAINTAIN; |
| 1328 | set_server_down(sv); |
| 1329 | } |
| 1330 | } else { |
| 1331 | set_server_up(sv); |
Willy Tarreau | 7046130 | 2010-10-22 14:39:02 +0200 | [diff] [blame] | 1332 | sv->health = sv->rise; /* up, but will fall down at first failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1336 | return 1; |
| 1337 | } |
| 1338 | else if (strcmp(args[1], "frontend") == 0) { |
| 1339 | struct proxy *px; |
| 1340 | |
| 1341 | px = expect_frontend_admin(s, si, args[2]); |
| 1342 | if (!px) |
| 1343 | return 1; |
| 1344 | |
| 1345 | if (px->state == PR_STSTOPPED) { |
| 1346 | si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 1347 | si->applet.st0 = STAT_CLI_PRINT; |
| 1348 | return 1; |
| 1349 | } |
| 1350 | |
| 1351 | if (px->state != PR_STPAUSED) { |
| 1352 | si->applet.ctx.cli.msg = "Frontend is already enabled.\n"; |
| 1353 | si->applet.st0 = STAT_CLI_PRINT; |
| 1354 | return 1; |
| 1355 | } |
| 1356 | |
| 1357 | if (!resume_proxy(px)) { |
| 1358 | si->applet.ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 1359 | si->applet.st0 = STAT_CLI_PRINT; |
| 1360 | return 1; |
| 1361 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1362 | return 1; |
| 1363 | } |
| 1364 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1365 | si->applet.ctx.cli.msg = "'enable' only supports 'frontend' and 'server'.\n"; |
| 1366 | si->applet.st0 = STAT_CLI_PRINT; |
| 1367 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1368 | } |
| 1369 | } |
| 1370 | else if (strcmp(args[0], "disable") == 0) { |
| 1371 | if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1372 | struct server *sv; |
| 1373 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1374 | sv = expect_server_admin(s, si, args[2]); |
| 1375 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1376 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 1377 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1378 | if (! (sv->state & SRV_MAINTAIN)) { |
| 1379 | /* Not already in maintenance, we can change the server state */ |
| 1380 | sv->state |= SRV_MAINTAIN; |
| 1381 | set_server_down(sv); |
| 1382 | } |
| 1383 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1384 | return 1; |
| 1385 | } |
| 1386 | else if (strcmp(args[1], "frontend") == 0) { |
| 1387 | struct proxy *px; |
| 1388 | |
| 1389 | px = expect_frontend_admin(s, si, args[2]); |
| 1390 | if (!px) |
| 1391 | return 1; |
| 1392 | |
| 1393 | if (px->state == PR_STSTOPPED) { |
| 1394 | si->applet.ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 1395 | si->applet.st0 = STAT_CLI_PRINT; |
| 1396 | return 1; |
| 1397 | } |
| 1398 | |
| 1399 | if (px->state == PR_STPAUSED) { |
| 1400 | si->applet.ctx.cli.msg = "Frontend is already disabled.\n"; |
| 1401 | si->applet.st0 = STAT_CLI_PRINT; |
| 1402 | return 1; |
| 1403 | } |
| 1404 | |
| 1405 | if (!pause_proxy(px)) { |
| 1406 | si->applet.ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 1407 | si->applet.st0 = STAT_CLI_PRINT; |
| 1408 | return 1; |
| 1409 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1410 | return 1; |
| 1411 | } |
| 1412 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1413 | si->applet.ctx.cli.msg = "'disable' only supports 'frontend' and 'server'.\n"; |
| 1414 | si->applet.st0 = STAT_CLI_PRINT; |
| 1415 | return 1; |
| 1416 | } |
| 1417 | } |
| 1418 | else if (strcmp(args[0], "shutdown") == 0) { |
| 1419 | if (strcmp(args[1], "frontend") == 0) { |
| 1420 | struct proxy *px; |
| 1421 | |
| 1422 | px = expect_frontend_admin(s, si, args[2]); |
| 1423 | if (!px) |
| 1424 | return 1; |
| 1425 | |
| 1426 | if (px->state == PR_STSTOPPED) { |
| 1427 | si->applet.ctx.cli.msg = "Frontend was already shut down.\n"; |
| 1428 | si->applet.st0 = STAT_CLI_PRINT; |
| 1429 | return 1; |
| 1430 | } |
| 1431 | |
| 1432 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1433 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1434 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 1435 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 1436 | stop_proxy(px); |
| 1437 | return 1; |
| 1438 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1439 | else if (strcmp(args[1], "session") == 0) { |
| 1440 | struct session *sess, *ptr; |
| 1441 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 1442 | if (s->listener->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 1443 | si->applet.ctx.cli.msg = stats_permission_denied_msg; |
| 1444 | si->applet.st0 = STAT_CLI_PRINT; |
| 1445 | return 1; |
| 1446 | } |
| 1447 | |
| 1448 | if (!*args[2]) { |
| 1449 | si->applet.ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 1450 | si->applet.st0 = STAT_CLI_PRINT; |
| 1451 | return 1; |
| 1452 | } |
| 1453 | |
| 1454 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 1455 | |
| 1456 | /* first, look for the requested session in the session table */ |
| 1457 | list_for_each_entry(sess, &sessions, list) { |
| 1458 | if (sess == ptr) |
| 1459 | break; |
| 1460 | } |
| 1461 | |
| 1462 | /* do we have the session ? */ |
| 1463 | if (sess != ptr) { |
| 1464 | si->applet.ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 1465 | si->applet.st0 = STAT_CLI_PRINT; |
| 1466 | return 1; |
| 1467 | } |
| 1468 | |
| 1469 | session_shutdown(sess, SN_ERR_KILLED); |
| 1470 | return 1; |
| 1471 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1472 | else if (strcmp(args[1], "sessions") == 0) { |
| 1473 | if (strcmp(args[2], "server") == 0) { |
| 1474 | struct server *sv; |
| 1475 | struct session *sess, *sess_bck; |
| 1476 | |
| 1477 | sv = expect_server_admin(s, si, args[3]); |
| 1478 | if (!sv) |
| 1479 | return 1; |
| 1480 | |
| 1481 | /* kill all the session that are on this server */ |
| 1482 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 1483 | if (sess->srv_conn == sv) |
| 1484 | session_shutdown(sess, SN_ERR_KILLED); |
| 1485 | |
| 1486 | return 1; |
| 1487 | } |
| 1488 | else { |
| 1489 | si->applet.ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 1490 | si->applet.st0 = STAT_CLI_PRINT; |
| 1491 | return 1; |
| 1492 | } |
| 1493 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1494 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 1495 | 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] | 1496 | si->applet.st0 = STAT_CLI_PRINT; |
| 1497 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1498 | } |
| 1499 | } |
| 1500 | 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] | 1501 | return 0; |
| 1502 | } |
| 1503 | return 1; |
| 1504 | } |
| 1505 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1506 | /* 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] | 1507 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 1508 | * state machine handling requests and various responses. We read a request, |
| 1509 | * 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] | 1510 | * Then we can read again. The state is stored in si->applet.st0 and is one of the |
| 1511 | * 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] | 1512 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1513 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 1514 | static void cli_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1515 | { |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1516 | struct channel *req = si->ob; |
| 1517 | struct channel *res = si->ib; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1518 | int reql; |
| 1519 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1520 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1521 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 1522 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1523 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1524 | while (1) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1525 | if (si->applet.st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1526 | /* Stats output not initialized yet */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1527 | memset(&si->applet.ctx.stats, 0, sizeof(si->applet.ctx.stats)); |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1528 | si->applet.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1529 | } |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1530 | else if (si->applet.st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1531 | /* Let's close for real now. We just close the request |
| 1532 | * side, the conditions below will complete if needed. |
| 1533 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1534 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1535 | break; |
| 1536 | } |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1537 | else if (si->applet.st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1538 | /* ensure we have some output room left in the event we |
| 1539 | * would want to return some info right after parsing. |
| 1540 | */ |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1541 | if (buffer_almost_full(si->ib->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1542 | break; |
| 1543 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1544 | reql = bo_getline(si->ob, trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1545 | if (reql <= 0) { /* closed or EOL not found */ |
| 1546 | if (reql == 0) |
| 1547 | break; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1548 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1549 | continue; |
| 1550 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1551 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1552 | /* seek for a possible semi-colon. If we find one, we |
| 1553 | * replace it with an LF and skip only this part. |
| 1554 | */ |
| 1555 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1556 | if (trash.str[len] == ';') { |
| 1557 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1558 | reql = len + 1; |
| 1559 | break; |
| 1560 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1561 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1562 | /* now it is time to check that we have a full line, |
| 1563 | * remove the trailing \n and possibly \r, then cut the |
| 1564 | * line. |
| 1565 | */ |
| 1566 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1567 | if (trash.str[len] != '\n') { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1568 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1569 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1570 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1571 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1572 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 1573 | len--; |
| 1574 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1575 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1576 | |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1577 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1578 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1579 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1580 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1581 | continue; |
| 1582 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1583 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1584 | si->applet.st1 = !si->applet.st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1585 | else if (strcmp(trash.str, "help") == 0 || |
| 1586 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1587 | si->applet.ctx.cli.msg = stats_sock_usage_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1588 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1589 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1590 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1591 | * another STAT_CLI_O_* into si->applet.st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1592 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1593 | } |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1594 | else if (!si->applet.st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1595 | /* if prompt is disabled, print help on empty lines, |
| 1596 | * so that the user at least knows how to enable |
| 1597 | * prompt and find help. |
| 1598 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1599 | si->applet.ctx.cli.msg = stats_sock_usage_msg; |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1600 | si->applet.st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | /* re-adjust req buffer */ |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1604 | bo_skip(si->ob, reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1605 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1606 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1607 | 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] | 1608 | if (res->flags & (CF_SHUTR_NOW|CF_SHUTR)) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1609 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1610 | continue; |
| 1611 | } |
| 1612 | |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1613 | switch (si->applet.st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1614 | case STAT_CLI_PRINT: |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1615 | if (bi_putstr(si->ib, si->applet.ctx.cli.msg) != -1) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1616 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1617 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1618 | case STAT_CLI_O_INFO: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1619 | if (stats_dump_raw_to_buffer(si)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1620 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1621 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1622 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1623 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1624 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1625 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1626 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1627 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1628 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1629 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1630 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1631 | case STAT_CLI_O_CLR: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1632 | if (stats_table_request(si, si->applet.st0)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1633 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1634 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1635 | default: /* abnormal state */ |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1636 | si->applet.st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1637 | break; |
| 1638 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1639 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1640 | /* 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] | 1641 | if (si->applet.st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 9dab5fc | 2012-05-07 11:56:55 +0200 | [diff] [blame] | 1642 | if (bi_putstr(si->ib, si->applet.st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1643 | si->applet.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1644 | } |
| 1645 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1646 | /* 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] | 1647 | if (si->applet.st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1648 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1649 | |
| 1650 | /* Now we close the output if one of the writers did so, |
| 1651 | * or if we're not in interactive mode and the request |
| 1652 | * buffer is empty. This still allows pipelined requests |
| 1653 | * to be sent in non-interactive mode. |
| 1654 | */ |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1655 | 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] | 1656 | si->applet.st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1657 | continue; |
| 1658 | } |
| 1659 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1660 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1661 | si->applet.st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1662 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1663 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1664 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1665 | 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] | 1666 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 1667 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1668 | /* 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] | 1669 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 1670 | * we forward the close to the request side so that it flows upstream to |
| 1671 | * the client. |
| 1672 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1673 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1674 | } |
| 1675 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1676 | 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] | 1677 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 1678 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 1679 | /* We have no more processing to do, and nothing more to send, and |
| 1680 | * the client side has closed. So we'll forward this state downstream |
| 1681 | * on the response buffer. |
| 1682 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1683 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1684 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1688 | si_update(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1689 | |
| 1690 | /* we don't want to expire timeouts while we're processing requests */ |
| 1691 | si->ib->rex = TICK_ETERNITY; |
| 1692 | si->ob->wex = TICK_ETERNITY; |
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 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1695 | 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] | 1696 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1697 | 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] | 1698 | |
| 1699 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 1700 | /* check that we have released everything then unregister */ |
| 1701 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1702 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1703 | } |
| 1704 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1705 | /* This function dumps statistics onto the stream interface's read buffer. |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1706 | * 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] | 1707 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 1708 | * Some states are not used but it makes the code more similar to other |
| 1709 | * functions which handle stats too. |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1710 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1711 | static int stats_dump_raw_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1712 | { |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1713 | struct proxy *px; |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1714 | unsigned int up; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1715 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1716 | chunk_reset(&trash); |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1717 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1718 | switch (si->conn->xprt_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1719 | case STAT_ST_INIT: |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1720 | /* the function had not been called yet */ |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1721 | si->conn->xprt_st = STAT_ST_HEAD; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1722 | /* fall through */ |
| 1723 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1724 | case STAT_ST_HEAD: |
| 1725 | if (si->applet.ctx.stats.flags & STAT_SHOW_STAT) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1726 | print_csv_header(&trash); |
| 1727 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1728 | return 0; |
| 1729 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1730 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1731 | si->conn->xprt_st = STAT_ST_INFO; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1732 | /* fall through */ |
| 1733 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1734 | case STAT_ST_INFO: |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1735 | up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1736 | if (si->applet.ctx.stats.flags & STAT_SHOW_INFO) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1737 | chunk_appendf(&trash, |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1738 | "Name: " PRODUCT_NAME "\n" |
| 1739 | "Version: " HAPROXY_VERSION "\n" |
| 1740 | "Release_date: " HAPROXY_DATE "\n" |
| 1741 | "Nbproc: %d\n" |
| 1742 | "Process_num: %d\n" |
| 1743 | "Pid: %d\n" |
| 1744 | "Uptime: %dd %dh%02dm%02ds\n" |
| 1745 | "Uptime_sec: %d\n" |
| 1746 | "Memmax_MB: %d\n" |
| 1747 | "Ulimit-n: %d\n" |
| 1748 | "Maxsock: %d\n" |
| 1749 | "Maxconn: %d\n" |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1750 | "Hard_maxconn: %d\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 1751 | "Maxpipes: %d\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1752 | "CurrConns: %d\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 1753 | "PipesUsed: %d\n" |
| 1754 | "PipesFree: %d\n" |
Willy Tarreau | 9cd552d | 2011-09-07 15:26:48 +0200 | [diff] [blame] | 1755 | "ConnRate: %d\n" |
| 1756 | "ConnRateLimit: %d\n" |
| 1757 | "MaxConnRate: %d\n" |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1758 | "CompressBpsIn: %u\n" |
| 1759 | "CompressBpsOut: %u\n" |
William Lallemand | 096f554 | 2012-11-19 17:26:05 +0100 | [diff] [blame] | 1760 | "CompressBpsRateLim: %u\n" |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1761 | #ifdef USE_ZLIB |
| 1762 | "ZlibMemUsage: %ld\n" |
| 1763 | "MaxZlibMemUsage: %ld\n" |
| 1764 | #endif |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 1765 | "Tasks: %d\n" |
| 1766 | "Run_queue: %d\n" |
Willy Tarreau | 45a1251 | 2011-09-10 16:56:42 +0200 | [diff] [blame] | 1767 | "Idle_pct: %d\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1768 | "node: %s\n" |
| 1769 | "description: %s\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1770 | "", |
| 1771 | global.nbproc, |
| 1772 | relative_pid, |
| 1773 | pid, |
| 1774 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 1775 | up, |
| 1776 | global.rlimit_memmax, |
| 1777 | global.rlimit_nofile, |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1778 | global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes, |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 1779 | actconn, pipes_used, pipes_free, |
Willy Tarreau | 9cd552d | 2011-09-07 15:26:48 +0200 | [diff] [blame] | 1780 | read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max, |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1781 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
William Lallemand | 096f554 | 2012-11-19 17:26:05 +0100 | [diff] [blame] | 1782 | global.comp_rate_lim, |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 1783 | #ifdef USE_ZLIB |
| 1784 | zlib_used_memory, global.maxzlibmem, |
| 1785 | #endif |
Willy Tarreau | 45a1251 | 2011-09-10 16:56:42 +0200 | [diff] [blame] | 1786 | nb_tasks_cur, run_queue_cur, idle_pct, |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1787 | global.node, global.desc?global.desc:"" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1788 | ); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1789 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1790 | return 0; |
| 1791 | } |
| 1792 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1793 | si->applet.ctx.stats.px = proxy; |
| 1794 | si->applet.ctx.stats.px_st = STAT_PX_ST_INIT; |
| 1795 | si->applet.ctx.stats.sv = NULL; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1796 | si->conn->xprt_st = STAT_ST_LIST; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1797 | /* fall through */ |
| 1798 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1799 | case STAT_ST_LIST: |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1800 | /* dump proxies */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1801 | if (si->applet.ctx.stats.flags & STAT_SHOW_STAT) { |
| 1802 | while (si->applet.ctx.stats.px) { |
| 1803 | px = si->applet.ctx.stats.px; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 1804 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 1805 | if (px->state != PR_STSTOPPED && px->uuid > 0 && |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1806 | (px->cap & (PR_CAP_FE | PR_CAP_BE))) { |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1807 | if (stats_dump_proxy(si, px, NULL) == 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1808 | return 0; |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1809 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1810 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1811 | si->applet.ctx.stats.px = px->next; |
| 1812 | si->applet.ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1813 | } |
| 1814 | /* here, we just have reached the last proxy */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1815 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1816 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1817 | si->conn->xprt_st = STAT_ST_END; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1818 | /* fall through */ |
| 1819 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1820 | case STAT_ST_END: |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1821 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 1822 | /* fall through */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1823 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1824 | case STAT_ST_FIN: |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1825 | return 1; |
| 1826 | |
| 1827 | default: |
| 1828 | /* unknown state ! */ |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1829 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1830 | return 1; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1831 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1835 | /* We don't want to land on the posted stats page because a refresh will |
| 1836 | * repost the data. We don't want this to happen on accident so we redirect |
| 1837 | * the browse to the stats page with a GET. |
| 1838 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1839 | static int stats_http_redir(struct stream_interface *si, struct uri_auth *uri) |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1840 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1841 | struct session *s = si->conn->xprt_ctx; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1842 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1843 | chunk_reset(&trash); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1844 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1845 | switch (si->conn->xprt_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1846 | case STAT_ST_INIT: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1847 | chunk_appendf(&trash, |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1848 | "HTTP/1.0 303 See Other\r\n" |
| 1849 | "Cache-Control: no-cache\r\n" |
| 1850 | "Content-Type: text/plain\r\n" |
| 1851 | "Connection: close\r\n" |
| 1852 | "Location: %s;st=%s", |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 1853 | uri->uri_prefix, |
| 1854 | ((si->applet.ctx.stats.st_code > STAT_STATUS_INIT) && |
| 1855 | (si->applet.ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 1856 | stat_status_codes[si->applet.ctx.stats.st_code]) ? |
| 1857 | stat_status_codes[si->applet.ctx.stats.st_code] : |
| 1858 | stat_status_codes[STAT_STATUS_UNKN]); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1859 | chunk_appendf(&trash, "\r\n\r\n"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1860 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1861 | if (bi_putchk(si->ib, &trash) == -1) |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1862 | return 0; |
| 1863 | |
| 1864 | s->txn.status = 303; |
| 1865 | |
| 1866 | if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is |
| 1867 | s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy |
| 1868 | if (!(s->flags & SN_FINST_MASK)) |
| 1869 | s->flags |= SN_FINST_R; |
| 1870 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1871 | si->conn->xprt_st = STAT_ST_FIN; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1872 | return 1; |
| 1873 | } |
| 1874 | return 1; |
| 1875 | } |
| 1876 | |
| 1877 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1878 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 1879 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1880 | * si->applet.st0 becomes non-zero once the transfer is finished. The handler |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1881 | * automatically unregisters itself once transfer is complete. |
| 1882 | */ |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 1883 | static void http_stats_io_handler(struct stream_interface *si) |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1884 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1885 | struct session *s = si->conn->xprt_ctx; |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1886 | struct channel *req = si->ob; |
| 1887 | struct channel *res = si->ib; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1888 | |
| 1889 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 1890 | goto out; |
| 1891 | |
| 1892 | /* check that the output is not closed */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1893 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1894 | si->applet.st0 = 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1895 | |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1896 | if (!si->applet.st0) { |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1897 | if (s->txn.meth == HTTP_METH_POST) { |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1898 | if (stats_http_redir(si, s->be->uri_auth)) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1899 | si->applet.st0 = 1; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1900 | si_shutw(si); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1901 | } |
| 1902 | } else { |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1903 | if (stats_dump_http(si, s->be->uri_auth)) { |
Willy Tarreau | bc4af05 | 2011-02-13 13:25:14 +0100 | [diff] [blame] | 1904 | si->applet.st0 = 1; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1905 | si_shutw(si); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 1906 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1910 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1911 | si_shutw(si); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1912 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1913 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && si->applet.st0) { |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1914 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1915 | res->flags |= CF_READ_NULL; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | /* update all other flags and resync with the other side */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1919 | si_update(si); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1920 | |
| 1921 | /* we don't want to expire timeouts while we're processing requests */ |
| 1922 | si->ib->rex = TICK_ETERNITY; |
| 1923 | si->ob->wex = TICK_ETERNITY; |
| 1924 | |
| 1925 | out: |
| 1926 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 1927 | /* check that we have released everything then unregister */ |
| 1928 | stream_int_unregister_handler(si); |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 1933 | /* This function dumps statistics in HTTP format onto the stream interface's |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 1934 | * 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] | 1935 | * properly set. It returns 0 if it had to stop writing data and an I/O is |
| 1936 | * needed, 1 if the dump is finished and the session must be closed, or -1 |
| 1937 | * in case of any error. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1938 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1939 | static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1940 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1941 | struct session *s = si->conn->xprt_ctx; |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1942 | struct channel *rep = si->ib; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1943 | struct proxy *px; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1944 | unsigned int up; |
| 1945 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1946 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1947 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1948 | switch (si->conn->xprt_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1949 | case STAT_ST_INIT: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1950 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1951 | "HTTP/1.0 200 OK\r\n" |
| 1952 | "Cache-Control: no-cache\r\n" |
| 1953 | "Connection: close\r\n" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1954 | "Content-Type: %s\r\n", |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1955 | (si->applet.ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1956 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1957 | if (uri->refresh > 0 && !(si->applet.ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1958 | chunk_appendf(&trash, "Refresh: %d\r\n", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1959 | uri->refresh); |
| 1960 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1961 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1962 | |
| 1963 | s->txn.status = 200; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1964 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 56a560a | 2009-09-22 19:27:35 +0200 | [diff] [blame] | 1965 | return 0; |
| 1966 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1967 | if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is |
| 1968 | s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy |
| 1969 | if (!(s->flags & SN_FINST_MASK)) |
| 1970 | s->flags |= SN_FINST_R; |
| 1971 | |
| 1972 | if (s->txn.meth == HTTP_METH_HEAD) { |
| 1973 | /* that's all we return in case of HEAD request */ |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1974 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1975 | return 1; |
| 1976 | } |
| 1977 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1978 | si->conn->xprt_st = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1979 | /* fall through */ |
| 1980 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 1981 | case STAT_ST_HEAD: |
| 1982 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 1983 | /* WARNING! This must fit in the first buffer !!! */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1984 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1985 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 1986 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 1987 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1988 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 1989 | "<style type=\"text/css\"><!--\n" |
| 1990 | "body {" |
Willy Tarreau | a94f2d2 | 2009-05-10 20:08:10 +0200 | [diff] [blame] | 1991 | " font-family: arial, helvetica, sans-serif;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1992 | " font-size: 12px;" |
| 1993 | " font-weight: normal;" |
| 1994 | " color: black;" |
| 1995 | " background: white;" |
| 1996 | "}\n" |
| 1997 | "th,td {" |
Willy Tarreau | a94f2d2 | 2009-05-10 20:08:10 +0200 | [diff] [blame] | 1998 | " font-size: 10px;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1999 | "}\n" |
| 2000 | "h1 {" |
Willy Tarreau | da6721b | 2009-07-15 10:07:05 +0200 | [diff] [blame] | 2001 | " font-size: x-large;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2002 | " margin-bottom: 0.5em;" |
| 2003 | "}\n" |
| 2004 | "h2 {" |
| 2005 | " font-family: helvetica, arial;" |
| 2006 | " font-size: x-large;" |
| 2007 | " font-weight: bold;" |
| 2008 | " font-style: italic;" |
| 2009 | " color: #6020a0;" |
| 2010 | " margin-top: 0em;" |
| 2011 | " margin-bottom: 0em;" |
| 2012 | "}\n" |
| 2013 | "h3 {" |
| 2014 | " font-family: helvetica, arial;" |
| 2015 | " font-size: 16px;" |
| 2016 | " font-weight: bold;" |
| 2017 | " color: #b00040;" |
| 2018 | " background: #e8e8d0;" |
| 2019 | " margin-top: 0em;" |
| 2020 | " margin-bottom: 0em;" |
| 2021 | "}\n" |
| 2022 | "li {" |
| 2023 | " margin-top: 0.25em;" |
| 2024 | " margin-right: 2em;" |
| 2025 | "}\n" |
| 2026 | ".hr {margin-top: 0.25em;" |
| 2027 | " border-color: black;" |
| 2028 | " border-bottom-style: solid;" |
| 2029 | "}\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2030 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2031 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 2032 | ".frontend {background: #e8e8d0;}\n" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2033 | ".socket {background: #d0d0d0;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2034 | ".backend {background: #e8e8d0;}\n" |
| 2035 | ".active0 {background: #ff9090;}\n" |
| 2036 | ".active1 {background: #ffd020;}\n" |
| 2037 | ".active2 {background: #ffffa0;}\n" |
| 2038 | ".active3 {background: #c0ffc0;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2039 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 2040 | ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */ |
| 2041 | ".active6 {background: #e0e0e0;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2042 | ".backup0 {background: #ff9090;}\n" |
| 2043 | ".backup1 {background: #ff80ff;}\n" |
| 2044 | ".backup2 {background: #c060ff;}\n" |
| 2045 | ".backup3 {background: #b0d0ff;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2046 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 2047 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 2048 | ".backup6 {background: #e0e0e0;}\n" |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2049 | ".maintain {background: #c07820;}\n" |
Willy Tarreau | da6721b | 2009-07-15 10:07:05 +0200 | [diff] [blame] | 2050 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2051 | "\n" |
Krzysztof Piotr Oledzki | 1f67285 | 2009-10-24 14:24:30 +0200 | [diff] [blame] | 2052 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 2053 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 2054 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 2055 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 2056 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 2057 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 2058 | "\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2059 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2060 | "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" |
| 2061 | "table.tbl td.ac { text-align: center;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2062 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2063 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
Willy Tarreau | da6721b | 2009-07-15 10:07:05 +0200 | [diff] [blame] | 2064 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2065 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2066 | "\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2067 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 2068 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 2069 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2070 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2071 | "-->\n" |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 2072 | "</style></head>\n", |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2073 | (uri->flags&ST_SHNODE) ? " on " : "", |
| 2074 | (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 2075 | ); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2076 | } else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2077 | print_csv_header(&trash); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2078 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2079 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2080 | return 0; |
| 2081 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 2082 | si->conn->xprt_st = STAT_ST_INFO; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2083 | /* fall through */ |
| 2084 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2085 | case STAT_ST_INFO: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2086 | up = (now.tv_sec - start_date.tv_sec); |
| 2087 | |
| 2088 | /* WARNING! this has to fit the first packet too. |
| 2089 | * We are around 3.5 kB, add adding entries will |
| 2090 | * become tricky if we want to support 4kB buffers ! |
| 2091 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2092 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2093 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2094 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 2095 | PRODUCT_NAME "%s</a></h1>\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2096 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2097 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 2098 | "<h3>> General process information</h3>\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2099 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 2100 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2101 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2102 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 2103 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
Willy Tarreau | 9cd552d | 2011-09-07 15:26:48 +0200 | [diff] [blame] | 2104 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
Willy Tarreau | 45a1251 | 2011-09-10 16:56:42 +0200 | [diff] [blame] | 2105 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2106 | "</td><td align=\"center\" nowrap>\n" |
| 2107 | "<table class=\"lgd\"><tr>\n" |
| 2108 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 2109 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 2110 | "</tr><tr>\n" |
| 2111 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 2112 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 2113 | "</tr><tr>\n" |
| 2114 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 2115 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 2116 | "</tr><tr>\n" |
| 2117 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2118 | "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>" |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2119 | "</tr><tr>\n" |
| 2120 | "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) </td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2121 | "</tr></table>\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2122 | "Note: UP with load-balancing disabled is reported as \"NOLB\"." |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2123 | "</td>" |
| 2124 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 2125 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 2126 | "", |
| 2127 | (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING), |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2128 | pid, (uri->flags&ST_SHNODE) ? " on " : "", (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 2129 | (uri->flags&ST_SHDESC)? ": " : "", (uri->flags&ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 2130 | pid, relative_pid, global.nbproc, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2131 | up / 86400, (up % 86400) / 3600, |
| 2132 | (up % 3600) / 60, (up % 60), |
| 2133 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 2134 | global.rlimit_memmax ? " MB" : "", |
| 2135 | global.rlimit_nofile, |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 2136 | global.maxsock, global.maxconn, global.maxpipes, |
Willy Tarreau | 9cd552d | 2011-09-07 15:26:48 +0200 | [diff] [blame] | 2137 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
Willy Tarreau | 45a1251 | 2011-09-10 16:56:42 +0200 | [diff] [blame] | 2138 | run_queue_cur, nb_tasks_cur, idle_pct |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2139 | ); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2140 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2141 | if (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2142 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2143 | "<li><a href=\"%s%s%s\">Show all servers</a><br>\n", |
| 2144 | uri->uri_prefix, |
| 2145 | "", |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2146 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2147 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2148 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2149 | "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 2150 | uri->uri_prefix, |
| 2151 | ";up", |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2152 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2153 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2154 | if (uri->refresh > 0) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2155 | if (si->applet.ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2156 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2157 | "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n", |
| 2158 | uri->uri_prefix, |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2159 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2160 | ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2161 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2162 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2163 | "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n", |
| 2164 | uri->uri_prefix, |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2165 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2166 | ";norefresh"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2167 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2168 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2169 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2170 | "<li><a href=\"%s%s%s\">Refresh now</a><br>\n", |
| 2171 | uri->uri_prefix, |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2172 | (si->applet.ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2173 | (si->applet.ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2174 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2175 | chunk_appendf(&trash, |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 2176 | "<li><a href=\"%s;csv%s\">CSV export</a><br>\n", |
| 2177 | uri->uri_prefix, |
| 2178 | (uri->refresh > 0) ? ";norefresh" : ""); |
| 2179 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2180 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2181 | "</ul></td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2182 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
Adrian Bridgett | afdb6e5 | 2012-03-19 23:36:42 +0000 | [diff] [blame] | 2183 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2184 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 2185 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 2186 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 2187 | "</ul>" |
| 2188 | "</td>" |
| 2189 | "</tr></table>\n" |
| 2190 | "" |
| 2191 | ); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2192 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2193 | if (si->applet.ctx.stats.st_code) { |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 2194 | switch (si->applet.ctx.stats.st_code) { |
| 2195 | case STAT_STATUS_DONE: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2196 | chunk_appendf(&trash, |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2197 | "<p><div class=active3>" |
| 2198 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 2199 | "Action processed successfully." |
| 2200 | "</div>\n", uri->uri_prefix); |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 2201 | break; |
| 2202 | case STAT_STATUS_NONE: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2203 | chunk_appendf(&trash, |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2204 | "<p><div class=active2>" |
| 2205 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 2206 | "Nothing has changed." |
| 2207 | "</div>\n", uri->uri_prefix); |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 2208 | break; |
| 2209 | case STAT_STATUS_PART: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2210 | chunk_appendf(&trash, |
Cyril Bonté | cf8d9ae | 2012-04-04 12:57:18 +0200 | [diff] [blame] | 2211 | "<p><div class=active2>" |
| 2212 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 2213 | "Action partially processed.<br>" |
| 2214 | "Some server names are probably unknown or ambiguous (duplicated names in the backend)." |
| 2215 | "</div>\n", uri->uri_prefix); |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 2216 | break; |
| 2217 | case STAT_STATUS_ERRP: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2218 | chunk_appendf(&trash, |
Cyril Bonté | cf8d9ae | 2012-04-04 12:57:18 +0200 | [diff] [blame] | 2219 | "<p><div class=active0>" |
| 2220 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 2221 | "Action not processed because of invalid parameters." |
| 2222 | "<ul>" |
| 2223 | "<li>The action is maybe unknown.</li>" |
| 2224 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 2225 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 2226 | "</ul>" |
| 2227 | "</div>\n", uri->uri_prefix); |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 2228 | break; |
| 2229 | case STAT_STATUS_EXCD: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2230 | chunk_appendf(&trash, |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2231 | "<p><div class=active0>" |
| 2232 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 2233 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 2234 | "You should retry with less servers at a time.</b>" |
| 2235 | "</div>\n", uri->uri_prefix); |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 2236 | break; |
| 2237 | case STAT_STATUS_DENY: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2238 | chunk_appendf(&trash, |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 2239 | "<p><div class=active0>" |
| 2240 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 2241 | "<b>Action denied.</b>" |
| 2242 | "</div>\n", uri->uri_prefix); |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 2243 | break; |
| 2244 | default: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2245 | chunk_appendf(&trash, |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2246 | "<p><div class=active6>" |
| 2247 | "<a class=lfsb href=\"%s\" title=\"Remove this message\">[X]</a> " |
| 2248 | "Unexpected result." |
| 2249 | "</div>\n", uri->uri_prefix); |
| 2250 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2251 | chunk_appendf(&trash,"<p>\n"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2252 | } |
| 2253 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2254 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2255 | return 0; |
| 2256 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2257 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2258 | si->applet.ctx.stats.px = proxy; |
| 2259 | si->applet.ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 2260 | si->conn->xprt_st = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2261 | /* fall through */ |
| 2262 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2263 | case STAT_ST_LIST: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2264 | /* dump proxies */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2265 | while (si->applet.ctx.stats.px) { |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2266 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2267 | return 0; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2268 | px = si->applet.ctx.stats.px; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 2269 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 2270 | if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE))) |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2271 | if (stats_dump_proxy(si, px, uri) == 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2272 | return 0; |
| 2273 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2274 | si->applet.ctx.stats.px = px->next; |
| 2275 | si->applet.ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2276 | } |
| 2277 | /* here, we just have reached the last proxy */ |
| 2278 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 2279 | si->conn->xprt_st = STAT_ST_END; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2280 | /* fall through */ |
| 2281 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2282 | case STAT_ST_END: |
| 2283 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2284 | chunk_appendf(&trash, "</body></html>\n"); |
| 2285 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2286 | return 0; |
| 2287 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2288 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 2289 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2290 | /* fall through */ |
| 2291 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2292 | case STAT_ST_FIN: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2293 | return 1; |
| 2294 | |
| 2295 | default: |
| 2296 | /* unknown state ! */ |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 2297 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2298 | return -1; |
| 2299 | } |
| 2300 | } |
| 2301 | |
| 2302 | |
| 2303 | /* |
| 2304 | * Dumps statistics for a proxy. |
| 2305 | * Returns 0 if it had to stop dumping data because of lack of buffer space, |
| 2306 | * ot non-zero if everything completed. |
| 2307 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 2308 | 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] | 2309 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 2310 | struct session *s = si->conn->xprt_ctx; |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 2311 | struct channel *rep = si->ib; |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2312 | 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] | 2313 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2314 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2315 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2316 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2317 | switch (si->applet.ctx.stats.px_st) { |
| 2318 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2319 | /* we are on a new proxy */ |
| 2320 | |
| 2321 | if (uri && uri->scope) { |
| 2322 | /* we have a limited scope, we have to check the proxy name */ |
| 2323 | struct stat_scope *scope; |
| 2324 | int len; |
| 2325 | |
| 2326 | len = strlen(px->id); |
| 2327 | scope = uri->scope; |
| 2328 | |
| 2329 | while (scope) { |
| 2330 | /* match exact proxy name */ |
| 2331 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 2332 | break; |
| 2333 | |
| 2334 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 2335 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2336 | break; |
| 2337 | scope = scope->next; |
| 2338 | } |
| 2339 | |
| 2340 | /* proxy name not found : don't dump anything */ |
| 2341 | if (scope == NULL) |
| 2342 | return 1; |
| 2343 | } |
| 2344 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2345 | if ((si->applet.ctx.stats.flags & STAT_BOUND) && (si->applet.ctx.stats.iid != -1) && |
| 2346 | (px->uuid != si->applet.ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2347 | return 1; |
| 2348 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2349 | si->applet.ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2350 | /* fall through */ |
| 2351 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2352 | case STAT_PX_ST_TH: |
| 2353 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
| 2354 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2355 | /* A form to enable/disable this proxy servers */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2356 | chunk_appendf(&trash, |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2357 | "<form action=\"%s\" method=\"post\">", |
| 2358 | uri->uri_prefix); |
| 2359 | } |
| 2360 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2361 | /* print a new table */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2362 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2363 | "<table class=\"tbl\" width=\"100%%\">\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2364 | "<tr class=\"titre\">" |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2365 | "<th class=\"pxname\" width=\"10%%\""); |
| 2366 | |
| 2367 | if (uri->flags&ST_SHLGNDS) { |
| 2368 | /* cap, mode, id */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2369 | chunk_appendf(&trash, " title=\"cap: %s, mode: %s, id: %d", |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2370 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 2371 | px->uuid); |
| 2372 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2373 | chunk_appendf(&trash, "\""); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2374 | } |
| 2375 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2376 | chunk_appendf(&trash, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2377 | ">%s<a name=\"%s\"></a>" |
| 2378 | "<a class=px href=\"#%s\">%s</a>%s</th>" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2379 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2380 | "</tr>\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 2381 | "</table>\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2382 | "<table class=\"tbl\" width=\"100%%\">\n" |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2383 | "<tr class=\"titre\">", |
| 2384 | (uri->flags & ST_SHLGNDS)?"<u>":"", |
| 2385 | px->id, px->id, px->id, |
| 2386 | (uri->flags & ST_SHLGNDS)?"</u>":"", |
| 2387 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 2388 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2389 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2390 | /* Column heading for Enable or Disable server */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2391 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2392 | } |
| 2393 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2394 | chunk_appendf(&trash, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2395 | "<th rowspan=2></th>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 2396 | "<th colspan=3>Queue</th>" |
| 2397 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2398 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 2399 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2400 | "<th colspan=9>Server</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2401 | "</tr>\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2402 | "<tr class=\"titre\">" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 2403 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 2404 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 2405 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2406 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 2407 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2408 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2409 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 2410 | "<th>Thrtle</th>\n" |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2411 | "</tr>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2412 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2413 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2414 | return 0; |
| 2415 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2416 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2417 | si->applet.ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2418 | /* fall through */ |
| 2419 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2420 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2421 | /* print the frontend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 2422 | if ((px->cap & PR_CAP_FE) && |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2423 | (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_FE)))) { |
| 2424 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2425 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2426 | /* name, queue */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2427 | "<tr class=\"frontend\">"); |
| 2428 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2429 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2430 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2431 | chunk_appendf(&trash, "<td></td>"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2432 | } |
| 2433 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2434 | chunk_appendf(&trash, |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2435 | "<td class=ac>" |
Krzysztof Piotr Oledzki | 1f67285 | 2009-10-24 14:24:30 +0200 | [diff] [blame] | 2436 | "<a name=\"%s/Frontend\"></a>" |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2437 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 2438 | "<td colspan=3></td>" |
Willy Tarreau | b44939a | 2010-02-26 11:35:39 +0100 | [diff] [blame] | 2439 | "", |
| 2440 | px->id, px->id); |
| 2441 | |
| 2442 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2443 | chunk_appendf(&trash, |
Willy Tarreau | b44939a | 2010-02-26 11:35:39 +0100 | [diff] [blame] | 2444 | /* sessions rate : current, max, limit */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2445 | "<td title=\"Cur: %u req/s\"><u>%s</u></td><td title=\"Max: %u req/s\"><u>%s</u></td><td>%s</td>" |
Willy Tarreau | b44939a | 2010-02-26 11:35:39 +0100 | [diff] [blame] | 2446 | "", |
| 2447 | read_freq_ctr(&px->fe_req_per_sec), |
| 2448 | U2H0(read_freq_ctr(&px->fe_sess_per_sec)), |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2449 | px->fe_counters.p.http.rps_max, |
| 2450 | U2H1(px->fe_counters.sps_max), |
Willy Tarreau | b44939a | 2010-02-26 11:35:39 +0100 | [diff] [blame] | 2451 | LIM2A2(px->fe_sps_lim, "-")); |
| 2452 | } else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2453 | chunk_appendf(&trash, |
Willy Tarreau | b44939a | 2010-02-26 11:35:39 +0100 | [diff] [blame] | 2454 | /* sessions rate : current, max, limit */ |
| 2455 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2456 | "", |
| 2457 | U2H0(read_freq_ctr(&px->fe_sess_per_sec)), |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2458 | U2H1(px->fe_counters.sps_max), LIM2A2(px->fe_sps_lim, "-")); |
Willy Tarreau | b44939a | 2010-02-26 11:35:39 +0100 | [diff] [blame] | 2459 | } |
| 2460 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2461 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2462 | /* sessions: current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2463 | "<td>%s</td><td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2464 | "<td" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2465 | "", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2466 | U2H3(px->feconn), U2H4(px->fe_counters.conn_max), U2H5(px->maxconn)); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2467 | |
| 2468 | /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2469 | if (px->mode == PR_MODE_HTTP) { |
| 2470 | int i; |
| 2471 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2472 | chunk_appendf(&trash, " title=\"%lld requests:", px->fe_counters.p.http.cum_req); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2473 | |
| 2474 | for (i = 1; i < 6; i++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2475 | chunk_appendf(&trash, " %dxx=%lld,", i, px->fe_counters.p.http.rsp[i]); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2476 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2477 | chunk_appendf(&trash, " other=%lld,", px->fe_counters.p.http.rsp[0]); |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 2478 | chunk_appendf(&trash, " compressed=%lld (%d%%)", |
| 2479 | px->fe_counters.p.http.comp_rsp, |
| 2480 | px->fe_counters.p.http.cum_req ? |
Willy Tarreau | 5730c68 | 2012-11-26 14:13:09 +0100 | [diff] [blame] | 2481 | (int)(100*px->fe_counters.p.http.comp_rsp/px->fe_counters.p.http.rsp[2]) : 0); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2482 | chunk_appendf(&trash, " intercepted=%lld\"", px->fe_counters.intercepted_req); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2483 | } |
| 2484 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2485 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2486 | /* sessions: total, lbtot */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2487 | ">%s%s%s</td><td></td>" |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 2488 | /* bytes : in */ |
| 2489 | "<td>%s</td><td" |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2490 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2491 | (px->mode == PR_MODE_HTTP)?"<u>":"", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2492 | U2H6(px->fe_counters.cum_sess), |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2493 | (px->mode == PR_MODE_HTTP)?"</u>":"", |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 2494 | U2H7(px->fe_counters.bytes_in)); |
| 2495 | |
| 2496 | /* compression stats (via td title): comp_in, comp_out, comp_byp */ |
Willy Tarreau | f149d8f | 2012-11-24 14:06:49 +0100 | [diff] [blame] | 2497 | chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld savings=%d%%\"", |
| 2498 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp, |
| 2499 | px->fe_counters.comp_in ? |
| 2500 | (int)((px->fe_counters.comp_in - px->fe_counters.comp_out)*100/px->fe_counters.comp_in) : 0); |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2501 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2502 | chunk_appendf(&trash, |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 2503 | /* bytes: out */ |
| 2504 | ">%s%s%s</td>" |
| 2505 | "", |
| 2506 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
| 2507 | U2H0(px->fe_counters.bytes_out), |
| 2508 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
| 2509 | |
| 2510 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2511 | /* denied: req, resp */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2512 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2513 | /* errors : request, connect, response */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2514 | "<td>%s</td><td></td><td></td>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 2515 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2516 | "<td></td><td></td>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2517 | /* server status : reflect frontend status */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2518 | "<td class=ac>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2519 | /* rest of server: nothing */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2520 | "<td class=ac colspan=8></td></tr>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2521 | "", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2522 | U2H0(px->fe_counters.denied_req), U2H1(px->fe_counters.denied_resp), |
| 2523 | U2H2(px->fe_counters.failed_req), |
Willy Tarreau | 562515c | 2011-07-25 08:11:52 +0200 | [diff] [blame] | 2524 | px->state == PR_STREADY ? "OPEN" : |
| 2525 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2526 | } else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2527 | chunk_appendf(&trash, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2528 | /* pxid, name, queue cur, queue max, */ |
| 2529 | "%s,FRONTEND,,," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 2530 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2531 | "%d,%d,%d,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2532 | /* bytes : in, out */ |
| 2533 | "%lld,%lld," |
| 2534 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2535 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2536 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2537 | "%lld,,," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 2538 | /* warnings: retries, redispatches */ |
| 2539 | ",," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2540 | /* server status : reflect frontend status */ |
| 2541 | "%s," |
| 2542 | /* rest of server: nothing */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 2543 | ",,,,,,,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2544 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2545 | "%d,%d,0,,,,%d," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2546 | /* rate, rate_lim, rate_max */ |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 2547 | "%u,%u,%u," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2548 | /* check_status, check_code, check_duration */ |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2549 | ",,,", |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2550 | px->id, |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2551 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 2552 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 2553 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 2554 | px->fe_counters.failed_req, |
Willy Tarreau | 562515c | 2011-07-25 08:11:52 +0200 | [diff] [blame] | 2555 | px->state == PR_STREADY ? "OPEN" : |
| 2556 | px->state == PR_STFULL ? "FULL" : "STOP", |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 2557 | relative_pid, px->uuid, STATS_TYPE_FE, |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 2558 | read_freq_ctr(&px->fe_sess_per_sec), |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2559 | px->fe_sps_lim, px->fe_counters.sps_max); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2560 | |
| 2561 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2562 | if (px->mode == PR_MODE_HTTP) { |
| 2563 | int i; |
| 2564 | |
| 2565 | for (i=1; i<6; i++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2566 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2567 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2568 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2569 | } else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2570 | chunk_appendf(&trash, ",,,,,,"); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2571 | } |
| 2572 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2573 | /* failed health analyses */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2574 | chunk_appendf(&trash, ","); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2575 | |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 2576 | /* requests : req_rate, req_rate_max, req_tot, */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2577 | chunk_appendf(&trash, "%u,%u,%lld,", |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 2578 | read_freq_ctr(&px->fe_req_per_sec), |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2579 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 2580 | |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2581 | /* errors: cli_aborts, srv_aborts */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2582 | chunk_appendf(&trash, ",,"); |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2583 | |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 2584 | /* compression: in, out, bypassed */ |
| 2585 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 2586 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 2587 | |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 2588 | /* compression: comp_rsp */ |
| 2589 | chunk_appendf(&trash, "%lld,", |
| 2590 | px->fe_counters.p.http.comp_rsp); |
| 2591 | |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2592 | /* finish with EOL */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2593 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2594 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2595 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2596 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2597 | return 0; |
| 2598 | } |
| 2599 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2600 | si->applet.ctx.stats.l = px->conf.listeners.n; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2601 | si->applet.ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2602 | /* fall through */ |
| 2603 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2604 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2605 | /* stats.l has been initialized above */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2606 | 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] | 2607 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2608 | return 0; |
| 2609 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 2610 | 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] | 2611 | if (!l->counters) |
| 2612 | continue; |
| 2613 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2614 | if (si->applet.ctx.stats.flags & STAT_BOUND) { |
| 2615 | if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2616 | break; |
| 2617 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2618 | 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] | 2619 | continue; |
| 2620 | } |
| 2621 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2622 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2623 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2624 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2625 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2626 | chunk_appendf(&trash, "<td></td>"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2627 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2628 | chunk_appendf(&trash, "<td class=ac"); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2629 | |
| 2630 | if (uri->flags&ST_SHLGNDS) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 2631 | char str[INET6_ADDRSTRLEN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2632 | int port; |
| 2633 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2634 | chunk_appendf(&trash, " title=\""); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2635 | |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 2636 | port = get_host_port(&l->addr); |
| 2637 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2638 | case AF_INET: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2639 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 2640 | break; |
| 2641 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2642 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 2643 | break; |
| 2644 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2645 | chunk_appendf(&trash, "unix, "); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 2646 | break; |
| 2647 | case -1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2648 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 2649 | break; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2650 | } |
| 2651 | |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2652 | /* id */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2653 | chunk_appendf(&trash, "id: %d\"", l->luid); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2654 | } |
| 2655 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2656 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2657 | /* name, queue */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2658 | ">%s<a name=\"%s/+%s\"></a>" |
| 2659 | "<a class=lfsb href=\"#%s/+%s\">%s</a></td><td colspan=3>%s</td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2660 | /* sessions rate: current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2661 | "<td colspan=3> </td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2662 | /* sessions: current, max, limit, total, lbtot */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2663 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2664 | "<td>%s</td><td> </td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2665 | /* bytes: in, out */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2666 | "<td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2667 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2668 | (uri->flags & ST_SHLGNDS)?"<u>":"", |
Krzysztof Piotr Oledzki | 2ec025d | 2010-01-04 11:33:32 +0100 | [diff] [blame] | 2669 | px->id, l->name, px->id, l->name, l->name, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2670 | (uri->flags & ST_SHLGNDS)?"</u>":"", |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2671 | U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn), |
| 2672 | U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out)); |
| 2673 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2674 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2675 | /* denied: req, resp */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2676 | "<td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2677 | /* errors: request, connect, response */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2678 | "<td>%s</td><td></td><td></td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2679 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2680 | "<td></td><td></td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2681 | /* server status: reflect listener status */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2682 | "<td class=ac>%s</td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2683 | /* rest of server: nothing */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2684 | "<td class=ac colspan=8></td></tr>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2685 | "", |
| 2686 | U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp), |
| 2687 | U2H2(l->counters->failed_req), |
Willy Tarreau | a17c2d9 | 2011-07-25 08:16:20 +0200 | [diff] [blame] | 2688 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2689 | } else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2690 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2691 | /* pxid, name, queue cur, queue max, */ |
| 2692 | "%s,%s,,," |
| 2693 | /* sessions: current, max, limit, total */ |
| 2694 | "%d,%d,%d,%lld," |
| 2695 | /* bytes: in, out */ |
| 2696 | "%lld,%lld," |
| 2697 | /* denied: req, resp */ |
| 2698 | "%lld,%lld," |
| 2699 | /* errors: request, connect, response */ |
| 2700 | "%lld,,," |
| 2701 | /* warnings: retries, redispatches */ |
| 2702 | ",," |
| 2703 | /* server status: reflect listener status */ |
| 2704 | "%s," |
| 2705 | /* rest of server: nothing */ |
| 2706 | ",,,,,,,," |
| 2707 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2708 | "%d,%d,%d,,,,%d," |
| 2709 | /* rate, rate_lim, rate_max */ |
| 2710 | ",,," |
| 2711 | /* check_status, check_code, check_duration */ |
| 2712 | ",,," |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2713 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2714 | ",,,,,," |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2715 | /* failed health analyses */ |
| 2716 | "," |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 2717 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2718 | ",,," |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2719 | /* errors: cli_aborts, srv_aborts */ |
| 2720 | ",," |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 2721 | /* compression: in, out, bypassed, comp_rsp */ |
| 2722 | ",,,," |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2723 | "\n", |
| 2724 | px->id, l->name, |
| 2725 | l->nbconn, l->counters->conn_max, |
| 2726 | l->maxconn, l->counters->cum_conn, |
| 2727 | l->counters->bytes_in, l->counters->bytes_out, |
| 2728 | l->counters->denied_req, l->counters->denied_resp, |
| 2729 | l->counters->failed_req, |
| 2730 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2731 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2732 | } |
| 2733 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2734 | if (bi_putchk(rep, &trash) == -1) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2735 | return 0; |
| 2736 | } |
| 2737 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2738 | si->applet.ctx.stats.sv = px->srv; /* may be NULL */ |
| 2739 | si->applet.ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2740 | /* fall through */ |
| 2741 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2742 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2743 | /* stats.sv has been initialized above */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2744 | 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] | 2745 | 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] | 2746 | |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2747 | if (buffer_almost_full(rep->buf)) |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2748 | return 0; |
| 2749 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2750 | sv = si->applet.ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2751 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2752 | if (si->applet.ctx.stats.flags & STAT_BOUND) { |
| 2753 | if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2754 | break; |
| 2755 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2756 | 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] | 2757 | continue; |
| 2758 | } |
| 2759 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 2760 | if (sv->track) |
| 2761 | svs = sv->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2762 | else |
| 2763 | svs = sv; |
| 2764 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2765 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2766 | if (!(svs->state & SRV_CHECKED)) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2767 | sv_state = 6; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2768 | else if (svs->state & SRV_RUNNING) { |
| 2769 | if (svs->health == svs->rise + svs->fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2770 | sv_state = 3; /* UP */ |
| 2771 | else |
| 2772 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2773 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2774 | if (svs->state & SRV_GOINGDOWN) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2775 | sv_state += 2; |
| 2776 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2777 | else |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2778 | if (svs->health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2779 | sv_state = 1; /* going up */ |
| 2780 | else |
| 2781 | sv_state = 0; /* DOWN */ |
| 2782 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2783 | 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] | 2784 | /* do not report servers which are DOWN */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2785 | si->applet.ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2786 | continue; |
| 2787 | } |
| 2788 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2789 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2790 | static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d ↑", |
| 2791 | "UP %d/%d ↓", "UP", |
| 2792 | "NOLB %d/%d ↓", "NOLB", |
| 2793 | "<i>no check</i>" }; |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2794 | if ((sv->state & SRV_MAINTAIN) || (svs->state & SRV_MAINTAIN)) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2795 | chunk_appendf(&trash, |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2796 | /* name */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2797 | "<tr class=\"maintain\">" |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2798 | ); |
| 2799 | } |
| 2800 | else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2801 | chunk_appendf(&trash, |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2802 | /* name */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2803 | "<tr class=\"%s%d\">", |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2804 | (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state); |
| 2805 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2806 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2807 | 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] | 2808 | chunk_appendf(&trash, |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 2809 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2810 | sv->id); |
| 2811 | } |
| 2812 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2813 | chunk_appendf(&trash, "<td class=ac"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2814 | |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2815 | if (uri->flags&ST_SHLGNDS) { |
| 2816 | char str[INET6_ADDRSTRLEN]; |
| 2817 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2818 | chunk_appendf(&trash, " title=\""); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2819 | |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 2820 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2821 | case AF_INET: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2822 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2823 | break; |
| 2824 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2825 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 2826 | break; |
| 2827 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2828 | chunk_appendf(&trash, "unix, "); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 2829 | break; |
| 2830 | case -1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2831 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 2832 | break; |
| 2833 | default: /* address family not supported */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2834 | break; |
| 2835 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2836 | |
| 2837 | /* id */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2838 | chunk_appendf(&trash, "id: %d", sv->puid); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2839 | |
| 2840 | /* cookie */ |
| 2841 | if (sv->cookie) { |
| 2842 | struct chunk src; |
| 2843 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2844 | chunk_appendf(&trash, ", cookie: '"); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2845 | |
| 2846 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2847 | chunk_htmlencode(&trash, &src); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2848 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2849 | chunk_appendf(&trash, "'"); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2850 | } |
| 2851 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2852 | chunk_appendf(&trash, "\""); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2853 | } |
| 2854 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2855 | chunk_appendf(&trash, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2856 | ">%s<a name=\"%s/%s\"></a>" |
| 2857 | "<a class=lfsb href=\"#%s/%s\">%s</a>%s</td>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 2858 | /* queue : current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2859 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 2860 | /* sessions rate : current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2861 | "<td>%s</td><td>%s</td><td></td>" |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2862 | /* sessions: current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2863 | "<td>%s</td><td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2864 | "<td" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2865 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2866 | (uri->flags & ST_SHLGNDS)?"<u>":"", |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2867 | px->id, sv->id, px->id, sv->id, sv->id, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2868 | (uri->flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 2869 | U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"), |
| 2870 | U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max), |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2871 | U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-")); |
| 2872 | |
| 2873 | /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2874 | if (px->mode == PR_MODE_HTTP) { |
| 2875 | int i; |
| 2876 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2877 | chunk_appendf(&trash, " title=\"rsp codes:"); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2878 | |
| 2879 | for (i = 1; i < 6; i++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2880 | chunk_appendf(&trash, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2881 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2882 | chunk_appendf(&trash, " other=%lld\"", sv->counters.p.http.rsp[0]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2883 | } |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2884 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2885 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2886 | /* sessions: total, lbtot */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2887 | ">%s%s%s</td><td>%s</td>", |
| 2888 | (px->mode == PR_MODE_HTTP)?"<u>":"", |
| 2889 | U2H0(sv->counters.cum_sess), |
| 2890 | (px->mode == PR_MODE_HTTP)?"</u>":"", |
| 2891 | U2H1(sv->counters.cum_lbconn)); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2892 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2893 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2894 | /* bytes : in, out */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2895 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2896 | /* denied: req, resp */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2897 | "<td></td><td>%s</td>" |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2898 | /* errors : request, connect */ |
| 2899 | "<td></td><td>%s</td>" |
| 2900 | /* errors : response */ |
Willy Tarreau | 6a8573e | 2010-03-05 18:15:23 +0100 | [diff] [blame] | 2901 | "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 2902 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2903 | "<td>%lld</td><td>%lld</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2904 | "", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2905 | U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out), |
| 2906 | U2H2(sv->counters.failed_secu), |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2907 | U2H3(sv->counters.failed_conns), |
Willy Tarreau | 6a8573e | 2010-03-05 18:15:23 +0100 | [diff] [blame] | 2908 | sv->counters.cli_aborts, |
| 2909 | sv->counters.srv_aborts, |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2910 | U2H6(sv->counters.failed_resp), |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2911 | sv->counters.retries, sv->counters.redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2912 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2913 | /* status, lest check */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2914 | chunk_appendf(&trash, "<td class=ac>"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2915 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2916 | if (sv->state & SRV_MAINTAIN) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2917 | chunk_appendf(&trash, "%s ", |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2918 | human_time(now.tv_sec - sv->last_change, 1)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2919 | chunk_appendf(&trash, "MAINT"); |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2920 | } |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2921 | else if (svs != sv && svs->state & SRV_MAINTAIN) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2922 | chunk_appendf(&trash, "%s ", |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2923 | human_time(now.tv_sec - svs->last_change, 1)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2924 | chunk_appendf(&trash, "MAINT(via)"); |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2925 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2926 | else if (svs->state & SRV_CHECKED) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2927 | chunk_appendf(&trash, "%s ", |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2928 | human_time(now.tv_sec - svs->last_change, 1)); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2929 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2930 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2931 | srv_hlt_st[sv_state], |
| 2932 | (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), |
| 2933 | (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2934 | } |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 2935 | |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2936 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2937 | chunk_appendf(&trash, "</td><td class=ac title=\"%s", |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 2938 | get_check_status_description(sv->check.status)); |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 2939 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 2940 | if (*sv->check.desc) { |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 2941 | struct chunk src; |
| 2942 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2943 | chunk_appendf(&trash, ": "); |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 2944 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 2945 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2946 | chunk_htmlencode(&trash, &src); |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 2947 | } |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2948 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2949 | chunk_appendf(&trash, "\"><u> %s%s", |
Willy Tarreau | 0eb2bed | 2012-11-24 00:20:24 +0100 | [diff] [blame] | 2950 | (sv->state & SRV_CHK_RUNNING) ? "* " : "", |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 2951 | get_check_status_info(sv->check.status)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2952 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 2953 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2954 | chunk_appendf(&trash, "/%d", sv->check.code); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2955 | |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 2956 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2957 | chunk_appendf(&trash, " in %lums</u>", sv->check.duration); |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2958 | } else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2959 | chunk_appendf(&trash, "</td><td>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2960 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2961 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2962 | /* weight */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2963 | "</td><td class=ac>%d</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2964 | /* act, bck */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2965 | "<td class=ac>%s</td><td class=ac>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2966 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 2967 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2968 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2969 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2970 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2971 | /* check failures: unique, fatal, down time */ |
Krzysztof Piotr Oledzki | 748196e | 2010-01-04 00:48:43 +0100 | [diff] [blame] | 2972 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2973 | chunk_appendf(&trash, "<td title=\"Failed Health Checks%s\"><u>%lld", |
Krzysztof Piotr Oledzki | 748196e | 2010-01-04 00:48:43 +0100 | [diff] [blame] | 2974 | svs->observe?"/Health Analyses":"", svs->counters.failed_checks); |
| 2975 | |
| 2976 | if (svs->observe) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2977 | chunk_appendf(&trash, "/%lld", svs->counters.failed_hana); |
Krzysztof Piotr Oledzki | 748196e | 2010-01-04 00:48:43 +0100 | [diff] [blame] | 2978 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2979 | chunk_appendf(&trash, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2980 | "</u></td>" |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2981 | "<td>%lld</td><td>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2982 | "", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2983 | svs->counters.down_trans, human_time(srv_downtime(sv), 1)); |
Krzysztof Piotr Oledzki | 748196e | 2010-01-04 00:48:43 +0100 | [diff] [blame] | 2984 | } else if (sv != svs) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2985 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | 88a14af | 2010-01-05 18:33:01 +0100 | [diff] [blame] | 2986 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2987 | svs->proxy->id, svs->id, svs->proxy->id, svs->id); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2988 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2989 | chunk_appendf(&trash, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2990 | "<td colspan=3></td>"); |
| 2991 | |
| 2992 | /* throttle */ |
| 2993 | if ((sv->state & SRV_WARMINGUP) && |
| 2994 | now.tv_sec < sv->last_change + sv->slowstart && |
| 2995 | now.tv_sec >= sv->last_change) { |
| 2996 | unsigned int ratio; |
| 2997 | ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2998 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2999 | "<td class=ac>%d %%</td></tr>\n", ratio); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3000 | } else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3001 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 3002 | "<td class=ac>-</td></tr>\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3003 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3004 | } else { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3005 | static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,", |
| 3006 | "UP %d/%d,", "UP,", |
| 3007 | "NOLB %d/%d,", "NOLB,", |
| 3008 | "no check," }; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3009 | chunk_appendf(&trash, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3010 | /* pxid, name */ |
| 3011 | "%s,%s," |
| 3012 | /* queue : current, max */ |
| 3013 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 3014 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 3015 | "%d,%d,%s,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3016 | /* bytes : in, out */ |
| 3017 | "%lld,%lld," |
| 3018 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 3019 | ",%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3020 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 3021 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 3022 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 3023 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3024 | "", |
| 3025 | px->id, sv->id, |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 3026 | sv->nbpend, sv->counters.nbpend_max, |
| 3027 | sv->cur_sess, sv->counters.cur_sess_max, LIM2A0(sv->maxconn, ""), sv->counters.cum_sess, |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 3028 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3029 | sv->counters.failed_secu, |
| 3030 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3031 | sv->counters.retries, sv->counters.redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3032 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3033 | /* status */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 3034 | if (sv->state & SRV_MAINTAIN) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3035 | chunk_appendf(&trash, "MAINT,"); |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 3036 | } |
| 3037 | else if (svs != sv && svs->state & SRV_MAINTAIN) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3038 | chunk_appendf(&trash, "MAINT(via),"); |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 3039 | } |
| 3040 | else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3041 | chunk_appendf(&trash, |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 3042 | srv_hlt_st[sv_state], |
| 3043 | (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), |
| 3044 | (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); |
| 3045 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3046 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3047 | chunk_appendf(&trash, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3048 | /* weight, active, backup */ |
| 3049 | "%d,%d,%d," |
| 3050 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 3051 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3052 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 3053 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 3054 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 3055 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3056 | if (sv->state & SRV_CHECKED) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3057 | chunk_appendf(&trash, |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 3058 | "%lld,%lld,%d,%d,", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 3059 | sv->counters.failed_checks, sv->counters.down_trans, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 3060 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3061 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3062 | chunk_appendf(&trash, |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3063 | ",,,,"); |
| 3064 | |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3065 | /* queue limit, pid, iid, sid, */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3066 | chunk_appendf(&trash, |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 3067 | "%s," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3068 | "%d,%d,%d,", |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 3069 | LIM2A0(sv->maxqueue, ""), |
| 3070 | relative_pid, px->uuid, sv->puid); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3071 | |
| 3072 | /* throttle */ |
| 3073 | if ((sv->state & SRV_WARMINGUP) && |
| 3074 | now.tv_sec < sv->last_change + sv->slowstart && |
| 3075 | now.tv_sec >= sv->last_change) { |
| 3076 | unsigned int ratio; |
| 3077 | ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3078 | chunk_appendf(&trash, "%d", ratio); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3079 | } |
| 3080 | |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 3081 | /* sessions: lbtot */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3082 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3083 | |
| 3084 | /* tracked */ |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3085 | if (sv->track) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3086 | chunk_appendf(&trash, "%s/%s,", |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 3087 | sv->track->proxy->id, sv->track->id); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3088 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3089 | chunk_appendf(&trash, ","); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 3090 | |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3091 | /* type */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3092 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3093 | |
| 3094 | /* rate */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3095 | chunk_appendf(&trash, "%u,,%u,", |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 3096 | read_freq_ctr(&sv->sess_per_sec), |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 3097 | sv->counters.sps_max); |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3098 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3099 | if (sv->state & SRV_CHECKED) { |
| 3100 | /* check_status */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3101 | chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3102 | |
| 3103 | /* check_code */ |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 3104 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3105 | chunk_appendf(&trash, "%u,", sv->check.code); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3106 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3107 | chunk_appendf(&trash, ","); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3108 | |
| 3109 | /* check_duration */ |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 3110 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3111 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3112 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3113 | chunk_appendf(&trash, ","); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3114 | |
| 3115 | } else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3116 | chunk_appendf(&trash, ",,,"); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3117 | } |
| 3118 | |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3119 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3120 | if (px->mode == PR_MODE_HTTP) { |
| 3121 | int i; |
| 3122 | |
| 3123 | for (i=1; i<6; i++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3124 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3125 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3126 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3127 | } else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3128 | chunk_appendf(&trash, ",,,,,,"); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3129 | } |
| 3130 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3131 | /* failed health analyses */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3132 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3133 | |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3134 | /* requests : req_rate, req_rate_max, req_tot, */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3135 | chunk_appendf(&trash, ",,,"); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3136 | |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3137 | /* errors: cli_aborts, srv_aborts */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3138 | chunk_appendf(&trash, "%lld,%lld,", |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3139 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3140 | |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3141 | /* compression: in, out, bypassed, comp_rsp */ |
| 3142 | chunk_appendf(&trash, ",,,,"); |
| 3143 | |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 3144 | /* finish with EOL */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3145 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3146 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3147 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3148 | return 0; |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3149 | } /* for sv */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3150 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3151 | si->applet.ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3152 | /* fall through */ |
| 3153 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3154 | case STAT_PX_ST_BE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3155 | /* print the backend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 3156 | if ((px->cap & PR_CAP_BE) && |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3157 | (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_BE)))) { |
| 3158 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3159 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3160 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3161 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3162 | chunk_appendf(&trash, "<td></td>"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3163 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3164 | chunk_appendf(&trash, "<td class=ac"); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3165 | |
| 3166 | if (uri->flags&ST_SHLGNDS) { |
| 3167 | /* balancing */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3168 | chunk_appendf(&trash, " title=\"balancing: %s", |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3169 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
Krzysztof Piotr Oledzki | c0f0c86 | 2010-01-06 15:03:18 +0100 | [diff] [blame] | 3170 | |
| 3171 | /* cookie */ |
| 3172 | if (px->cookie_name) { |
| 3173 | struct chunk src; |
| 3174 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3175 | chunk_appendf(&trash, ", cookie: '"); |
Krzysztof Piotr Oledzki | c0f0c86 | 2010-01-06 15:03:18 +0100 | [diff] [blame] | 3176 | |
| 3177 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3178 | chunk_htmlencode(&trash, &src); |
Krzysztof Piotr Oledzki | c0f0c86 | 2010-01-06 15:03:18 +0100 | [diff] [blame] | 3179 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3180 | chunk_appendf(&trash, "'"); |
Krzysztof Piotr Oledzki | c0f0c86 | 2010-01-06 15:03:18 +0100 | [diff] [blame] | 3181 | } |
| 3182 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3183 | chunk_appendf(&trash, "\""); |
Krzysztof Piotr Oledzki | c0f0c86 | 2010-01-06 15:03:18 +0100 | [diff] [blame] | 3184 | |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 3185 | } |
| 3186 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3187 | chunk_appendf(&trash, |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3188 | /* name */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 3189 | ">%s<a name=\"%s/Backend\"></a>" |
| 3190 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3191 | /* queue : current, max */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 3192 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 3193 | /* sessions rate : current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 3194 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 3195 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 3196 | (uri->flags & ST_SHLGNDS)?"<u>":"", |
Krzysztof Piotr Oledzki | 1f67285 | 2009-10-24 14:24:30 +0200 | [diff] [blame] | 3197 | px->id, px->id, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 3198 | (uri->flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 3199 | U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->be_counters.nbpend_max), |
| 3200 | U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->be_counters.sps_max)); |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 3201 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3202 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3203 | /* sessions: current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 3204 | "<td>%s</td><td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3205 | "<td" |
| 3206 | "", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 3207 | U2H2(px->beconn), U2H3(px->be_counters.conn_max), U2H4(px->fullconn)); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3208 | |
| 3209 | /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3210 | if (px->mode == PR_MODE_HTTP) { |
| 3211 | int i; |
| 3212 | |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3213 | chunk_appendf(&trash, " title=\"%lld requests:", px->be_counters.p.http.cum_req); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3214 | |
| 3215 | for (i = 1; i < 6; i++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3216 | chunk_appendf(&trash, " %dxx=%lld", i, px->be_counters.p.http.rsp[i]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3217 | |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3218 | chunk_appendf(&trash, " other=%lld ", px->be_counters.p.http.rsp[0]); |
| 3219 | chunk_appendf(&trash, " compressed=%lld (%d%%)\"", |
| 3220 | px->be_counters.p.http.comp_rsp, |
| 3221 | px->be_counters.p.http.cum_req ? |
Willy Tarreau | 5730c68 | 2012-11-26 14:13:09 +0100 | [diff] [blame] | 3222 | (int)(100*px->be_counters.p.http.comp_rsp/px->be_counters.p.http.rsp[2]) : 0); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3223 | } |
| 3224 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3225 | chunk_appendf(&trash, |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3226 | /* sessions: total, lbtot */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 3227 | ">%s%s%s</td><td>%s</td>" |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3228 | /* bytes: in */ |
| 3229 | "<td>%s</td><td" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 3230 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 3231 | (px->mode == PR_MODE_HTTP)?"<u>":"", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 3232 | U2H6(px->be_counters.cum_conn), |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 3233 | (px->mode == PR_MODE_HTTP)?"</u>":"", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 3234 | U2H7(px->be_counters.cum_lbconn), |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3235 | U2H8(px->be_counters.bytes_in)); |
| 3236 | |
| 3237 | /* compression stats (via td title): comp_in, comp_out, comp_byp */ |
Willy Tarreau | f149d8f | 2012-11-24 14:06:49 +0100 | [diff] [blame] | 3238 | chunk_appendf(&trash, " title=\"compression: in=%lld out=%lld bypassed=%lld savings=%d%%\"", |
| 3239 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp, |
| 3240 | px->be_counters.comp_in ? |
| 3241 | (int)((px->be_counters.comp_in - px->be_counters.comp_out)*100/px->be_counters.comp_in) : 0); |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 3242 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3243 | chunk_appendf(&trash, |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3244 | /* bytes: out */ |
| 3245 | ">%s%s%s</td>" |
| 3246 | "", |
| 3247 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
| 3248 | U2H0(px->be_counters.bytes_out), |
| 3249 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 3250 | |
| 3251 | chunk_appendf(&trash, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3252 | /* denied: req, resp */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 3253 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3254 | /* errors : request, connect */ |
| 3255 | "<td></td><td>%s</td>" |
| 3256 | /* errors : response */ |
Willy Tarreau | 6a8573e | 2010-03-05 18:15:23 +0100 | [diff] [blame] | 3257 | "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 3258 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 3259 | "<td>%lld</td><td>%lld</td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 3260 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3261 | * if the backend has known working servers or if it has no server at |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 3262 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3263 | * active and backups. */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 3264 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3265 | "<td class=ac>%d</td><td class=ac>%d</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 3266 | "", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 3267 | U2H0(px->be_counters.denied_req), U2H1(px->be_counters.denied_resp), |
| 3268 | U2H2(px->be_counters.failed_conns), |
| 3269 | px->be_counters.cli_aborts, |
| 3270 | px->be_counters.srv_aborts, |
| 3271 | U2H5(px->be_counters.failed_resp), |
| 3272 | px->be_counters.retries, px->be_counters.redispatches, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 3273 | human_time(now.tv_sec - px->last_change, 1), |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 3274 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 3275 | "<font color=\"red\"><b>DOWN</b></font>", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 3276 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 3277 | px->srv_act, px->srv_bck); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 3278 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3279 | chunk_appendf(&trash, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3280 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 3281 | "<td class=ac> </td><td>%d</td>" |
| 3282 | "<td>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3283 | "<td></td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 3284 | "</tr>", |
| 3285 | px->down_trans, |
| 3286 | px->srv?human_time(be_downtime(px), 1):" "); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3287 | } else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3288 | chunk_appendf(&trash, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3289 | /* pxid, name */ |
| 3290 | "%s,BACKEND," |
| 3291 | /* queue : current, max */ |
| 3292 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 3293 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 3294 | "%d,%d,%d,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3295 | /* bytes : in, out */ |
| 3296 | "%lld,%lld," |
| 3297 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 3298 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3299 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 3300 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 3301 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 3302 | "%lld,%lld," |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 3303 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3304 | * if the backend has known working servers or if it has no server at |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 3305 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3306 | * active and backups. */ |
| 3307 | "%s," |
| 3308 | "%d,%d,%d," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 3309 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 3310 | ",%d,%d,%d,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 3311 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 3312 | "%d,%d,0,,%lld,,%d," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 3313 | /* rate, rate_lim, rate_max, */ |
| 3314 | "%u,,%u," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 3315 | /* check_status, check_code, check_duration */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3316 | ",,,", |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3317 | px->id, |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 3318 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 3319 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 3320 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 3321 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 3322 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 3323 | px->be_counters.retries, px->be_counters.redispatches, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 3324 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 3325 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 3326 | px->srv_act, px->srv_bck, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 3327 | px->down_trans, (int)(now.tv_sec - px->last_change), |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 3328 | px->srv?be_downtime(px):0, |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 3329 | relative_pid, px->uuid, |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 3330 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 3331 | read_freq_ctr(&px->be_sess_per_sec), |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 3332 | px->be_counters.sps_max); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3333 | |
| 3334 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3335 | if (px->mode == PR_MODE_HTTP) { |
| 3336 | int i; |
| 3337 | |
| 3338 | for (i=1; i<6; i++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3339 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3340 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3341 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3342 | } else { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3343 | chunk_appendf(&trash, ",,,,,,"); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3344 | } |
| 3345 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3346 | /* failed health analyses */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3347 | chunk_appendf(&trash, ","); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 3348 | |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3349 | /* requests : req_rate, req_rate_max, req_tot, */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3350 | chunk_appendf(&trash, ",,,"); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 3351 | |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3352 | /* errors: cli_aborts, srv_aborts */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3353 | chunk_appendf(&trash, "%lld,%lld,", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 3354 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 3355 | |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 3356 | /* compression: in, out, bypassed */ |
| 3357 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3358 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 3359 | |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 3360 | /* compression: comp_rsp */ |
| 3361 | chunk_appendf(&trash, "%lld,", |
| 3362 | px->be_counters.p.http.comp_rsp); |
| 3363 | |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3364 | /* finish with EOL */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3365 | chunk_appendf(&trash, "\n"); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 3366 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3367 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3368 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3369 | return 0; |
| 3370 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3371 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3372 | si->applet.ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3373 | /* fall through */ |
| 3374 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3375 | case STAT_PX_ST_END: |
| 3376 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3377 | chunk_appendf(&trash, "</table>"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3378 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3379 | if (px->cap & PR_CAP_BE && px->srv && (si->applet.ctx.stats.flags & STAT_ADMIN)) { |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3380 | /* close the form used to enable/disable this proxy servers */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3381 | chunk_appendf(&trash, |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3382 | "Choose the action to perform on the checked servers : " |
| 3383 | "<select name=action>" |
| 3384 | "<option value=\"\"></option>" |
| 3385 | "<option value=\"disable\">Disable</option>" |
| 3386 | "<option value=\"enable\">Enable</option>" |
Willy Tarreau | d728224 | 2012-06-04 00:22:44 +0200 | [diff] [blame] | 3387 | "<option value=\"stop\">Soft Stop</option>" |
| 3388 | "<option value=\"start\">Soft Start</option>" |
Willy Tarreau | 4f8a83c | 2012-06-04 00:26:23 +0200 | [diff] [blame] | 3389 | "<option value=\"shutdown\">Kill Sessions</option>" |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3390 | "</select>" |
Cyril Bonté | aa0a45d | 2012-04-04 12:57:20 +0200 | [diff] [blame] | 3391 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3392 | " <input type=\"submit\" value=\"Apply\">" |
| 3393 | "</form>", |
Cyril Bonté | aa0a45d | 2012-04-04 12:57:20 +0200 | [diff] [blame] | 3394 | px->uuid); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3395 | } |
| 3396 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3397 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3398 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3399 | if (bi_putchk(rep, &trash) == -1) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3400 | return 0; |
| 3401 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3402 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3403 | si->applet.ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3404 | /* fall through */ |
| 3405 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3406 | case STAT_PX_ST_FIN: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3407 | return 1; |
| 3408 | |
| 3409 | default: |
| 3410 | /* unknown state, we should put an abort() here ! */ |
| 3411 | return 1; |
| 3412 | } |
| 3413 | } |
| 3414 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3415 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 3416 | { |
| 3417 | if (!conn->ctrl) |
| 3418 | return "NONE"; |
| 3419 | return conn->ctrl->name; |
| 3420 | } |
| 3421 | |
| 3422 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 3423 | { |
| 3424 | static char ptr[17]; |
| 3425 | |
| 3426 | if (!conn->xprt) |
| 3427 | return "NONE"; |
| 3428 | |
| 3429 | if (conn->xprt == &raw_sock) |
| 3430 | return "RAW"; |
| 3431 | |
| 3432 | #ifdef USE_OPENSSL |
| 3433 | if (conn->xprt == &ssl_sock) |
| 3434 | return "SSL"; |
| 3435 | #endif |
| 3436 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 3437 | return ptr; |
| 3438 | } |
| 3439 | |
| 3440 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 3441 | { |
| 3442 | static char ptr[17]; |
| 3443 | |
| 3444 | if (!conn->data) |
| 3445 | return "NONE"; |
| 3446 | |
| 3447 | if (conn->data == &sess_conn_cb) |
| 3448 | return "SESS"; |
| 3449 | |
| 3450 | if (conn->data == &si_conn_cb) |
| 3451 | return "STRM"; |
| 3452 | |
| 3453 | if (conn->data == &check_conn_cb) |
| 3454 | return "CHCK"; |
| 3455 | |
| 3456 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 3457 | return ptr; |
| 3458 | } |
| 3459 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 3460 | /* This function dumps a complete session state onto the stream interface's |
| 3461 | * read buffer. The xprt_ctx must have been zeroed first, and the flags |
| 3462 | * 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] | 3463 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 3464 | * 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] | 3465 | */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3466 | 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] | 3467 | { |
| 3468 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3469 | extern const char *monthname[12]; |
| 3470 | char pn[INET6_ADDRSTRLEN]; |
| 3471 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3472 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3473 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3474 | 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] | 3475 | /* session changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3476 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
| 3477 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3478 | return 0; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3479 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3480 | si->applet.ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3481 | return 1; |
| 3482 | } |
| 3483 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3484 | switch (si->applet.ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3485 | case 0: /* main status of the session */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3486 | si->applet.ctx.sess.uid = sess->uniq_id; |
| 3487 | si->applet.ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3488 | /* fall through */ |
| 3489 | |
| 3490 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3491 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3492 | "%p: id=%u, proto=%s", |
| 3493 | sess, |
| 3494 | sess->uniq_id, |
| 3495 | sess->listener->proto->name); |
| 3496 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3497 | 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] | 3498 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3499 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3500 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3501 | pn, get_host_port(&sess->si[0].conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3502 | break; |
| 3503 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3504 | chunk_appendf(&trash, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3505 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3506 | default: |
| 3507 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3508 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3509 | break; |
| 3510 | } |
| 3511 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3512 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3513 | " 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] | 3514 | 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] | 3515 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3516 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3517 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3518 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 3519 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 3520 | sess->listener ? sess->listener->luid : 0); |
| 3521 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3522 | conn_get_to_addr(sess->si[0].conn); |
| 3523 | 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] | 3524 | case AF_INET: |
| 3525 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3526 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3527 | pn, get_host_port(&sess->si[0].conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3528 | break; |
| 3529 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3530 | chunk_appendf(&trash, " addr=unix:%d\n", sess->listener->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3531 | break; |
| 3532 | default: |
| 3533 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3534 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3535 | break; |
| 3536 | } |
| 3537 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3538 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3539 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3540 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3541 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3542 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 3543 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3544 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3545 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3546 | conn_get_from_addr(sess->si[1].conn); |
| 3547 | 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] | 3548 | case AF_INET: |
| 3549 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3550 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3551 | pn, get_host_port(&sess->si[1].conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3552 | break; |
| 3553 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3554 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3555 | break; |
| 3556 | default: |
| 3557 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3558 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3559 | break; |
| 3560 | } |
| 3561 | |
| 3562 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3563 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3564 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 3565 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 3566 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3567 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3568 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3569 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3570 | conn_get_to_addr(sess->si[1].conn); |
| 3571 | 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] | 3572 | case AF_INET: |
| 3573 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3574 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3575 | pn, get_host_port(&sess->si[1].conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3576 | break; |
| 3577 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3578 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3579 | break; |
| 3580 | default: |
| 3581 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3582 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 3583 | break; |
| 3584 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3585 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3586 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3587 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s)\n", |
| 3588 | sess->task, |
| 3589 | sess->task->state, |
| 3590 | sess->task->nice, sess->task->calls, |
| 3591 | sess->task->expire ? |
| 3592 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 3593 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 3594 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3595 | task_in_rq(sess->task) ? ", running" : ""); |
| 3596 | |
| 3597 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3598 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3599 | " task created [%02d/%s/%04d:%02d:%02d:%02d.%06d] (age=%s)\n", |
| 3600 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 3601 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec), |
| 3602 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 3603 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3604 | chunk_appendf(&trash, |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3605 | " si[0]=%p (state=%d flags=0x%02x conn=%p exp=%s, et=0x%03x)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3606 | &sess->si[0], |
| 3607 | sess->si[0].state, |
| 3608 | sess->si[0].flags, |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3609 | sess->si[0].conn, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3610 | sess->si[0].exp ? |
| 3611 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 3612 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 3613 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3614 | sess->si[0].err_type); |
| 3615 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3616 | chunk_appendf(&trash, |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3617 | " si[1]=%p (state=%d flags=0x%02x conn=%p exp=%s, et=0x%03x)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3618 | &sess->si[1], |
| 3619 | sess->si[1].state, |
| 3620 | sess->si[1].flags, |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3621 | sess->si[1].conn, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3622 | sess->si[1].exp ? |
| 3623 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 3624 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 3625 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3626 | sess->si[1].err_type); |
| 3627 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3628 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3629 | " lconn=%p ctrl=%s xprt=%s data=%s\n", |
| 3630 | sess->si[0].conn, |
| 3631 | get_conn_ctrl_name(sess->si[0].conn), |
| 3632 | get_conn_xprt_name(sess->si[0].conn), |
| 3633 | get_conn_data_name(sess->si[0].conn)); |
| 3634 | |
| 3635 | chunk_appendf(&trash, |
| 3636 | " target=%d flags=0x%08x fd=%d fd_spec=%02x\n", |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3637 | sess->si[0].conn->target ? *sess->si[0].conn->target : 0, |
Willy Tarreau | 1feca01 | 2012-11-19 18:15:19 +0100 | [diff] [blame] | 3638 | sess->si[0].conn->flags, |
| 3639 | sess->si[0].conn->t.sock.fd, |
| 3640 | sess->si[0].conn->t.sock.fd >= 0 ? fdtab[sess->si[0].conn->t.sock.fd].spec_e : 0); |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3641 | |
| 3642 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3643 | " rconn=%p ctrl=%s xprt=%s data=%s\n", |
| 3644 | sess->si[1].conn, |
| 3645 | get_conn_ctrl_name(sess->si[1].conn), |
| 3646 | get_conn_xprt_name(sess->si[1].conn), |
| 3647 | get_conn_data_name(sess->si[1].conn)); |
| 3648 | |
| 3649 | chunk_appendf(&trash, |
| 3650 | " target=%d flags=0x%08x fd=%d fd_spec=%02x\n", |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3651 | sess->si[1].conn->target ? *sess->si[1].conn->target : 0, |
Willy Tarreau | 1feca01 | 2012-11-19 18:15:19 +0100 | [diff] [blame] | 3652 | sess->si[1].conn->flags, |
| 3653 | sess->si[1].conn->t.sock.fd, |
| 3654 | sess->si[1].conn->t.sock.fd >= 0 ? fdtab[sess->si[1].conn->t.sock.fd].spec_e : 0); |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 3655 | |
| 3656 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3657 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3658 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 3659 | http_msg_state_str(sess->txn.req.msg_state), http_msg_state_str(sess->txn.rsp.msg_state)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3660 | |
| 3661 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3662 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3663 | " 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] | 3664 | " an_exp=%s", |
| 3665 | sess->req, |
| 3666 | sess->req->flags, sess->req->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3667 | sess->req->pipe ? sess->req->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3668 | sess->req->to_forward, sess->req->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3669 | sess->req->analyse_exp ? |
| 3670 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 3671 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3672 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3673 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3674 | " rex=%s", |
| 3675 | sess->req->rex ? |
| 3676 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 3677 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3678 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3679 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3680 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3681 | " 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] | 3682 | sess->req->wex ? |
| 3683 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 3684 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3685 | sess->req->buf, |
| 3686 | sess->req->buf->data, sess->req->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3687 | (int)(sess->req->buf->p - sess->req->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3688 | sess->txn.req.next, sess->req->buf->i, |
| 3689 | sess->req->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3690 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3691 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3692 | " 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] | 3693 | " an_exp=%s", |
| 3694 | sess->rep, |
| 3695 | sess->rep->flags, sess->rep->analysers, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3696 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3697 | sess->rep->to_forward, sess->rep->total, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3698 | sess->rep->analyse_exp ? |
| 3699 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 3700 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3701 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3702 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3703 | " rex=%s", |
| 3704 | sess->rep->rex ? |
| 3705 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 3706 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3707 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3708 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3709 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3710 | " 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] | 3711 | sess->rep->wex ? |
| 3712 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 3713 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3714 | sess->rep->buf, |
| 3715 | sess->rep->buf->data, sess->rep->buf->o, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3716 | (int)(sess->rep->buf->p - sess->rep->buf->data), |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 3717 | sess->txn.rsp.next, sess->rep->buf->i, |
| 3718 | sess->rep->buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3719 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3720 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3721 | return 0; |
| 3722 | |
| 3723 | /* use other states to dump the contents */ |
| 3724 | } |
| 3725 | /* end of dump */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3726 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3727 | si->applet.ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3728 | return 1; |
| 3729 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3730 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 3731 | /* This function dumps all sessions' states onto the stream interface's |
| 3732 | * 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] | 3733 | * properly set. It returns 0 if the output buffer is full and it needs |
| 3734 | * to be called again, otherwise non-zero. It is designed to be called |
| 3735 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3736 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 3737 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3738 | { |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 3739 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3740 | /* If we're forced to shut down, we might have to remove our |
| 3741 | * reference to the last session being dumped. |
| 3742 | */ |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3743 | if (si->conn->xprt_st == STAT_ST_LIST) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3744 | if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) { |
| 3745 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3746 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3747 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3748 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 3749 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3750 | } |
| 3751 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3752 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3753 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3754 | switch (si->conn->xprt_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3755 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3756 | /* the function had not been called yet, let's prepare the |
| 3757 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3758 | * pointer to the first in the global list. When a target |
| 3759 | * session is being destroyed, it is responsible for updating |
| 3760 | * this pointer. We know we have reached the end when this |
| 3761 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3762 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3763 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
| 3764 | si->applet.ctx.sess.bref.ref = sessions.n; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3765 | si->conn->xprt_st = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3766 | /* fall through */ |
| 3767 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3768 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3769 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3770 | if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) { |
| 3771 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3772 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | /* and start from where we stopped */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3776 | while (si->applet.ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 3777 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3778 | struct session *curr_sess; |
| 3779 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3780 | 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] | 3781 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3782 | if (si->applet.ctx.sess.target) { |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3783 | 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] | 3784 | goto next_sess; |
| 3785 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3786 | LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3787 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3788 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3789 | return 0; |
| 3790 | |
| 3791 | /* session dump complete */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3792 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3793 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3794 | if (si->applet.ctx.sess.target != (void *)-1) { |
| 3795 | si->applet.ctx.sess.target = NULL; |
| 3796 | break; |
| 3797 | } |
| 3798 | else |
| 3799 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3800 | } |
| 3801 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3802 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3803 | "%p: proto=%s", |
| 3804 | curr_sess, |
| 3805 | curr_sess->listener->proto->name); |
| 3806 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3807 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3808 | 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] | 3809 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3810 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3811 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3812 | " src=%s:%d fe=%s be=%s srv=%s", |
| 3813 | pn, |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3814 | get_host_port(&curr_sess->si[0].conn->addr.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3815 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3816 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 3817 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3818 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3819 | break; |
| 3820 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3821 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3822 | " src=unix:%d fe=%s be=%s srv=%s", |
| 3823 | curr_sess->listener->luid, |
| 3824 | curr_sess->fe->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 3825 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 3826 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3827 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3828 | break; |
| 3829 | } |
| 3830 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3831 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 3832 | " ts=%02x age=%s calls=%d", |
| 3833 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 3834 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 3835 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3836 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3837 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 3838 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3839 | curr_sess->req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3840 | curr_sess->req->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3841 | curr_sess->req->analysers, |
| 3842 | curr_sess->req->rex ? |
| 3843 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 3844 | TICKS_TO_MS(1000)) : ""); |
| 3845 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3846 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3847 | ",wx=%s", |
| 3848 | curr_sess->req->wex ? |
| 3849 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 3850 | TICKS_TO_MS(1000)) : ""); |
| 3851 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3852 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3853 | ",ax=%s]", |
| 3854 | curr_sess->req->analyse_exp ? |
| 3855 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 3856 | TICKS_TO_MS(1000)) : ""); |
| 3857 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3858 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 3859 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3860 | curr_sess->rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 3861 | curr_sess->rep->buf->i, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3862 | curr_sess->rep->analysers, |
| 3863 | curr_sess->rep->rex ? |
| 3864 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 3865 | TICKS_TO_MS(1000)) : ""); |
| 3866 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3867 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3868 | ",wx=%s", |
| 3869 | curr_sess->rep->wex ? |
| 3870 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 3871 | TICKS_TO_MS(1000)) : ""); |
| 3872 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3873 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3874 | ",ax=%s]", |
| 3875 | curr_sess->rep->analyse_exp ? |
| 3876 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 3877 | TICKS_TO_MS(1000)) : ""); |
| 3878 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3879 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3880 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 3881 | curr_sess->si[0].state, |
| 3882 | curr_sess->si[0].flags, |
Willy Tarreau | 7f7ad91 | 2012-11-11 19:27:15 +0100 | [diff] [blame] | 3883 | curr_sess->si[0].conn->t.sock.fd, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3884 | curr_sess->si[0].exp ? |
| 3885 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 3886 | TICKS_TO_MS(1000)) : ""); |
| 3887 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3888 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3889 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 3890 | curr_sess->si[1].state, |
| 3891 | curr_sess->si[1].flags, |
Willy Tarreau | 7f7ad91 | 2012-11-11 19:27:15 +0100 | [diff] [blame] | 3892 | curr_sess->si[1].conn->t.sock.fd, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3893 | curr_sess->si[1].exp ? |
| 3894 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 3895 | TICKS_TO_MS(1000)) : ""); |
| 3896 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3897 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3898 | " exp=%s", |
| 3899 | curr_sess->task->expire ? |
| 3900 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 3901 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 3902 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3903 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3904 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3905 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3906 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3907 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3908 | /* let's try again later from this session. We add ourselves into |
| 3909 | * this session's users so that it can remove us upon termination. |
| 3910 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3911 | LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 3912 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3913 | } |
| 3914 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3915 | next_sess: |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3916 | si->applet.ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3917 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3918 | |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 3919 | 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] | 3920 | /* specified session not found */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3921 | if (si->applet.ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3922 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3923 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3924 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3925 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3926 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3927 | return 0; |
| 3928 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3929 | si->applet.ctx.sess.target = NULL; |
| 3930 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3931 | return 1; |
| 3932 | } |
| 3933 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3934 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3935 | /* fall through */ |
| 3936 | |
| 3937 | default: |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3938 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 3939 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3940 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 3941 | } |
| 3942 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 3943 | /* This is called when the stream interface is closed. For instance, upon an |
| 3944 | * external abort, we won't call the i/o handler anymore so we may need to |
| 3945 | * remove back references to the session currently being dumped. |
| 3946 | */ |
| 3947 | void cli_release_handler(struct stream_interface *si) |
| 3948 | { |
| 3949 | if (si->applet.st0 == STAT_CLI_O_SESS && si->conn->xprt_st == STAT_ST_LIST) { |
| 3950 | if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) |
| 3951 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3952 | } |
| 3953 | } |
| 3954 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 3955 | /* This function dumps all tables' states onto the stream interface's |
| 3956 | * 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] | 3957 | * properly set. It returns 0 if the output buffer is full and it needs |
| 3958 | * to be called again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3959 | */ |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 3960 | static int stats_table_request(struct stream_interface *si, bool show) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3961 | { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3962 | struct session *s = si->conn->xprt_ctx; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3963 | struct ebmb_node *eb; |
| 3964 | int dt; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 3965 | bool skip_entry; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3966 | |
| 3967 | /* |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3968 | * We have 3 possible states in si->conn->xprt_st : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3969 | * - STAT_ST_INIT : the first call |
| 3970 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3971 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3972 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3973 | * and the entry pointer points to the next entry to be dumped, |
| 3974 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3975 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3976 | * data though. |
| 3977 | */ |
| 3978 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 3979 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3980 | /* 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] | 3981 | if (si->conn->xprt_st == STAT_ST_LIST) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3982 | si->applet.ctx.table.entry->ref_cnt--; |
| 3983 | 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] | 3984 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3985 | return 1; |
| 3986 | } |
| 3987 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3988 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3989 | |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3990 | while (si->conn->xprt_st != STAT_ST_FIN) { |
| 3991 | switch (si->conn->xprt_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3992 | case STAT_ST_INIT: |
| 3993 | si->applet.ctx.table.proxy = si->applet.ctx.table.target; |
| 3994 | if (!si->applet.ctx.table.proxy) |
| 3995 | si->applet.ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3996 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3997 | si->applet.ctx.table.entry = NULL; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 3998 | si->conn->xprt_st = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3999 | break; |
| 4000 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4001 | case STAT_ST_INFO: |
| 4002 | if (!si->applet.ctx.table.proxy || |
| 4003 | (si->applet.ctx.table.target && |
| 4004 | si->applet.ctx.table.proxy != si->applet.ctx.table.target)) { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4005 | si->conn->xprt_st = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4006 | break; |
| 4007 | } |
| 4008 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4009 | if (si->applet.ctx.table.proxy->table.size) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4010 | 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] | 4011 | si->applet.ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4012 | return 0; |
| 4013 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4014 | if (si->applet.ctx.table.target && |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 4015 | s->listener->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4016 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4017 | eb = ebmb_first(&si->applet.ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4018 | if (eb) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4019 | si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 4020 | si->applet.ctx.table.entry->ref_cnt++; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4021 | si->conn->xprt_st = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4022 | break; |
| 4023 | } |
| 4024 | } |
| 4025 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4026 | si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4027 | break; |
| 4028 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4029 | case STAT_ST_LIST: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4030 | skip_entry = false; |
| 4031 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4032 | if (si->applet.ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4033 | /* we're filtering on some data contents */ |
| 4034 | void *ptr; |
| 4035 | long long data; |
| 4036 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4037 | dt = si->applet.ctx.table.data_type; |
| 4038 | ptr = stktable_data_ptr(&si->applet.ctx.table.proxy->table, |
| 4039 | si->applet.ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4040 | dt); |
| 4041 | |
| 4042 | data = 0; |
| 4043 | switch (stktable_data_types[dt].std_type) { |
| 4044 | case STD_T_SINT: |
| 4045 | data = stktable_data_cast(ptr, std_t_sint); |
| 4046 | break; |
| 4047 | case STD_T_UINT: |
| 4048 | data = stktable_data_cast(ptr, std_t_uint); |
| 4049 | break; |
| 4050 | case STD_T_ULL: |
| 4051 | data = stktable_data_cast(ptr, std_t_ull); |
| 4052 | break; |
| 4053 | case STD_T_FRQP: |
| 4054 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4055 | si->applet.ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4056 | break; |
| 4057 | } |
| 4058 | |
| 4059 | /* 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] | 4060 | if ((data < si->applet.ctx.table.value && |
| 4061 | (si->applet.ctx.table.data_op == STD_OP_EQ || |
| 4062 | si->applet.ctx.table.data_op == STD_OP_GT || |
| 4063 | si->applet.ctx.table.data_op == STD_OP_GE)) || |
| 4064 | (data == si->applet.ctx.table.value && |
| 4065 | (si->applet.ctx.table.data_op == STD_OP_NE || |
| 4066 | si->applet.ctx.table.data_op == STD_OP_GT || |
| 4067 | si->applet.ctx.table.data_op == STD_OP_LT)) || |
| 4068 | (data > si->applet.ctx.table.value && |
| 4069 | (si->applet.ctx.table.data_op == STD_OP_EQ || |
| 4070 | si->applet.ctx.table.data_op == STD_OP_LT || |
| 4071 | si->applet.ctx.table.data_op == STD_OP_LE))) |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4072 | skip_entry = true; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 4073 | } |
| 4074 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4075 | if (show && !skip_entry && |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4076 | !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] | 4077 | si->applet.ctx.table.entry)) |
| 4078 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4079 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4080 | si->applet.ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4081 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4082 | eb = ebmb_next(&si->applet.ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4083 | if (eb) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4084 | struct stksess *old = si->applet.ctx.table.entry; |
| 4085 | si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 4086 | if (show) |
| 4087 | stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, old); |
| 4088 | else |
| 4089 | stksess_kill(&si->applet.ctx.table.proxy->table, old); |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4090 | si->applet.ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4091 | break; |
| 4092 | } |
| 4093 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 4094 | |
| 4095 | if (show) |
| 4096 | stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry); |
| 4097 | else if (!skip_entry && !si->applet.ctx.table.entry->ref_cnt) |
| 4098 | stksess_kill(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry); |
| 4099 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4100 | si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next; |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4101 | si->conn->xprt_st = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4102 | break; |
| 4103 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4104 | case STAT_ST_END: |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 4105 | si->conn->xprt_st = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 4106 | break; |
| 4107 | } |
| 4108 | } |
| 4109 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4110 | } |
| 4111 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4112 | /* 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] | 4113 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 4114 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 4115 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 4116 | * lines are respected within the limit of 70 output chars. Lines that are |
| 4117 | * continuation of a previous truncated line begin with "+" instead of " " |
| 4118 | * after the offset. The new pointer is returned. |
| 4119 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4120 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 4121 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4122 | { |
| 4123 | int end; |
| 4124 | unsigned char c; |
| 4125 | |
| 4126 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 4127 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4128 | return ptr; |
| 4129 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 4130 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4131 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4132 | while (ptr < len && ptr < bsize) { |
| 4133 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4134 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4135 | if (out->len > end - 2) |
| 4136 | break; |
| 4137 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4138 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4139 | if (out->len > end - 3) |
| 4140 | break; |
| 4141 | out->str[out->len++] = '\\'; |
| 4142 | switch (c) { |
| 4143 | case '\t': c = 't'; break; |
| 4144 | case '\n': c = 'n'; break; |
| 4145 | case '\r': c = 'r'; break; |
| 4146 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 4147 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4148 | } |
| 4149 | out->str[out->len++] = c; |
| 4150 | } else { |
| 4151 | if (out->len > end - 5) |
| 4152 | break; |
| 4153 | out->str[out->len++] = '\\'; |
| 4154 | out->str[out->len++] = 'x'; |
| 4155 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 4156 | out->str[out->len++] = hextab[c & 0xF]; |
| 4157 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 4158 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4159 | /* we had a line break, let's return now */ |
| 4160 | out->str[out->len++] = '\n'; |
| 4161 | *line = ptr; |
| 4162 | return ptr; |
| 4163 | } |
| 4164 | } |
| 4165 | /* we have an incomplete line, we return it as-is */ |
| 4166 | out->str[out->len++] = '\n'; |
| 4167 | return ptr; |
| 4168 | } |
| 4169 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 4170 | /* This function dumps all captured errors onto the stream interface's |
| 4171 | * 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] | 4172 | * properly set. It returns 0 if the output buffer is full and it needs |
| 4173 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4174 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4175 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4176 | { |
| 4177 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4178 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 4179 | if (unlikely(si->ib->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4180 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4181 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4182 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4183 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4184 | if (!si->applet.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4185 | /* the function had not been called yet, let's prepare the |
| 4186 | * buffer for a response. |
| 4187 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4188 | struct tm tm; |
| 4189 | |
| 4190 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4191 | 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] | 4192 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 4193 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 4194 | error_snapshot_id); |
| 4195 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4196 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 4197 | /* Socket buffer full. Let's try again later from the same point */ |
| 4198 | return 0; |
| 4199 | } |
| 4200 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4201 | si->applet.ctx.errors.px = proxy; |
| 4202 | si->applet.ctx.errors.buf = 0; |
| 4203 | si->applet.ctx.errors.bol = 0; |
| 4204 | si->applet.ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | /* we have two inner loops here, one for the proxy, the other one for |
| 4208 | * the buffer. |
| 4209 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4210 | while (si->applet.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4211 | struct error_snapshot *es; |
| 4212 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4213 | if (si->applet.ctx.errors.buf == 0) |
| 4214 | es = &si->applet.ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4215 | else |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4216 | es = &si->applet.ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4217 | |
| 4218 | if (!es->when.tv_sec) |
| 4219 | goto next; |
| 4220 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4221 | if (si->applet.ctx.errors.iid >= 0 && |
| 4222 | si->applet.ctx.errors.px->uuid != si->applet.ctx.errors.iid && |
| 4223 | es->oe->uuid != si->applet.ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4224 | goto next; |
| 4225 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4226 | if (si->applet.ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4227 | /* just print headers now */ |
| 4228 | |
| 4229 | char pn[INET6_ADDRSTRLEN]; |
| 4230 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4231 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4232 | |
| 4233 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4234 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4235 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 4236 | 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] | 4237 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4238 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 4239 | case AF_INET: |
| 4240 | case AF_INET6: |
| 4241 | port = get_host_port(&es->src); |
| 4242 | break; |
| 4243 | default: |
| 4244 | port = 0; |
| 4245 | } |
| 4246 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4247 | switch (si->applet.ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4248 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4249 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4250 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4251 | " backend %s (#%d)", |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4252 | si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4253 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 4254 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4255 | break; |
| 4256 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4257 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4258 | " backend %s (#%d) : invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4259 | " frontend %s (#%d)", |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4260 | si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4261 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4262 | break; |
| 4263 | } |
| 4264 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4265 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 4266 | ", server %s (#%d), event #%u\n" |
| 4267 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 4268 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 4269 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 4270 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 4271 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 4272 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 4273 | es->ev_id, |
| 4274 | pn, port, es->sid, es->s_flags, |
| 4275 | es->state, es->m_flags, es->t_flags, |
| 4276 | es->m_clen, es->m_blen, |
| 4277 | es->b_flags, es->b_out, es->b_tot, |
| 4278 | es->len, es->b_wrap, es->pos); |
| 4279 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4280 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4281 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4282 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4283 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4284 | si->applet.ctx.errors.ptr = 0; |
| 4285 | si->applet.ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4286 | } |
| 4287 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4288 | if (si->applet.ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4289 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4290 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4291 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4292 | if (bi_putchk(si->ib, &trash) == -1) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4293 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4294 | goto next; |
| 4295 | } |
| 4296 | |
| 4297 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4298 | 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] | 4299 | int newptr; |
| 4300 | int newline; |
| 4301 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4302 | newline = si->applet.ctx.errors.bol; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4303 | 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] | 4304 | if (newptr == si->applet.ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4305 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4306 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4307 | if (bi_putchk(si->ib, &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4308 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4309 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4310 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4311 | si->applet.ctx.errors.ptr = newptr; |
| 4312 | si->applet.ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4313 | }; |
| 4314 | next: |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4315 | si->applet.ctx.errors.bol = 0; |
| 4316 | si->applet.ctx.errors.ptr = -1; |
| 4317 | si->applet.ctx.errors.buf++; |
| 4318 | if (si->applet.ctx.errors.buf > 1) { |
| 4319 | si->applet.ctx.errors.buf = 0; |
| 4320 | si->applet.ctx.errors.px = si->applet.ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 4325 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 4326 | } |
| 4327 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4328 | /* parse the "level" argument on the bind lines */ |
| 4329 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 4330 | { |
| 4331 | if (!*args[cur_arg + 1]) { |
| 4332 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 4333 | return ERR_ALERT | ERR_FATAL; |
| 4334 | } |
| 4335 | |
| 4336 | if (!strcmp(args[cur_arg+1], "user")) |
| 4337 | conf->level = ACCESS_LVL_USER; |
| 4338 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 4339 | conf->level = ACCESS_LVL_OPER; |
| 4340 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 4341 | conf->level = ACCESS_LVL_ADMIN; |
| 4342 | else { |
| 4343 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 4344 | args[cur_arg], args[cur_arg+1]); |
| 4345 | return ERR_ALERT | ERR_FATAL; |
| 4346 | } |
| 4347 | |
| 4348 | return 0; |
| 4349 | } |
| 4350 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4351 | struct si_applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4352 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4353 | .name = "<STATS>", /* used for logging */ |
| 4354 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 4355 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4356 | }; |
| 4357 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 4358 | static struct si_applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 4359 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4360 | .name = "<CLI>", /* used for logging */ |
| 4361 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 4362 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 4363 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 4364 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4365 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 4366 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 4367 | { 0, NULL, NULL }, |
| 4368 | }}; |
| 4369 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4370 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 4371 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 4372 | { NULL, NULL, 0 }, |
| 4373 | }}; |
| 4374 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4375 | __attribute__((constructor)) |
| 4376 | static void __dumpstats_module_init(void) |
| 4377 | { |
| 4378 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 4379 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 4380 | } |
| 4381 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4382 | /* |
| 4383 | * Local variables: |
| 4384 | * c-indent-level: 8 |
| 4385 | * c-basic-offset: 8 |
| 4386 | * End: |
| 4387 | */ |