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) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 2204 | char str[INET6_ADDRSTRLEN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2205 | int port; |
| 2206 | |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 2207 | chunk_printf(&msg, " title=\""); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2208 | |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 2209 | port = get_host_port(&l->addr); |
| 2210 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 2211 | case AF_INET: |
| 2212 | chunk_printf(&msg, "IPv4: %s:%d, ", str, port); |
| 2213 | break; |
| 2214 | case AF_INET6: |
| 2215 | chunk_printf(&msg, "IPv6: [%s]:%d, ", str, port); |
| 2216 | break; |
| 2217 | case AF_UNIX: |
| 2218 | chunk_printf(&msg, "unix, "); |
| 2219 | break; |
| 2220 | case -1: |
| 2221 | chunk_printf(&msg, "(%s), ", strerror(errno)); |
| 2222 | break; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2223 | } |
| 2224 | |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2225 | /* id */ |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 2226 | chunk_printf(&msg, "id: %d\"", l->luid); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2227 | } |
| 2228 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2229 | chunk_printf(&msg, |
| 2230 | /* name, queue */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2231 | ">%s<a name=\"%s/+%s\"></a>" |
| 2232 | "<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] | 2233 | /* sessions rate: current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2234 | "<td colspan=3> </td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2235 | /* sessions: current, max, limit, total, lbtot */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2236 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 2237 | "<td>%s</td><td> </td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2238 | /* bytes: in, out */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2239 | "<td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2240 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2241 | (uri->flags & ST_SHLGNDS)?"<u>":"", |
Krzysztof Piotr Oledzki | 2ec025d | 2010-01-04 11:33:32 +0100 | [diff] [blame] | 2242 | px->id, l->name, px->id, l->name, l->name, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2243 | (uri->flags & ST_SHLGNDS)?"</u>":"", |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2244 | U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn), |
| 2245 | U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out)); |
| 2246 | |
| 2247 | chunk_printf(&msg, |
| 2248 | /* denied: req, resp */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2249 | "<td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2250 | /* errors: request, connect, response */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2251 | "<td>%s</td><td></td><td></td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2252 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2253 | "<td></td><td></td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2254 | /* server status: reflect listener status */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2255 | "<td class=ac>%s</td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2256 | /* rest of server: nothing */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2257 | "<td class=ac colspan=8></td></tr>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2258 | "", |
| 2259 | U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp), |
| 2260 | U2H2(l->counters->failed_req), |
Willy Tarreau | a17c2d9 | 2011-07-25 08:16:20 +0200 | [diff] [blame] | 2261 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2262 | } else { |
| 2263 | chunk_printf(&msg, |
| 2264 | /* pxid, name, queue cur, queue max, */ |
| 2265 | "%s,%s,,," |
| 2266 | /* sessions: current, max, limit, total */ |
| 2267 | "%d,%d,%d,%lld," |
| 2268 | /* bytes: in, out */ |
| 2269 | "%lld,%lld," |
| 2270 | /* denied: req, resp */ |
| 2271 | "%lld,%lld," |
| 2272 | /* errors: request, connect, response */ |
| 2273 | "%lld,,," |
| 2274 | /* warnings: retries, redispatches */ |
| 2275 | ",," |
| 2276 | /* server status: reflect listener status */ |
| 2277 | "%s," |
| 2278 | /* rest of server: nothing */ |
| 2279 | ",,,,,,,," |
| 2280 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 2281 | "%d,%d,%d,,,,%d," |
| 2282 | /* rate, rate_lim, rate_max */ |
| 2283 | ",,," |
| 2284 | /* check_status, check_code, check_duration */ |
| 2285 | ",,," |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2286 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2287 | ",,,,,," |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2288 | /* failed health analyses */ |
| 2289 | "," |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 2290 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2291 | ",,," |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2292 | /* errors: cli_aborts, srv_aborts */ |
| 2293 | ",," |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 2294 | "\n", |
| 2295 | px->id, l->name, |
| 2296 | l->nbconn, l->counters->conn_max, |
| 2297 | l->maxconn, l->counters->cum_conn, |
| 2298 | l->counters->bytes_in, l->counters->bytes_out, |
| 2299 | l->counters->denied_req, l->counters->denied_resp, |
| 2300 | l->counters->failed_req, |
| 2301 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 2302 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 2303 | } |
| 2304 | |
| 2305 | if (buffer_feed_chunk(rep, &msg) >= 0) |
| 2306 | return 0; |
| 2307 | } |
| 2308 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2309 | si->applet.ctx.stats.sv = px->srv; /* may be NULL */ |
| 2310 | si->applet.ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2311 | /* fall through */ |
| 2312 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2313 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2314 | /* stats.sv has been initialized above */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2315 | 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] | 2316 | 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] | 2317 | |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2318 | if (buffer_almost_full(rep)) |
| 2319 | return 0; |
| 2320 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2321 | sv = si->applet.ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2322 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2323 | if (si->applet.ctx.stats.flags & STAT_BOUND) { |
| 2324 | if (!(si->applet.ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2325 | break; |
| 2326 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2327 | 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] | 2328 | continue; |
| 2329 | } |
| 2330 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2331 | if (sv->tracked) |
| 2332 | svs = sv->tracked; |
| 2333 | else |
| 2334 | svs = sv; |
| 2335 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2336 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2337 | if (!(svs->state & SRV_CHECKED)) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2338 | sv_state = 6; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2339 | else if (svs->state & SRV_RUNNING) { |
| 2340 | if (svs->health == svs->rise + svs->fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2341 | sv_state = 3; /* UP */ |
| 2342 | else |
| 2343 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2344 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2345 | if (svs->state & SRV_GOINGDOWN) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2346 | sv_state += 2; |
| 2347 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2348 | else |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2349 | if (svs->health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2350 | sv_state = 1; /* going up */ |
| 2351 | else |
| 2352 | sv_state = 0; /* DOWN */ |
| 2353 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2354 | 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] | 2355 | /* do not report servers which are DOWN */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2356 | si->applet.ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2357 | continue; |
| 2358 | } |
| 2359 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2360 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2361 | static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d ↑", |
| 2362 | "UP %d/%d ↓", "UP", |
| 2363 | "NOLB %d/%d ↓", "NOLB", |
| 2364 | "<i>no check</i>" }; |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2365 | if ((sv->state & SRV_MAINTAIN) || (svs->state & SRV_MAINTAIN)) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2366 | chunk_printf(&msg, |
| 2367 | /* name */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2368 | "<tr class=\"maintain\">" |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2369 | ); |
| 2370 | } |
| 2371 | else { |
| 2372 | chunk_printf(&msg, |
| 2373 | /* name */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2374 | "<tr class=\"%s%d\">", |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2375 | (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state); |
| 2376 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2377 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2378 | 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] | 2379 | chunk_printf(&msg, |
| 2380 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 2381 | sv->id); |
| 2382 | } |
| 2383 | |
| 2384 | chunk_printf(&msg, "<td class=ac"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2385 | |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2386 | if (uri->flags&ST_SHLGNDS) { |
| 2387 | char str[INET6_ADDRSTRLEN]; |
| 2388 | |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 2389 | chunk_printf(&msg, " title=\""); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2390 | |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 2391 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2392 | case AF_INET: |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 2393 | chunk_printf(&msg, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2394 | break; |
| 2395 | case AF_INET6: |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 2396 | chunk_printf(&msg, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 2397 | break; |
| 2398 | case AF_UNIX: |
| 2399 | chunk_printf(&msg, "unix, "); |
| 2400 | break; |
| 2401 | case -1: |
| 2402 | chunk_printf(&msg, "(%s), ", strerror(errno)); |
| 2403 | break; |
| 2404 | default: /* address family not supported */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 2405 | break; |
| 2406 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2407 | |
| 2408 | /* id */ |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 2409 | chunk_printf(&msg, "id: %d", sv->puid); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2410 | |
| 2411 | /* cookie */ |
| 2412 | if (sv->cookie) { |
| 2413 | struct chunk src; |
| 2414 | |
| 2415 | chunk_printf(&msg, ", cookie: '"); |
| 2416 | |
| 2417 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 2418 | chunk_htmlencode(&msg, &src); |
| 2419 | |
| 2420 | chunk_printf(&msg, "'"); |
| 2421 | } |
| 2422 | |
| 2423 | chunk_printf(&msg, "\""); |
| 2424 | } |
| 2425 | |
| 2426 | chunk_printf(&msg, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2427 | ">%s<a name=\"%s/%s\"></a>" |
| 2428 | "<a class=lfsb href=\"#%s/%s\">%s</a>%s</td>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 2429 | /* queue : current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2430 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 2431 | /* sessions rate : current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2432 | "<td>%s</td><td>%s</td><td></td>" |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2433 | /* sessions: current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2434 | "<td>%s</td><td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2435 | "<td" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2436 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2437 | (uri->flags & ST_SHLGNDS)?"<u>":"", |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2438 | px->id, sv->id, px->id, sv->id, sv->id, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2439 | (uri->flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 2440 | U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"), |
| 2441 | 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] | 2442 | U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-")); |
| 2443 | |
| 2444 | /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2445 | if (px->mode == PR_MODE_HTTP) { |
| 2446 | int i; |
| 2447 | |
| 2448 | chunk_printf(&msg, " title=\"rsp codes:"); |
| 2449 | |
| 2450 | for (i = 1; i < 6; i++) |
| 2451 | chunk_printf(&msg, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]); |
| 2452 | |
| 2453 | chunk_printf(&msg, " other=%lld\"", sv->counters.p.http.rsp[0]); |
| 2454 | } |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2455 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2456 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2457 | /* sessions: total, lbtot */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2458 | ">%s%s%s</td><td>%s</td>", |
| 2459 | (px->mode == PR_MODE_HTTP)?"<u>":"", |
| 2460 | U2H0(sv->counters.cum_sess), |
| 2461 | (px->mode == PR_MODE_HTTP)?"</u>":"", |
| 2462 | U2H1(sv->counters.cum_lbconn)); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2463 | |
| 2464 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2465 | /* bytes : in, out */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2466 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2467 | /* denied: req, resp */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2468 | "<td></td><td>%s</td>" |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2469 | /* errors : request, connect */ |
| 2470 | "<td></td><td>%s</td>" |
| 2471 | /* errors : response */ |
Willy Tarreau | 6a8573e | 2010-03-05 18:15:23 +0100 | [diff] [blame] | 2472 | "<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] | 2473 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2474 | "<td>%lld</td><td>%lld</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2475 | "", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2476 | U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out), |
| 2477 | U2H2(sv->counters.failed_secu), |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2478 | U2H3(sv->counters.failed_conns), |
Willy Tarreau | 6a8573e | 2010-03-05 18:15:23 +0100 | [diff] [blame] | 2479 | sv->counters.cli_aborts, |
| 2480 | sv->counters.srv_aborts, |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2481 | U2H6(sv->counters.failed_resp), |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2482 | sv->counters.retries, sv->counters.redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2483 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2484 | /* status, lest check */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2485 | chunk_printf(&msg, "<td class=ac>"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2486 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2487 | if (sv->state & SRV_MAINTAIN) { |
| 2488 | chunk_printf(&msg, "%s ", |
| 2489 | human_time(now.tv_sec - sv->last_change, 1)); |
| 2490 | chunk_printf(&msg, "MAINT"); |
| 2491 | } |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2492 | else if (svs != sv && svs->state & SRV_MAINTAIN) { |
| 2493 | chunk_printf(&msg, "%s ", |
| 2494 | human_time(now.tv_sec - svs->last_change, 1)); |
| 2495 | chunk_printf(&msg, "MAINT(via)"); |
| 2496 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2497 | else if (svs->state & SRV_CHECKED) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2498 | chunk_printf(&msg, "%s ", |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2499 | human_time(now.tv_sec - svs->last_change, 1)); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2500 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2501 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2502 | srv_hlt_st[sv_state], |
| 2503 | (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), |
| 2504 | (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2505 | } |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 2506 | |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2507 | if (sv->state & SRV_CHECKED) { |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2508 | chunk_printf(&msg, "</td><td class=ac title=\"%s", |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 2509 | get_check_status_description(sv->check_status)); |
| 2510 | |
| 2511 | if (*sv->check_desc) { |
| 2512 | struct chunk src; |
| 2513 | |
| 2514 | chunk_printf(&msg, ": "); |
| 2515 | |
| 2516 | chunk_initlen(&src, sv->check_desc, 0, strlen(sv->check_desc)); |
| 2517 | chunk_htmlencode(&msg, &src); |
| 2518 | } |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2519 | |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2520 | chunk_printf(&msg, "\"><u> %s%s", |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2521 | tv_iszero(&sv->check_start)?"":"* ", |
| 2522 | get_check_status_info(sv->check_status)); |
| 2523 | |
| 2524 | if (sv->check_status >= HCHK_STATUS_L57DATA) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2525 | chunk_printf(&msg, "/%d", sv->check_code); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2526 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2527 | if (sv->check_status >= HCHK_STATUS_CHECKED && sv->check_duration >= 0) |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2528 | chunk_printf(&msg, " in %lums</u>", sv->check_duration); |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2529 | } else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2530 | chunk_printf(&msg, "</td><td>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2531 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2532 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2533 | /* weight */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2534 | "</td><td class=ac>%d</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2535 | /* act, bck */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2536 | "<td class=ac>%s</td><td class=ac>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2537 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 2538 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2539 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2540 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2541 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2542 | /* check failures: unique, fatal, down time */ |
Krzysztof Piotr Oledzki | 748196e | 2010-01-04 00:48:43 +0100 | [diff] [blame] | 2543 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2544 | chunk_printf(&msg, "<td title=\"Failed Health Checks%s\"><u>%lld", |
Krzysztof Piotr Oledzki | 748196e | 2010-01-04 00:48:43 +0100 | [diff] [blame] | 2545 | svs->observe?"/Health Analyses":"", svs->counters.failed_checks); |
| 2546 | |
| 2547 | if (svs->observe) |
| 2548 | chunk_printf(&msg, "/%lld", svs->counters.failed_hana); |
| 2549 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2550 | chunk_printf(&msg, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2551 | "</u></td>" |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2552 | "<td>%lld</td><td>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2553 | "", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2554 | svs->counters.down_trans, human_time(srv_downtime(sv), 1)); |
Krzysztof Piotr Oledzki | 748196e | 2010-01-04 00:48:43 +0100 | [diff] [blame] | 2555 | } else if (sv != svs) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2556 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | 88a14af | 2010-01-05 18:33:01 +0100 | [diff] [blame] | 2557 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2558 | svs->proxy->id, svs->id, svs->proxy->id, svs->id); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2559 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2560 | chunk_printf(&msg, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2561 | "<td colspan=3></td>"); |
| 2562 | |
| 2563 | /* throttle */ |
| 2564 | if ((sv->state & SRV_WARMINGUP) && |
| 2565 | now.tv_sec < sv->last_change + sv->slowstart && |
| 2566 | now.tv_sec >= sv->last_change) { |
| 2567 | unsigned int ratio; |
| 2568 | 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] | 2569 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2570 | "<td class=ac>%d %%</td></tr>\n", ratio); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2571 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2572 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2573 | "<td class=ac>-</td></tr>\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2574 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2575 | } else { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2576 | static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,", |
| 2577 | "UP %d/%d,", "UP,", |
| 2578 | "NOLB %d/%d,", "NOLB,", |
| 2579 | "no check," }; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2580 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2581 | /* pxid, name */ |
| 2582 | "%s,%s," |
| 2583 | /* queue : current, max */ |
| 2584 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 2585 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2586 | "%d,%d,%s,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2587 | /* bytes : in, out */ |
| 2588 | "%lld,%lld," |
| 2589 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2590 | ",%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2591 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2592 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 2593 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2594 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2595 | "", |
| 2596 | px->id, sv->id, |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 2597 | sv->nbpend, sv->counters.nbpend_max, |
| 2598 | 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] | 2599 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2600 | sv->counters.failed_secu, |
| 2601 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2602 | sv->counters.retries, sv->counters.redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2603 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2604 | /* status */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2605 | if (sv->state & SRV_MAINTAIN) { |
| 2606 | chunk_printf(&msg, "MAINT,"); |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2607 | } |
| 2608 | else if (svs != sv && svs->state & SRV_MAINTAIN) { |
| 2609 | chunk_printf(&msg, "MAINT(via),"); |
| 2610 | } |
| 2611 | else { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2612 | chunk_printf(&msg, |
| 2613 | srv_hlt_st[sv_state], |
| 2614 | (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), |
| 2615 | (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); |
| 2616 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2617 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2618 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2619 | /* weight, active, backup */ |
| 2620 | "%d,%d,%d," |
| 2621 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 2622 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2623 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2624 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2625 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2626 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2627 | if (sv->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2628 | chunk_printf(&msg, |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2629 | "%lld,%lld,%d,%d,", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2630 | sv->counters.failed_checks, sv->counters.down_trans, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 2631 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2632 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2633 | chunk_printf(&msg, |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 2634 | ",,,,"); |
| 2635 | |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2636 | /* queue limit, pid, iid, sid, */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2637 | chunk_printf(&msg, |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 2638 | "%s," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2639 | "%d,%d,%d,", |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 2640 | LIM2A0(sv->maxqueue, ""), |
| 2641 | relative_pid, px->uuid, sv->puid); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2642 | |
| 2643 | /* throttle */ |
| 2644 | if ((sv->state & SRV_WARMINGUP) && |
| 2645 | now.tv_sec < sv->last_change + sv->slowstart && |
| 2646 | now.tv_sec >= sv->last_change) { |
| 2647 | unsigned int ratio; |
| 2648 | 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] | 2649 | chunk_printf(&msg, "%d", ratio); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2650 | } |
| 2651 | |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 2652 | /* sessions: lbtot */ |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2653 | chunk_printf(&msg, ",%lld,", sv->counters.cum_lbconn); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2654 | |
| 2655 | /* tracked */ |
| 2656 | if (sv->tracked) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2657 | chunk_printf(&msg, "%s/%s,", |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2658 | sv->tracked->proxy->id, sv->tracked->id); |
| 2659 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2660 | chunk_printf(&msg, ","); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2661 | |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 2662 | /* type */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2663 | chunk_printf(&msg, "%d,", STATS_TYPE_SV); |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 2664 | |
| 2665 | /* rate */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2666 | chunk_printf(&msg, "%u,,%u,", |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 2667 | read_freq_ctr(&sv->sess_per_sec), |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 2668 | sv->counters.sps_max); |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 2669 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2670 | if (sv->state & SRV_CHECKED) { |
| 2671 | /* check_status */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2672 | chunk_printf(&msg, "%s,", get_check_status_info(sv->check_status)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2673 | |
| 2674 | /* check_code */ |
| 2675 | if (sv->check_status >= HCHK_STATUS_L57DATA) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2676 | chunk_printf(&msg, "%u,", sv->check_code); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2677 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2678 | chunk_printf(&msg, ","); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2679 | |
| 2680 | /* check_duration */ |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2681 | if (sv->check_status >= HCHK_STATUS_CHECKED) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2682 | chunk_printf(&msg, "%lu,", sv->check_duration); |
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 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2687 | chunk_printf(&msg, ",,,"); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2688 | } |
| 2689 | |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2690 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2691 | if (px->mode == PR_MODE_HTTP) { |
| 2692 | int i; |
| 2693 | |
| 2694 | for (i=1; i<6; i++) |
| 2695 | chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[i]); |
| 2696 | |
| 2697 | chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[0]); |
| 2698 | } else { |
| 2699 | chunk_printf(&msg, ",,,,,,"); |
| 2700 | } |
| 2701 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2702 | /* failed health analyses */ |
| 2703 | chunk_printf(&msg, "%lld,", sv->counters.failed_hana); |
| 2704 | |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 2705 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2706 | chunk_printf(&msg, ",,,"); |
| 2707 | |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2708 | /* errors: cli_aborts, srv_aborts */ |
| 2709 | chunk_printf(&msg, "%lld,%lld,", |
| 2710 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 2711 | |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 2712 | /* finish with EOL */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2713 | chunk_printf(&msg, "\n"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2714 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2715 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2716 | return 0; |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2717 | } /* for sv */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2718 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2719 | si->applet.ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2720 | /* fall through */ |
| 2721 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2722 | case STAT_PX_ST_BE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2723 | /* print the backend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 2724 | if ((px->cap & PR_CAP_BE) && |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2725 | (!(si->applet.ctx.stats.flags & STAT_BOUND) || (si->applet.ctx.stats.type & (1 << STATS_TYPE_BE)))) { |
| 2726 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2727 | chunk_printf(&msg, "<tr class=\"backend\">"); |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2728 | 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] | 2729 | /* Column sub-heading for Enable or Disable server */ |
| 2730 | chunk_printf(&msg, "<td></td>"); |
| 2731 | } |
| 2732 | chunk_printf(&msg, "<td class=ac"); |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2733 | |
| 2734 | if (uri->flags&ST_SHLGNDS) { |
| 2735 | /* balancing */ |
Krzysztof Piotr Oledzki | c0f0c86 | 2010-01-06 15:03:18 +0100 | [diff] [blame] | 2736 | chunk_printf(&msg, " title=\"balancing: %s", |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2737 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
Krzysztof Piotr Oledzki | c0f0c86 | 2010-01-06 15:03:18 +0100 | [diff] [blame] | 2738 | |
| 2739 | /* cookie */ |
| 2740 | if (px->cookie_name) { |
| 2741 | struct chunk src; |
| 2742 | |
| 2743 | chunk_printf(&msg, ", cookie: '"); |
| 2744 | |
| 2745 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 2746 | chunk_htmlencode(&msg, &src); |
| 2747 | |
| 2748 | chunk_printf(&msg, "'"); |
| 2749 | } |
| 2750 | |
| 2751 | chunk_printf(&msg, "\""); |
| 2752 | |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | chunk_printf(&msg, |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2756 | /* name */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2757 | ">%s<a name=\"%s/Backend\"></a>" |
| 2758 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2759 | /* queue : current, max */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2760 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 2761 | /* sessions rate : current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2762 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 2763 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2764 | (uri->flags & ST_SHLGNDS)?"<u>":"", |
Krzysztof Piotr Oledzki | 1f67285 | 2009-10-24 14:24:30 +0200 | [diff] [blame] | 2765 | px->id, px->id, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2766 | (uri->flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2767 | U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->be_counters.nbpend_max), |
| 2768 | 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] | 2769 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2770 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2771 | /* sessions: current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2772 | "<td>%s</td><td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2773 | "<td" |
| 2774 | "", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2775 | 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] | 2776 | |
| 2777 | /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2778 | if (px->mode == PR_MODE_HTTP) { |
| 2779 | int i; |
| 2780 | |
| 2781 | chunk_printf(&msg, " title=\"rsp codes:"); |
| 2782 | |
| 2783 | for (i = 1; i < 6; i++) |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2784 | 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] | 2785 | |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2786 | 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] | 2787 | } |
| 2788 | |
| 2789 | chunk_printf(&msg, |
| 2790 | /* sessions: total, lbtot */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2791 | ">%s%s%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2792 | /* bytes: in, out */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2793 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2794 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2795 | (px->mode == PR_MODE_HTTP)?"<u>":"", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2796 | U2H6(px->be_counters.cum_conn), |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2797 | (px->mode == PR_MODE_HTTP)?"</u>":"", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2798 | U2H7(px->be_counters.cum_lbconn), |
| 2799 | U2H8(px->be_counters.bytes_in), U2H9(px->be_counters.bytes_out)); |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2800 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2801 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2802 | /* denied: req, resp */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2803 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2804 | /* errors : request, connect */ |
| 2805 | "<td></td><td>%s</td>" |
| 2806 | /* errors : response */ |
Willy Tarreau | 6a8573e | 2010-03-05 18:15:23 +0100 | [diff] [blame] | 2807 | "<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] | 2808 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2809 | "<td>%lld</td><td>%lld</td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2810 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2811 | * 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] | 2812 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2813 | * active and backups. */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2814 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 2815 | "<td class=ac>%d</td><td class=ac>%d</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2816 | "", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2817 | U2H0(px->be_counters.denied_req), U2H1(px->be_counters.denied_resp), |
| 2818 | U2H2(px->be_counters.failed_conns), |
| 2819 | px->be_counters.cli_aborts, |
| 2820 | px->be_counters.srv_aborts, |
| 2821 | U2H5(px->be_counters.failed_resp), |
| 2822 | px->be_counters.retries, px->be_counters.redispatches, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2823 | human_time(now.tv_sec - px->last_change, 1), |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2824 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 2825 | "<font color=\"red\"><b>DOWN</b></font>", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 2826 | (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] | 2827 | px->srv_act, px->srv_bck); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2828 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2829 | chunk_printf(&msg, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2830 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2831 | "<td class=ac> </td><td>%d</td>" |
| 2832 | "<td>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2833 | "<td></td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2834 | "</tr>", |
| 2835 | px->down_trans, |
| 2836 | px->srv?human_time(be_downtime(px), 1):" "); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2837 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2838 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2839 | /* pxid, name */ |
| 2840 | "%s,BACKEND," |
| 2841 | /* queue : current, max */ |
| 2842 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 2843 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2844 | "%d,%d,%d,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2845 | /* bytes : in, out */ |
| 2846 | "%lld,%lld," |
| 2847 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2848 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2849 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2850 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 2851 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2852 | "%lld,%lld," |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2853 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2854 | * 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] | 2855 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2856 | * active and backups. */ |
| 2857 | "%s," |
| 2858 | "%d,%d,%d," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2859 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 2860 | ",%d,%d,%d,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2861 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2862 | "%d,%d,0,,%lld,,%d," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 2863 | /* rate, rate_lim, rate_max, */ |
| 2864 | "%u,,%u," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2865 | /* check_status, check_code, check_duration */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2866 | ",,,", |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2867 | px->id, |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2868 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 2869 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 2870 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 2871 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 2872 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 2873 | px->be_counters.retries, px->be_counters.redispatches, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 2874 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 2875 | (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] | 2876 | px->srv_act, px->srv_bck, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 2877 | px->down_trans, (int)(now.tv_sec - px->last_change), |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 2878 | px->srv?be_downtime(px):0, |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 2879 | relative_pid, px->uuid, |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2880 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 2881 | read_freq_ctr(&px->be_sess_per_sec), |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2882 | px->be_counters.sps_max); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2883 | |
| 2884 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2885 | if (px->mode == PR_MODE_HTTP) { |
| 2886 | int i; |
| 2887 | |
| 2888 | for (i=1; i<6; i++) |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2889 | chunk_printf(&msg, "%lld,", px->be_counters.p.http.rsp[i]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2890 | |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2891 | chunk_printf(&msg, "%lld,", px->be_counters.p.http.rsp[0]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2892 | } else { |
| 2893 | chunk_printf(&msg, ",,,,,,"); |
| 2894 | } |
| 2895 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2896 | /* failed health analyses */ |
| 2897 | chunk_printf(&msg, ","); |
| 2898 | |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 2899 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2900 | chunk_printf(&msg, ",,,"); |
| 2901 | |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2902 | /* errors: cli_aborts, srv_aborts */ |
| 2903 | chunk_printf(&msg, "%lld,%lld,", |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2904 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2905 | |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2906 | /* finish with EOL */ |
| 2907 | chunk_printf(&msg, "\n"); |
| 2908 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2909 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2910 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2911 | return 0; |
| 2912 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2913 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2914 | si->applet.ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2915 | /* fall through */ |
| 2916 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2917 | case STAT_PX_ST_END: |
| 2918 | if (!(si->applet.ctx.stats.flags & STAT_FMT_CSV)) { |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 2919 | chunk_printf(&msg, "</table>"); |
| 2920 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2921 | 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] | 2922 | /* close the form used to enable/disable this proxy servers */ |
| 2923 | chunk_printf(&msg, |
| 2924 | "Choose the action to perform on the checked servers : " |
| 2925 | "<select name=action>" |
| 2926 | "<option value=\"\"></option>" |
| 2927 | "<option value=\"disable\">Disable</option>" |
| 2928 | "<option value=\"enable\">Enable</option>" |
| 2929 | "</select>" |
| 2930 | "<input type=\"hidden\" name=\"b\" value=\"%s\">" |
| 2931 | " <input type=\"submit\" value=\"Apply\">" |
| 2932 | "</form>", |
| 2933 | px->id); |
| 2934 | } |
| 2935 | |
| 2936 | chunk_printf(&msg, "<p>\n"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2937 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2938 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2939 | return 0; |
| 2940 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2941 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2942 | si->applet.ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2943 | /* fall through */ |
| 2944 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2945 | case STAT_PX_ST_FIN: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2946 | return 1; |
| 2947 | |
| 2948 | default: |
| 2949 | /* unknown state, we should put an abort() here ! */ |
| 2950 | return 1; |
| 2951 | } |
| 2952 | } |
| 2953 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2954 | /* This function dumps a complete session state onto the stream intreface's |
| 2955 | * read buffer. The data_ctx must have been zeroed first, and the flags |
| 2956 | * properly set. The session has to be set in data_ctx.sess.target. It returns |
| 2957 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 2958 | * 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] | 2959 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 2960 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2961 | { |
| 2962 | struct tm tm; |
| 2963 | struct chunk msg; |
| 2964 | struct session *sess; |
| 2965 | extern const char *monthname[12]; |
| 2966 | char pn[INET6_ADDRSTRLEN]; |
| 2967 | |
| 2968 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2969 | sess = si->applet.ctx.sess.target; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2970 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2971 | 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] | 2972 | /* session changed, no need to go any further */ |
| 2973 | chunk_printf(&msg, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2974 | if (buffer_feed_chunk(si->ib, &msg) >= 0) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2975 | return 0; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2976 | si->applet.ctx.sess.target = NULL; |
| 2977 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2978 | return 1; |
| 2979 | } |
| 2980 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2981 | switch (si->applet.ctx.sess.section) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2982 | case 0: /* main status of the session */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 2983 | si->applet.ctx.sess.uid = sess->uniq_id; |
| 2984 | si->applet.ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2985 | /* fall through */ |
| 2986 | |
| 2987 | case 1: |
| 2988 | chunk_printf(&msg, |
| 2989 | "%p: id=%u, proto=%s", |
| 2990 | sess, |
| 2991 | sess->uniq_id, |
| 2992 | sess->listener->proto->name); |
| 2993 | |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 2994 | switch (addr_to_str(&sess->si[0].addr.c.from, pn, sizeof(pn))) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2995 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2996 | case AF_INET6: |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 2997 | chunk_printf(&msg, " source=%s:%d\n", |
| 2998 | pn, get_host_port(&sess->si[0].addr.c.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2999 | break; |
| 3000 | case AF_UNIX: |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 3001 | chunk_printf(&msg, " source=unix:%d\n", sess->listener->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3002 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3003 | default: |
| 3004 | /* no more information to print right now */ |
| 3005 | chunk_printf(&msg, "\n"); |
| 3006 | break; |
| 3007 | } |
| 3008 | |
| 3009 | chunk_printf(&msg, |
| 3010 | " 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] | 3011 | 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] | 3012 | |
| 3013 | chunk_printf(&msg, |
| 3014 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)\n", |
| 3015 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 3016 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 3017 | sess->listener ? sess->listener->luid : 0); |
| 3018 | |
| 3019 | chunk_printf(&msg, |
| 3020 | " backend=%s (id=%u mode=%s) server=%s (id=%u)\n", |
| 3021 | sess->be->id, sess->be->uuid, sess->be->mode ? "http" : "tcp", |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 3022 | target_srv(&sess->target) ? target_srv(&sess->target)->id : "<none>", |
| 3023 | target_srv(&sess->target) ? target_srv(&sess->target)->puid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3024 | |
| 3025 | chunk_printf(&msg, |
| 3026 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s)\n", |
| 3027 | sess->task, |
| 3028 | sess->task->state, |
| 3029 | sess->task->nice, sess->task->calls, |
| 3030 | sess->task->expire ? |
| 3031 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 3032 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 3033 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3034 | task_in_rq(sess->task) ? ", running" : ""); |
| 3035 | |
| 3036 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
| 3037 | chunk_printf(&msg, |
| 3038 | " task created [%02d/%s/%04d:%02d:%02d:%02d.%06d] (age=%s)\n", |
| 3039 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 3040 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec), |
| 3041 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 3042 | |
| 3043 | chunk_printf(&msg, |
| 3044 | " si[0]=%p (state=%d flags=0x%02x fd=%d exp=%s, et=0x%03x)\n", |
| 3045 | &sess->si[0], |
| 3046 | sess->si[0].state, |
| 3047 | sess->si[0].flags, |
| 3048 | sess->si[0].fd, |
| 3049 | sess->si[0].exp ? |
| 3050 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 3051 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 3052 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3053 | sess->si[0].err_type); |
| 3054 | |
| 3055 | chunk_printf(&msg, |
| 3056 | " si[1]=%p (state=%d flags=0x%02x fd=%d exp=%s, et=0x%03x)\n", |
| 3057 | &sess->si[1], |
| 3058 | sess->si[1].state, |
| 3059 | sess->si[1].flags, |
| 3060 | sess->si[1].fd, |
| 3061 | sess->si[1].exp ? |
| 3062 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 3063 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 3064 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3065 | sess->si[1].err_type); |
| 3066 | |
| 3067 | chunk_printf(&msg, |
| 3068 | " txn=%p (flags=0x%x meth=%d status=%d req.st=%d rsp.st=%d)\n", |
| 3069 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 3070 | sess->txn.req.msg_state, sess->txn.rsp.msg_state); |
| 3071 | |
| 3072 | |
| 3073 | chunk_printf(&msg, |
Willy Tarreau | d8ee85a | 2011-03-28 16:06:28 +0200 | [diff] [blame] | 3074 | " 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] | 3075 | " an_exp=%s", |
| 3076 | sess->req, |
| 3077 | sess->req->flags, sess->req->analysers, |
| 3078 | sess->req->l, sess->req->send_max, |
| 3079 | sess->req->pipe ? sess->req->pipe->data : 0, |
| 3080 | sess->req->to_forward, |
| 3081 | sess->req->analyse_exp ? |
| 3082 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 3083 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3084 | |
| 3085 | chunk_printf(&msg, |
| 3086 | " rex=%s", |
| 3087 | sess->req->rex ? |
| 3088 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 3089 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3090 | |
| 3091 | chunk_printf(&msg, |
| 3092 | " wex=%s\n" |
| 3093 | " data=%p r=%d w=%d lr=%d total=%lld\n", |
| 3094 | sess->req->wex ? |
| 3095 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 3096 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3097 | sess->req->data, |
Willy Tarreau | 4e1554c | 2010-03-21 23:21:00 +0100 | [diff] [blame] | 3098 | (int)(sess->req->r - sess->req->data), |
| 3099 | (int)(sess->req->w - sess->req->data), |
| 3100 | (int)(sess->req->lr - sess->req->data), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3101 | sess->req->total); |
| 3102 | |
| 3103 | chunk_printf(&msg, |
Willy Tarreau | d8ee85a | 2011-03-28 16:06:28 +0200 | [diff] [blame] | 3104 | " 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] | 3105 | " an_exp=%s", |
| 3106 | sess->rep, |
| 3107 | sess->rep->flags, sess->rep->analysers, |
| 3108 | sess->rep->l, sess->rep->send_max, |
| 3109 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
| 3110 | sess->rep->to_forward, |
| 3111 | sess->rep->analyse_exp ? |
| 3112 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 3113 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3114 | |
| 3115 | chunk_printf(&msg, |
| 3116 | " rex=%s", |
| 3117 | sess->rep->rex ? |
| 3118 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 3119 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 3120 | |
| 3121 | chunk_printf(&msg, |
| 3122 | " wex=%s\n" |
| 3123 | " data=%p r=%d w=%d lr=%d total=%lld\n", |
| 3124 | sess->rep->wex ? |
| 3125 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 3126 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 3127 | sess->rep->data, |
Willy Tarreau | 4e1554c | 2010-03-21 23:21:00 +0100 | [diff] [blame] | 3128 | (int)(sess->rep->r - sess->rep->data), |
| 3129 | (int)(sess->rep->w - sess->rep->data), |
| 3130 | (int)(sess->rep->lr - sess->rep->data), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3131 | sess->rep->total); |
| 3132 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3133 | if (buffer_feed_chunk(si->ib, &msg) >= 0) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3134 | return 0; |
| 3135 | |
| 3136 | /* use other states to dump the contents */ |
| 3137 | } |
| 3138 | /* end of dump */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3139 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3140 | return 1; |
| 3141 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3142 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3143 | /* This function dumps all sessions' states onto the stream intreface's |
| 3144 | * read buffer. The data_ctx must have been zeroed first, and the flags |
| 3145 | * properly set. It returns 0 if the output buffer is full and it needs |
| 3146 | * to be called again, otherwise non-zero. It is designed to be called |
| 3147 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3148 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 3149 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3150 | { |
| 3151 | struct chunk msg; |
| 3152 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3153 | if (unlikely(si->ib->flags & (BF_WRITE_ERROR|BF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3154 | /* If we're forced to shut down, we might have to remove our |
| 3155 | * reference to the last session being dumped. |
| 3156 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3157 | if (si->applet.state == STAT_ST_LIST) { |
| 3158 | if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) { |
| 3159 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3160 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3161 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3162 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 3163 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3164 | } |
| 3165 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3166 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3167 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3168 | switch (si->applet.state) { |
| 3169 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3170 | /* the function had not been called yet, let's prepare the |
| 3171 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3172 | * pointer to the first in the global list. When a target |
| 3173 | * session is being destroyed, it is responsible for updating |
| 3174 | * this pointer. We know we have reached the end when this |
| 3175 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3176 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3177 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
| 3178 | si->applet.ctx.sess.bref.ref = sessions.n; |
| 3179 | si->applet.state = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3180 | /* fall through */ |
| 3181 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3182 | case STAT_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3183 | /* first, let's detach the back-ref from a possible previous session */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3184 | if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) { |
| 3185 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3186 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | /* and start from where we stopped */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3190 | while (si->applet.ctx.sess.bref.ref != &sessions) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 3191 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3192 | struct session *curr_sess; |
| 3193 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3194 | 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] | 3195 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3196 | if (si->applet.ctx.sess.target) { |
| 3197 | if (si->applet.ctx.sess.target != curr_sess) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3198 | goto next_sess; |
| 3199 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3200 | LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3201 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3202 | if (!stats_dump_full_sess_to_buffer(si)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3203 | return 0; |
| 3204 | |
| 3205 | /* session dump complete */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3206 | LIST_DEL(&si->applet.ctx.sess.bref.users); |
| 3207 | LIST_INIT(&si->applet.ctx.sess.bref.users); |
| 3208 | si->applet.ctx.sess.target = NULL; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3209 | break; |
| 3210 | } |
| 3211 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3212 | chunk_printf(&msg, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3213 | "%p: proto=%s", |
| 3214 | curr_sess, |
| 3215 | curr_sess->listener->proto->name); |
| 3216 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3217 | |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 3218 | switch (addr_to_str(&curr_sess->si[0].addr.c.from, pn, sizeof(pn))) { |
| 3219 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3220 | case AF_INET6: |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3221 | chunk_printf(&msg, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3222 | " src=%s:%d fe=%s be=%s srv=%s", |
| 3223 | pn, |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 3224 | get_host_port(&curr_sess->si[0].addr.c.from), |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3225 | curr_sess->fe->id, |
| 3226 | curr_sess->be->id, |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 3227 | target_srv(&curr_sess->target) ? target_srv(&curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3228 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3229 | break; |
| 3230 | case AF_UNIX: |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3231 | chunk_printf(&msg, |
| 3232 | " src=unix:%d fe=%s be=%s srv=%s", |
| 3233 | curr_sess->listener->luid, |
| 3234 | curr_sess->fe->id, |
| 3235 | curr_sess->be->id, |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 3236 | target_srv(&curr_sess->target) ? target_srv(&curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 3237 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3238 | break; |
| 3239 | } |
| 3240 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3241 | chunk_printf(&msg, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 3242 | " ts=%02x age=%s calls=%d", |
| 3243 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 3244 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 3245 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3246 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3247 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3248 | " rq[f=%06xh,l=%d,an=%02xh,rx=%s", |
| 3249 | curr_sess->req->flags, |
| 3250 | curr_sess->req->l, |
| 3251 | curr_sess->req->analysers, |
| 3252 | curr_sess->req->rex ? |
| 3253 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 3254 | TICKS_TO_MS(1000)) : ""); |
| 3255 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3256 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3257 | ",wx=%s", |
| 3258 | curr_sess->req->wex ? |
| 3259 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 3260 | TICKS_TO_MS(1000)) : ""); |
| 3261 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3262 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3263 | ",ax=%s]", |
| 3264 | curr_sess->req->analyse_exp ? |
| 3265 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 3266 | TICKS_TO_MS(1000)) : ""); |
| 3267 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3268 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3269 | " rp[f=%06xh,l=%d,an=%02xh,rx=%s", |
| 3270 | curr_sess->rep->flags, |
| 3271 | curr_sess->rep->l, |
| 3272 | curr_sess->rep->analysers, |
| 3273 | curr_sess->rep->rex ? |
| 3274 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 3275 | TICKS_TO_MS(1000)) : ""); |
| 3276 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3277 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3278 | ",wx=%s", |
| 3279 | curr_sess->rep->wex ? |
| 3280 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 3281 | TICKS_TO_MS(1000)) : ""); |
| 3282 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3283 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3284 | ",ax=%s]", |
| 3285 | curr_sess->rep->analyse_exp ? |
| 3286 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 3287 | TICKS_TO_MS(1000)) : ""); |
| 3288 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3289 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3290 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 3291 | curr_sess->si[0].state, |
| 3292 | curr_sess->si[0].flags, |
| 3293 | curr_sess->si[0].fd, |
| 3294 | curr_sess->si[0].exp ? |
| 3295 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 3296 | TICKS_TO_MS(1000)) : ""); |
| 3297 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3298 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3299 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 3300 | curr_sess->si[1].state, |
| 3301 | curr_sess->si[1].flags, |
| 3302 | curr_sess->si[1].fd, |
| 3303 | curr_sess->si[1].exp ? |
| 3304 | human_time(TICKS_TO_MS(curr_sess->si[1].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 | " exp=%s", |
| 3309 | curr_sess->task->expire ? |
| 3310 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 3311 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 3312 | if (task_in_rq(curr_sess->task)) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3313 | chunk_printf(&msg, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 3314 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3315 | chunk_printf(&msg, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3316 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3317 | if (buffer_feed_chunk(si->ib, &msg) >= 0) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 3318 | /* let's try again later from this session. We add ourselves into |
| 3319 | * this session's users so that it can remove us upon termination. |
| 3320 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3321 | LIST_ADDQ(&curr_sess->back_refs, &si->applet.ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 3322 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3323 | } |
| 3324 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3325 | next_sess: |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3326 | si->applet.ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3327 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3328 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3329 | if (si->applet.ctx.sess.target) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3330 | /* specified session not found */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3331 | if (si->applet.ctx.sess.section > 0) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3332 | chunk_printf(&msg, " *** session terminated while we were watching it ***\n"); |
| 3333 | else |
| 3334 | chunk_printf(&msg, "Session not found.\n"); |
| 3335 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3336 | if (buffer_feed_chunk(si->ib, &msg) >= 0) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3337 | return 0; |
| 3338 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3339 | si->applet.ctx.sess.target = NULL; |
| 3340 | si->applet.ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 3341 | return 1; |
| 3342 | } |
| 3343 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3344 | si->applet.state = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3345 | /* fall through */ |
| 3346 | |
| 3347 | default: |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3348 | si->applet.state = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 3349 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3350 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 3351 | } |
| 3352 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3353 | /* This function dumps all tables' states onto the stream intreface's |
| 3354 | * read buffer. The data_ctx must have been zeroed first, and the flags |
| 3355 | * properly set. It returns 0 if the output buffer is full and it needs |
| 3356 | * to be called again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3357 | */ |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 3358 | static int stats_table_request(struct stream_interface *si, bool show) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3359 | { |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3360 | struct session *s = si->applet.private; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3361 | struct chunk msg; |
| 3362 | struct ebmb_node *eb; |
| 3363 | int dt; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 3364 | bool skip_entry; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3365 | |
| 3366 | /* |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3367 | * We have 3 possible states in si->applet.state : |
| 3368 | * - STAT_ST_INIT : the first call |
| 3369 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3370 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3371 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3372 | * and the entry pointer points to the next entry to be dumped, |
| 3373 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3374 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3375 | * data though. |
| 3376 | */ |
| 3377 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3378 | if (unlikely(si->ib->flags & (BF_WRITE_ERROR|BF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3379 | /* 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] | 3380 | if (si->applet.state == STAT_ST_LIST) { |
| 3381 | si->applet.ctx.table.entry->ref_cnt--; |
| 3382 | 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] | 3383 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3384 | return 1; |
| 3385 | } |
| 3386 | |
| 3387 | chunk_init(&msg, trash, sizeof(trash)); |
| 3388 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3389 | while (si->applet.state != STAT_ST_FIN) { |
| 3390 | switch (si->applet.state) { |
| 3391 | case STAT_ST_INIT: |
| 3392 | si->applet.ctx.table.proxy = si->applet.ctx.table.target; |
| 3393 | if (!si->applet.ctx.table.proxy) |
| 3394 | si->applet.ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3395 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3396 | si->applet.ctx.table.entry = NULL; |
| 3397 | si->applet.state = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3398 | break; |
| 3399 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3400 | case STAT_ST_INFO: |
| 3401 | if (!si->applet.ctx.table.proxy || |
| 3402 | (si->applet.ctx.table.target && |
| 3403 | si->applet.ctx.table.proxy != si->applet.ctx.table.target)) { |
| 3404 | si->applet.state = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3405 | break; |
| 3406 | } |
| 3407 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3408 | if (si->applet.ctx.table.proxy->table.size) { |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 3409 | if (show && !stats_dump_table_head_to_buffer(&msg, si, si->applet.ctx.table.proxy, |
| 3410 | si->applet.ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3411 | return 0; |
| 3412 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3413 | if (si->applet.ctx.table.target && |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3414 | s->listener->perm.ux.level >= ACCESS_LVL_OPER) { |
| 3415 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3416 | eb = ebmb_first(&si->applet.ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3417 | if (eb) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3418 | si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 3419 | si->applet.ctx.table.entry->ref_cnt++; |
| 3420 | si->applet.state = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3421 | break; |
| 3422 | } |
| 3423 | } |
| 3424 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3425 | si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3426 | break; |
| 3427 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3428 | case STAT_ST_LIST: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 3429 | skip_entry = false; |
| 3430 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3431 | if (si->applet.ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 3432 | /* we're filtering on some data contents */ |
| 3433 | void *ptr; |
| 3434 | long long data; |
| 3435 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3436 | dt = si->applet.ctx.table.data_type; |
| 3437 | ptr = stktable_data_ptr(&si->applet.ctx.table.proxy->table, |
| 3438 | si->applet.ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 3439 | dt); |
| 3440 | |
| 3441 | data = 0; |
| 3442 | switch (stktable_data_types[dt].std_type) { |
| 3443 | case STD_T_SINT: |
| 3444 | data = stktable_data_cast(ptr, std_t_sint); |
| 3445 | break; |
| 3446 | case STD_T_UINT: |
| 3447 | data = stktable_data_cast(ptr, std_t_uint); |
| 3448 | break; |
| 3449 | case STD_T_ULL: |
| 3450 | data = stktable_data_cast(ptr, std_t_ull); |
| 3451 | break; |
| 3452 | case STD_T_FRQP: |
| 3453 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3454 | si->applet.ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 3455 | break; |
| 3456 | } |
| 3457 | |
| 3458 | /* 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] | 3459 | if ((data < si->applet.ctx.table.value && |
| 3460 | (si->applet.ctx.table.data_op == STD_OP_EQ || |
| 3461 | si->applet.ctx.table.data_op == STD_OP_GT || |
| 3462 | si->applet.ctx.table.data_op == STD_OP_GE)) || |
| 3463 | (data == si->applet.ctx.table.value && |
| 3464 | (si->applet.ctx.table.data_op == STD_OP_NE || |
| 3465 | si->applet.ctx.table.data_op == STD_OP_GT || |
| 3466 | si->applet.ctx.table.data_op == STD_OP_LT)) || |
| 3467 | (data > si->applet.ctx.table.value && |
| 3468 | (si->applet.ctx.table.data_op == STD_OP_EQ || |
| 3469 | si->applet.ctx.table.data_op == STD_OP_LT || |
| 3470 | si->applet.ctx.table.data_op == STD_OP_LE))) |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 3471 | skip_entry = true; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 3472 | } |
| 3473 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 3474 | if (show && !skip_entry && |
| 3475 | !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] | 3476 | si->applet.ctx.table.entry)) |
| 3477 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3478 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3479 | si->applet.ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3480 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3481 | eb = ebmb_next(&si->applet.ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3482 | if (eb) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3483 | struct stksess *old = si->applet.ctx.table.entry; |
| 3484 | si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 3485 | stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, old); |
| 3486 | si->applet.ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3487 | break; |
| 3488 | } |
| 3489 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 3490 | |
| 3491 | if (show) |
| 3492 | stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry); |
| 3493 | else if (!skip_entry && !si->applet.ctx.table.entry->ref_cnt) |
| 3494 | stksess_kill(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry); |
| 3495 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3496 | si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next; |
| 3497 | si->applet.state = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3498 | break; |
| 3499 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3500 | case STAT_ST_END: |
| 3501 | si->applet.state = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 3502 | break; |
| 3503 | } |
| 3504 | } |
| 3505 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3506 | } |
| 3507 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 3508 | /* 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] | 3509 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 3510 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 3511 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 3512 | * lines are respected within the limit of 70 output chars. Lines that are |
| 3513 | * continuation of a previous truncated line begin with "+" instead of " " |
| 3514 | * after the offset. The new pointer is returned. |
| 3515 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 3516 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 3517 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3518 | { |
| 3519 | int end; |
| 3520 | unsigned char c; |
| 3521 | |
| 3522 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3523 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3524 | return ptr; |
| 3525 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3526 | chunk_printf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3527 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 3528 | while (ptr < len && ptr < bsize) { |
| 3529 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 3530 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3531 | if (out->len > end - 2) |
| 3532 | break; |
| 3533 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 3534 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3535 | if (out->len > end - 3) |
| 3536 | break; |
| 3537 | out->str[out->len++] = '\\'; |
| 3538 | switch (c) { |
| 3539 | case '\t': c = 't'; break; |
| 3540 | case '\n': c = 'n'; break; |
| 3541 | case '\r': c = 'r'; break; |
| 3542 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 3543 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3544 | } |
| 3545 | out->str[out->len++] = c; |
| 3546 | } else { |
| 3547 | if (out->len > end - 5) |
| 3548 | break; |
| 3549 | out->str[out->len++] = '\\'; |
| 3550 | out->str[out->len++] = 'x'; |
| 3551 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 3552 | out->str[out->len++] = hextab[c & 0xF]; |
| 3553 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 3554 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3555 | /* we had a line break, let's return now */ |
| 3556 | out->str[out->len++] = '\n'; |
| 3557 | *line = ptr; |
| 3558 | return ptr; |
| 3559 | } |
| 3560 | } |
| 3561 | /* we have an incomplete line, we return it as-is */ |
| 3562 | out->str[out->len++] = '\n'; |
| 3563 | return ptr; |
| 3564 | } |
| 3565 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3566 | /* This function dumps all captured errors onto the stream intreface's |
| 3567 | * read buffer. The data_ctx must have been zeroed first, and the flags |
| 3568 | * properly set. It returns 0 if the output buffer is full and it needs |
| 3569 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3570 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 3571 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3572 | { |
| 3573 | extern const char *monthname[12]; |
| 3574 | struct chunk msg; |
| 3575 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3576 | if (unlikely(si->ib->flags & (BF_WRITE_ERROR|BF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3577 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3578 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3579 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3580 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3581 | if (!si->applet.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3582 | /* the function had not been called yet, let's prepare the |
| 3583 | * buffer for a response. |
| 3584 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 3585 | struct tm tm; |
| 3586 | |
| 3587 | get_localtime(date.tv_sec, &tm); |
| 3588 | chunk_printf(&msg, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n", |
| 3589 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 3590 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 3591 | error_snapshot_id); |
| 3592 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3593 | if (buffer_feed_chunk(si->ib, &msg) >= 0) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 3594 | /* Socket buffer full. Let's try again later from the same point */ |
| 3595 | return 0; |
| 3596 | } |
| 3597 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3598 | si->applet.ctx.errors.px = proxy; |
| 3599 | si->applet.ctx.errors.buf = 0; |
| 3600 | si->applet.ctx.errors.bol = 0; |
| 3601 | si->applet.ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | /* we have two inner loops here, one for the proxy, the other one for |
| 3605 | * the buffer. |
| 3606 | */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3607 | while (si->applet.ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3608 | struct error_snapshot *es; |
| 3609 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3610 | if (si->applet.ctx.errors.buf == 0) |
| 3611 | es = &si->applet.ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3612 | else |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3613 | es = &si->applet.ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3614 | |
| 3615 | if (!es->when.tv_sec) |
| 3616 | goto next; |
| 3617 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3618 | if (si->applet.ctx.errors.iid >= 0 && |
| 3619 | si->applet.ctx.errors.px->uuid != si->applet.ctx.errors.iid && |
| 3620 | es->oe->uuid != si->applet.ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3621 | goto next; |
| 3622 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3623 | if (si->applet.ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3624 | /* just print headers now */ |
| 3625 | |
| 3626 | char pn[INET6_ADDRSTRLEN]; |
| 3627 | struct tm tm; |
| 3628 | |
| 3629 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 8811f8e | 2010-03-05 17:42:58 +0100 | [diff] [blame] | 3630 | chunk_printf(&msg, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3631 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 3632 | 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] | 3633 | |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame^] | 3634 | addr_to_str(&es->src, pn, sizeof(pn)); |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3635 | switch (si->applet.ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3636 | case 0: |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3637 | chunk_printf(&msg, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3638 | " frontend %s (#%d): invalid request\n" |
| 3639 | " src %s, session #%d, backend %s (#%d), server %s (#%d)\n" |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 3640 | " HTTP internal state %d, buffer flags 0x%08x, event #%u\n" |
Willy Tarreau | 8811f8e | 2010-03-05 17:42:58 +0100 | [diff] [blame] | 3641 | " request length %d bytes, error at position %d:\n \n", |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3642 | si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid, |
Willy Tarreau | 3fd6cec | 2010-03-25 06:45:07 +0100 | [diff] [blame] | 3643 | pn, es->sid, (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 3644 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3645 | es->srv ? es->srv->id : "<NONE>", |
| 3646 | es->srv ? es->srv->puid : -1, |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 3647 | es->state, es->flags, es->ev_id, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3648 | es->len, es->pos); |
| 3649 | break; |
| 3650 | case 1: |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3651 | chunk_printf(&msg, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3652 | " backend %s (#%d) : invalid response\n" |
| 3653 | " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n" |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 3654 | " HTTP internal state %d, buffer flags 0x%08x, event #%u\n" |
Willy Tarreau | 8811f8e | 2010-03-05 17:42:58 +0100 | [diff] [blame] | 3655 | " response length %d bytes, error at position %d:\n \n", |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3656 | si->applet.ctx.errors.px->id, si->applet.ctx.errors.px->uuid, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3657 | pn, es->sid, es->oe->id, es->oe->uuid, |
| 3658 | es->srv ? es->srv->id : "<NONE>", |
| 3659 | es->srv ? es->srv->puid : -1, |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 3660 | es->state, es->flags, es->ev_id, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3661 | es->len, es->pos); |
| 3662 | break; |
| 3663 | } |
| 3664 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3665 | if (buffer_feed_chunk(si->ib, &msg) >= 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3666 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3667 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3668 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3669 | si->applet.ctx.errors.ptr = 0; |
| 3670 | si->applet.ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3671 | } |
| 3672 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3673 | if (si->applet.ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3674 | /* the snapshot changed while we were dumping it */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3675 | chunk_printf(&msg, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3676 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3677 | if (buffer_feed_chunk(si->ib, &msg) >= 0) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3678 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3679 | goto next; |
| 3680 | } |
| 3681 | |
| 3682 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3683 | 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] | 3684 | int newptr; |
| 3685 | int newline; |
| 3686 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3687 | newline = si->applet.ctx.errors.bol; |
| 3688 | newptr = dump_text_line(&msg, es->buf, sizeof(es->buf), es->len, &newline, si->applet.ctx.errors.ptr); |
| 3689 | if (newptr == si->applet.ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3690 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3691 | |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 3692 | if (buffer_feed_chunk(si->ib, &msg) >= 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3693 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3694 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3695 | } |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3696 | si->applet.ctx.errors.ptr = newptr; |
| 3697 | si->applet.ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3698 | }; |
| 3699 | next: |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 3700 | si->applet.ctx.errors.bol = 0; |
| 3701 | si->applet.ctx.errors.ptr = -1; |
| 3702 | si->applet.ctx.errors.buf++; |
| 3703 | if (si->applet.ctx.errors.buf > 1) { |
| 3704 | si->applet.ctx.errors.buf = 0; |
| 3705 | si->applet.ctx.errors.px = si->applet.ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3706 | } |
| 3707 | } |
| 3708 | |
| 3709 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3710 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3711 | } |
| 3712 | |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 3713 | struct si_applet http_stats_applet = { |
| 3714 | .name = "<STATS>", /* used for logging */ |
| 3715 | .fct = http_stats_io_handler, |
| 3716 | }; |
| 3717 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 3718 | static struct si_applet cli_applet = { |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 3719 | .name = "<CLI>", /* used for logging */ |
| 3720 | .fct = cli_io_handler, |
| 3721 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3722 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 3723 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 3724 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 3725 | { 0, NULL, NULL }, |
| 3726 | }}; |
| 3727 | |
| 3728 | __attribute__((constructor)) |
| 3729 | static void __dumpstats_module_init(void) |
| 3730 | { |
| 3731 | cfg_register_keywords(&cfg_kws); |
| 3732 | } |
| 3733 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3734 | /* |
| 3735 | * Local variables: |
| 3736 | * c-indent-level: 8 |
| 3737 | * c-basic-offset: 8 |
| 3738 | * End: |
| 3739 | */ |