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