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