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