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