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