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