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