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