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