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