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