Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Functions dedicated to statistics output |
| 3 | * |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 4 | * Copyright 2000-2009 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 | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 47 | #include <proto/pipe.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 48 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 49 | #include <proto/proxy.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 50 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 51 | #include <proto/server.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 52 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 53 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 54 | |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 55 | const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 56 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 57 | " 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] | 58 | " help : this message\n" |
| 59 | " prompt : toggle interactive mode with prompt\n" |
| 60 | " quit : disconnect\n" |
| 61 | " show info : report information about the running process\n" |
| 62 | " show stat : report counters for each proxy and server\n" |
| 63 | " show errors : report last request and response errors for each proxy\n" |
| 64 | " show sess : report the list of current sessions\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame^] | 65 | " get weight : report a server's current weight\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 66 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 67 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 68 | const char stats_permission_denied_msg[] = |
| 69 | "Permission denied\n" |
| 70 | ""; |
| 71 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 72 | /* This function parses a "stats" statement in the "global" section. It returns |
| 73 | * -1 if there is any error, otherwise zero. If it returns -1, it may write an |
| 74 | * error message into ther <err> buffer, for at most <errlen> bytes, trailing |
| 75 | * zero included. The trailing '\n' must not be written. The function must be |
| 76 | * called with <args> pointing to the first word after "stats". |
| 77 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 78 | static int stats_parse_global(char **args, int section_type, struct proxy *curpx, |
| 79 | struct proxy *defpx, char *err, int errlen) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 80 | { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 81 | args++; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 82 | if (!strcmp(args[0], "socket")) { |
| 83 | struct sockaddr_un su; |
| 84 | int cur_arg; |
| 85 | |
| 86 | if (*args[1] == 0) { |
| 87 | snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket"); |
| 88 | return -1; |
| 89 | } |
| 90 | |
| 91 | if (global.stats_sock.state != LI_NEW) { |
| 92 | snprintf(err, errlen, "'stats socket' already specified in global section"); |
| 93 | return -1; |
| 94 | } |
| 95 | |
| 96 | su.sun_family = AF_UNIX; |
| 97 | strncpy(su.sun_path, args[1], sizeof(su.sun_path)); |
| 98 | su.sun_path[sizeof(su.sun_path) - 1] = 0; |
| 99 | memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit |
| 100 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 101 | if (!global.stats_fe) { |
| 102 | if ((global.stats_fe = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 103 | snprintf(err, errlen, "out of memory"); |
| 104 | return -1; |
| 105 | } |
| 106 | |
| 107 | LIST_INIT(&global.stats_fe->pendconns); |
| 108 | LIST_INIT(&global.stats_fe->acl); |
| 109 | LIST_INIT(&global.stats_fe->block_cond); |
| 110 | LIST_INIT(&global.stats_fe->redirect_rules); |
| 111 | LIST_INIT(&global.stats_fe->mon_fail_cond); |
| 112 | LIST_INIT(&global.stats_fe->switching_rules); |
| 113 | LIST_INIT(&global.stats_fe->tcp_req.inspect_rules); |
| 114 | |
| 115 | /* Timeouts are defined as -1, so we cannot use the zeroed area |
| 116 | * as a default value. |
| 117 | */ |
| 118 | proxy_reset_timeouts(global.stats_fe); |
| 119 | |
| 120 | global.stats_fe->last_change = now.tv_sec; |
| 121 | global.stats_fe->id = strdup("GLOBAL"); |
| 122 | global.stats_fe->cap = PR_CAP_FE; |
| 123 | } |
| 124 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 125 | global.stats_sock.state = LI_INIT; |
Willy Tarreau | 6fb42e0 | 2007-10-28 17:02:33 +0100 | [diff] [blame] | 126 | global.stats_sock.options = LI_O_NONE; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 127 | global.stats_sock.accept = uxst_event_accept; |
Willy Tarreau | 104eb36 | 2009-08-16 18:51:29 +0200 | [diff] [blame] | 128 | global.stats_sock.handler = process_session; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 129 | global.stats_sock.analysers = 0; |
Willy Tarreau | 2c9f5b1 | 2009-08-16 19:12:36 +0200 | [diff] [blame] | 130 | global.stats_sock.nice = -64; /* we want to boost priority for local stats */ |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 131 | global.stats_sock.private = global.stats_fe; /* must point to the frontend */ |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 132 | global.stats_sock.perm.ux.level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 133 | |
| 134 | global.stats_fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
| 135 | global.stats_sock.timeout = &global.stats_fe->timeout.client; |
| 136 | |
| 137 | global.stats_sock.next = global.stats_fe->listen; |
| 138 | global.stats_fe->listen = &global.stats_sock; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 139 | |
| 140 | cur_arg = 2; |
| 141 | while (*args[cur_arg]) { |
| 142 | if (!strcmp(args[cur_arg], "uid")) { |
| 143 | global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]); |
| 144 | cur_arg += 2; |
| 145 | } |
| 146 | else if (!strcmp(args[cur_arg], "gid")) { |
| 147 | global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]); |
| 148 | cur_arg += 2; |
| 149 | } |
| 150 | else if (!strcmp(args[cur_arg], "mode")) { |
| 151 | global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 152 | cur_arg += 2; |
| 153 | } |
| 154 | else if (!strcmp(args[cur_arg], "user")) { |
| 155 | struct passwd *user; |
| 156 | user = getpwnam(args[cur_arg + 1]); |
| 157 | if (!user) { |
| 158 | snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')", |
| 159 | args[cur_arg + 1]); |
| 160 | return -1; |
| 161 | } |
| 162 | global.stats_sock.perm.ux.uid = user->pw_uid; |
| 163 | cur_arg += 2; |
| 164 | } |
| 165 | else if (!strcmp(args[cur_arg], "group")) { |
| 166 | struct group *group; |
| 167 | group = getgrnam(args[cur_arg + 1]); |
| 168 | if (!group) { |
| 169 | snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')", |
| 170 | args[cur_arg + 1]); |
| 171 | return -1; |
| 172 | } |
| 173 | global.stats_sock.perm.ux.gid = group->gr_gid; |
| 174 | cur_arg += 2; |
| 175 | } |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 176 | else if (!strcmp(args[cur_arg], "level")) { |
| 177 | if (!strcmp(args[cur_arg+1], "user")) |
| 178 | global.stats_sock.perm.ux.level = ACCESS_LVL_USER; |
| 179 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 180 | global.stats_sock.perm.ux.level = ACCESS_LVL_OPER; |
| 181 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 182 | global.stats_sock.perm.ux.level = ACCESS_LVL_ADMIN; |
| 183 | else { |
| 184 | snprintf(err, errlen, "'stats socket level' only supports 'user', 'operator', and 'admin'"); |
| 185 | return -1; |
| 186 | } |
| 187 | cur_arg += 2; |
| 188 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 189 | else { |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 190 | 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] | 191 | return -1; |
| 192 | } |
| 193 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 194 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 195 | uxst_add_listener(&global.stats_sock); |
| 196 | global.maxsock++; |
| 197 | } |
| 198 | else if (!strcmp(args[0], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 199 | unsigned timeout; |
| 200 | const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS); |
| 201 | |
| 202 | if (res) { |
| 203 | snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res); |
| 204 | return -1; |
| 205 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 206 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 207 | if (!timeout) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 208 | snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'"); |
| 209 | return -1; |
| 210 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 211 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 212 | } |
| 213 | else if (!strcmp(args[0], "maxconn")) { |
| 214 | int maxconn = atol(args[1]); |
| 215 | |
| 216 | if (maxconn <= 0) { |
| 217 | snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'"); |
| 218 | return -1; |
| 219 | } |
| 220 | global.maxsock -= global.stats_sock.maxconn; |
| 221 | global.stats_sock.maxconn = maxconn; |
| 222 | global.maxsock += global.stats_sock.maxconn; |
| 223 | } |
| 224 | else { |
| 225 | snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section"); |
| 226 | return -1; |
| 227 | } |
| 228 | return 0; |
| 229 | } |
| 230 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 231 | int print_csv_header(struct chunk *msg) |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 232 | { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 233 | return chunk_printf(msg, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 234 | "# pxname,svname," |
| 235 | "qcur,qmax," |
| 236 | "scur,smax,slim,stot," |
| 237 | "bin,bout," |
| 238 | "dreq,dresp," |
| 239 | "ereq,econ,eresp," |
| 240 | "wretr,wredis," |
| 241 | "status,weight,act,bck," |
| 242 | "chkfail,chkdown,lastchg,downtime,qlimit," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 243 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 244 | "rate,rate_lim,rate_max," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 245 | "check_status,check_code,check_duration," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 246 | "\n"); |
| 247 | } |
| 248 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 249 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 250 | * called from an applet running in a stream interface. The function returns 1 |
| 251 | * if the request was understood, otherwise zero. It sets si->st0 to a value |
| 252 | * designating the function which will have to process the request. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 253 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 254 | int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 255 | { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 256 | struct session *s = si->private; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 257 | char *args[MAX_STATS_ARGS + 1]; |
| 258 | int arg; |
| 259 | |
| 260 | while (isspace((unsigned char)*line)) |
| 261 | line++; |
| 262 | |
| 263 | arg = 0; |
| 264 | args[arg] = line; |
| 265 | |
| 266 | while (*line && arg < MAX_STATS_ARGS) { |
| 267 | if (isspace((unsigned char)*line)) { |
| 268 | *line++ = '\0'; |
| 269 | |
| 270 | while (isspace((unsigned char)*line)) |
| 271 | line++; |
| 272 | |
| 273 | args[++arg] = line; |
| 274 | continue; |
| 275 | } |
| 276 | |
| 277 | line++; |
| 278 | } |
| 279 | |
| 280 | while (++arg <= MAX_STATS_ARGS) |
| 281 | args[arg] = line; |
| 282 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 283 | s->data_ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 284 | if (strcmp(args[0], "show") == 0) { |
| 285 | if (strcmp(args[1], "stat") == 0) { |
| 286 | if (*args[2] && *args[3] && *args[4]) { |
| 287 | s->data_ctx.stats.flags |= STAT_BOUND; |
| 288 | s->data_ctx.stats.iid = atoi(args[2]); |
| 289 | s->data_ctx.stats.type = atoi(args[3]); |
| 290 | s->data_ctx.stats.sid = atoi(args[4]); |
| 291 | } |
| 292 | |
| 293 | s->data_ctx.stats.flags |= STAT_SHOW_STAT; |
| 294 | s->data_ctx.stats.flags |= STAT_FMT_CSV; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 295 | s->data_state = DATA_ST_INIT; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 296 | si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 297 | } |
| 298 | else if (strcmp(args[1], "info") == 0) { |
| 299 | s->data_ctx.stats.flags |= STAT_SHOW_INFO; |
| 300 | s->data_ctx.stats.flags |= STAT_FMT_CSV; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 301 | s->data_state = DATA_ST_INIT; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 302 | si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 303 | } |
| 304 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 305 | s->data_state = DATA_ST_INIT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 306 | if (s->listener->perm.ux.level < ACCESS_LVL_OPER) { |
Willy Tarreau | 9bcc91e | 2009-10-10 18:01:44 +0200 | [diff] [blame] | 307 | buffer_feed(si->ib, stats_permission_denied_msg); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 308 | return 1; |
| 309 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 310 | si->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 311 | } |
| 312 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 313 | if (s->listener->perm.ux.level < ACCESS_LVL_OPER) { |
Willy Tarreau | 9bcc91e | 2009-10-10 18:01:44 +0200 | [diff] [blame] | 314 | buffer_feed(si->ib, stats_permission_denied_msg); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 315 | return 1; |
| 316 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 317 | if (*args[2]) |
| 318 | s->data_ctx.errors.iid = atoi(args[2]); |
| 319 | else |
| 320 | s->data_ctx.errors.iid = -1; |
| 321 | s->data_ctx.errors.px = NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 322 | s->data_state = DATA_ST_INIT; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 323 | si->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 324 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 325 | else { /* neither "stat" nor "info" nor "sess" nor "errors"*/ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 326 | return 0; |
| 327 | } |
| 328 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 329 | else if (strcmp(args[0], "clear") == 0) { |
| 330 | if (strcmp(args[1], "counters") == 0) { |
| 331 | struct proxy *px; |
| 332 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 333 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 334 | int clrall = 0; |
| 335 | |
| 336 | if (strcmp(args[2], "all") == 0) |
| 337 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 338 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 339 | /* check permissions */ |
| 340 | if (s->listener->perm.ux.level < ACCESS_LVL_OPER || |
| 341 | (clrall && s->listener->perm.ux.level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 9bcc91e | 2009-10-10 18:01:44 +0200 | [diff] [blame] | 342 | buffer_feed(si->ib, stats_permission_denied_msg); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 343 | return 1; |
| 344 | } |
| 345 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 346 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 347 | if (clrall) |
| 348 | memset(&px->counters, 0, sizeof(px->counters)); |
| 349 | else { |
| 350 | px->counters.feconn_max = 0; |
| 351 | px->counters.beconn_max = 0; |
| 352 | px->counters.fe_sps_max = 0; |
| 353 | px->counters.be_sps_max = 0; |
| 354 | px->counters.nbpend_max = 0; |
| 355 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 356 | |
| 357 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 358 | if (clrall) |
| 359 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 360 | else { |
| 361 | sv->counters.cur_sess_max = 0; |
| 362 | sv->counters.nbpend_max = 0; |
| 363 | sv->counters.sps_max = 0; |
| 364 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 365 | |
| 366 | for (li = px->listen; li; li = li->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 367 | if (li->counters) { |
| 368 | if (clrall) |
| 369 | memset(li->counters, 0, sizeof(*li->counters)); |
| 370 | else |
| 371 | li->counters->conn_max = 0; |
| 372 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | return 1; |
| 376 | } |
| 377 | else { |
| 378 | return 0; |
| 379 | } |
| 380 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame^] | 381 | else if (strcmp(args[0], "get") == 0) { |
| 382 | if (strcmp(args[1], "weight") == 0) { |
| 383 | struct proxy *px; |
| 384 | struct server *sv; |
| 385 | |
| 386 | /* split "backend/server" and make <line> point to server */ |
| 387 | for (line = args[2]; *line; line++) |
| 388 | if (*line == '/') { |
| 389 | *line++ = '\0'; |
| 390 | break; |
| 391 | } |
| 392 | |
| 393 | if (!*line) { |
| 394 | buffer_feed(si->ib, "Require 'backend/server'.\n"); |
| 395 | return 1; |
| 396 | } |
| 397 | |
| 398 | if (!get_backend_server(args[2], line, &px, &sv)) { |
| 399 | if (!px) |
| 400 | buffer_feed(si->ib, "No such backend.\n"); |
| 401 | else |
| 402 | buffer_feed(si->ib, "No such server.\n"); |
| 403 | return 1; |
| 404 | } |
| 405 | |
| 406 | /* return server's effective weight at the moment */ |
| 407 | snprintf(trash, sizeof(trash), "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 408 | buffer_feed(si->ib, trash); |
| 409 | return 1; |
| 410 | } |
| 411 | else { /* not "get weight" */ |
| 412 | return 0; |
| 413 | } |
| 414 | } |
| 415 | else { /* not "show" nor "clear" nor "get" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 416 | return 0; |
| 417 | } |
| 418 | return 1; |
| 419 | } |
| 420 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 421 | /* 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] | 422 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 423 | * state machine handling requests and various responses. We read a request, |
| 424 | * then we process it and send the response, and we possibly display a prompt. |
| 425 | * Then we can read again. The state is stored in si->st0 and is one of the |
| 426 | * STAT_CLI_* constants. si->st1 is used to indicate whether prompt is enabled |
| 427 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 428 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 429 | void stats_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 430 | { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 431 | struct session *s = si->private; |
| 432 | struct buffer *req = si->ob; |
| 433 | struct buffer *res = si->ib; |
| 434 | int reql; |
| 435 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 436 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 437 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 438 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 439 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 440 | while (1) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 441 | if (si->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 442 | /* Stats output not initialized yet */ |
| 443 | memset(&s->data_ctx.stats, 0, sizeof(s->data_ctx.stats)); |
| 444 | s->data_source = DATA_SRC_STATS; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 445 | si->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 446 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 447 | else if (si->st0 == STAT_CLI_END) { |
| 448 | /* Let's close for real now. We just close the request |
| 449 | * side, the conditions below will complete if needed. |
| 450 | */ |
| 451 | si->shutw(si); |
| 452 | break; |
| 453 | } |
| 454 | else if (si->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 455 | reql = buffer_si_peekline(si->ob, trash, sizeof(trash)); |
| 456 | if (reql <= 0) { /* closed or EOL not found */ |
| 457 | if (reql == 0) |
| 458 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 459 | si->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 460 | continue; |
| 461 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 462 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 463 | /* seek for a possible semi-colon. If we find one, we |
| 464 | * replace it with an LF and skip only this part. |
| 465 | */ |
| 466 | for (len = 0; len < reql; len++) |
| 467 | if (trash[len] == ';') { |
| 468 | trash[len] = '\n'; |
| 469 | reql = len + 1; |
| 470 | break; |
| 471 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 472 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 473 | /* now it is time to check that we have a full line, |
| 474 | * remove the trailing \n and possibly \r, then cut the |
| 475 | * line. |
| 476 | */ |
| 477 | len = reql - 1; |
| 478 | if (trash[len] != '\n') { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 479 | si->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 480 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 481 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 482 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 483 | if (len && trash[len-1] == '\r') |
| 484 | len--; |
| 485 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 486 | trash[len] = '\0'; |
| 487 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 488 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 489 | if (len) { |
| 490 | if (strcmp(trash, "quit") == 0) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 491 | si->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 492 | continue; |
| 493 | } |
| 494 | else if (strcmp(trash, "prompt") == 0) |
| 495 | si->st1 = !si->st1; |
| 496 | else if (strcmp(trash, "help") == 0 || |
| 497 | !stats_sock_parse_request(si, trash)) |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 498 | si->st0 = STAT_CLI_O_HELP; |
| 499 | /* NB: stats_sock_parse_request() may have put |
| 500 | * another STAT_CLI_O_* into si->st0. |
| 501 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 502 | } |
| 503 | else if (!si->st1) { |
| 504 | /* if prompt is disabled, print help on empty lines, |
| 505 | * so that the user at least knows how to enable |
| 506 | * prompt and find help. |
| 507 | */ |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 508 | si->st0 = STAT_CLI_O_HELP; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /* re-adjust req buffer */ |
| 512 | buffer_skip(si->ob, reql); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 513 | req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 514 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 515 | 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] | 516 | if (res->flags & (BF_SHUTR_NOW|BF_SHUTR)) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 517 | si->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 518 | continue; |
| 519 | } |
| 520 | |
| 521 | switch (si->st0) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 522 | case STAT_CLI_O_HELP: |
Willy Tarreau | 9bcc91e | 2009-10-10 18:01:44 +0200 | [diff] [blame] | 523 | if (buffer_feed(si->ib, stats_sock_usage_msg) < 0) |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 524 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 525 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 526 | case STAT_CLI_O_INFO: |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 527 | if (stats_dump_raw_to_buffer(s, res)) |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 528 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 529 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 530 | case STAT_CLI_O_SESS: |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 531 | if (stats_dump_sess_to_buffer(s, res)) |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 532 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 533 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 534 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 535 | if (stats_dump_errors_to_buffer(s, res)) |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 536 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 537 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 538 | default: /* abnormal state */ |
| 539 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 540 | break; |
| 541 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 542 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 543 | /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */ |
| 544 | if (si->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 9bcc91e | 2009-10-10 18:01:44 +0200 | [diff] [blame] | 545 | if (buffer_feed(si->ib, si->st1 ? "\n> " : "\n") < 0) |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 546 | si->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 547 | } |
| 548 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 549 | /* 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] | 550 | if (si->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 551 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 552 | |
| 553 | /* Now we close the output if one of the writers did so, |
| 554 | * or if we're not in interactive mode and the request |
| 555 | * buffer is empty. This still allows pipelined requests |
| 556 | * to be sent in non-interactive mode. |
| 557 | */ |
| 558 | 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] | 559 | si->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 560 | continue; |
| 561 | } |
| 562 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 563 | /* switch state back to GETREQ to read next requests */ |
| 564 | si->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 565 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 566 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 567 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 568 | 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] | 569 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 570 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 571 | /* Other size has closed, let's abort if we have no more processing to do |
| 572 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 573 | * we forward the close to the request side so that it flows upstream to |
| 574 | * the client. |
| 575 | */ |
| 576 | si->shutw(si); |
| 577 | } |
| 578 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 579 | 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] | 580 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 581 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 582 | /* We have no more processing to do, and nothing more to send, and |
| 583 | * the client side has closed. So we'll forward this state downstream |
| 584 | * on the response buffer. |
| 585 | */ |
| 586 | si->shutr(si); |
| 587 | res->flags |= BF_READ_NULL; |
| 588 | } |
| 589 | |
| 590 | /* update all other flags and resync with the other side */ |
| 591 | si->update(si); |
| 592 | |
| 593 | /* we don't want to expire timeouts while we're processing requests */ |
| 594 | si->ib->rex = TICK_ETERNITY; |
| 595 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 596 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 597 | out: |
| 598 | DPRINTF(stderr, "%s@%d: st=%d, rqf=%x, rpf=%x, rql=%d, rqs=%d, rl=%d, rs=%d\n", |
| 599 | __FUNCTION__, __LINE__, |
| 600 | si->state, req->flags, res->flags, req->l, req->send_max, res->l, res->send_max); |
| 601 | |
| 602 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 603 | /* check that we have released everything then unregister */ |
| 604 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 605 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 606 | } |
| 607 | |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 608 | /* This function is called to send output to the response buffer. |
| 609 | * It dumps statistics onto the output buffer <rep> owned by session <s>. |
| 610 | * s->data_ctx must have been zeroed first, and the flags properly set. |
| 611 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 612 | * Some states are not used but it makes the code more similar to other |
| 613 | * functions which handle stats too. |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 614 | */ |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 615 | int stats_dump_raw_to_buffer(struct session *s, struct buffer *rep) |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 616 | { |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 617 | struct proxy *px; |
| 618 | struct chunk msg; |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 619 | unsigned int up; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 620 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 621 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 622 | |
| 623 | switch (s->data_state) { |
| 624 | case DATA_ST_INIT: |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 625 | /* the function had not been called yet */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 626 | s->data_state = DATA_ST_HEAD; |
| 627 | /* fall through */ |
| 628 | |
| 629 | case DATA_ST_HEAD: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 630 | if (s->data_ctx.stats.flags & STAT_SHOW_STAT) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 631 | print_csv_header(&msg); |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 632 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 633 | return 0; |
| 634 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 635 | |
| 636 | s->data_state = DATA_ST_INFO; |
| 637 | /* fall through */ |
| 638 | |
| 639 | case DATA_ST_INFO: |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 640 | up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 641 | if (s->data_ctx.stats.flags & STAT_SHOW_INFO) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 642 | chunk_printf(&msg, |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 643 | "Name: " PRODUCT_NAME "\n" |
| 644 | "Version: " HAPROXY_VERSION "\n" |
| 645 | "Release_date: " HAPROXY_DATE "\n" |
| 646 | "Nbproc: %d\n" |
| 647 | "Process_num: %d\n" |
| 648 | "Pid: %d\n" |
| 649 | "Uptime: %dd %dh%02dm%02ds\n" |
| 650 | "Uptime_sec: %d\n" |
| 651 | "Memmax_MB: %d\n" |
| 652 | "Ulimit-n: %d\n" |
| 653 | "Maxsock: %d\n" |
| 654 | "Maxconn: %d\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 655 | "Maxpipes: %d\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 656 | "CurrConns: %d\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 657 | "PipesUsed: %d\n" |
| 658 | "PipesFree: %d\n" |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 659 | "Tasks: %d\n" |
| 660 | "Run_queue: %d\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 661 | "node: %s\n" |
| 662 | "description: %s\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 663 | "", |
| 664 | global.nbproc, |
| 665 | relative_pid, |
| 666 | pid, |
| 667 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 668 | up, |
| 669 | global.rlimit_memmax, |
| 670 | global.rlimit_nofile, |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 671 | global.maxsock, global.maxconn, global.maxpipes, |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 672 | actconn, pipes_used, pipes_free, |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 673 | nb_tasks_cur, run_queue_cur, |
| 674 | global.node, global.desc?global.desc:"" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 675 | ); |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 676 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 680 | s->data_ctx.stats.px = proxy; |
| 681 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 682 | |
| 683 | s->data_ctx.stats.sv = NULL; |
| 684 | s->data_ctx.stats.sv_st = 0; |
| 685 | |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 686 | s->data_state = DATA_ST_LIST; |
| 687 | /* fall through */ |
| 688 | |
| 689 | case DATA_ST_LIST: |
| 690 | /* dump proxies */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 691 | if (s->data_ctx.stats.flags & STAT_SHOW_STAT) { |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 692 | while (s->data_ctx.stats.px) { |
| 693 | px = s->data_ctx.stats.px; |
| 694 | /* skip the disabled proxies and non-networked ones */ |
| 695 | if (px->state != PR_STSTOPPED && |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 696 | (px->cap & (PR_CAP_FE | PR_CAP_BE))) { |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 697 | if (stats_dump_proxy(s, px, NULL) == 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 698 | return 0; |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 699 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 700 | |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 701 | s->data_ctx.stats.px = px->next; |
| 702 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 703 | } |
| 704 | /* here, we just have reached the last proxy */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 705 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 706 | |
| 707 | s->data_state = DATA_ST_END; |
| 708 | /* fall through */ |
| 709 | |
| 710 | case DATA_ST_END: |
| 711 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 712 | /* fall through */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 713 | |
| 714 | case DATA_ST_FIN: |
| 715 | return 1; |
| 716 | |
| 717 | default: |
| 718 | /* unknown state ! */ |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 719 | s->data_state = DATA_ST_FIN; |
| 720 | return 1; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 721 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 725 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 726 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
| 727 | * si->st0 becomes non-zero once the transfer is finished. The handler |
| 728 | * automatically unregisters itself once transfer is complete. |
| 729 | */ |
| 730 | void http_stats_io_handler(struct stream_interface *si) |
| 731 | { |
| 732 | struct session *s = si->private; |
| 733 | struct buffer *req = si->ob; |
| 734 | struct buffer *res = si->ib; |
| 735 | |
| 736 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 737 | goto out; |
| 738 | |
| 739 | /* check that the output is not closed */ |
| 740 | if (res->flags & (BF_SHUTW|BF_SHUTW_NOW)) |
| 741 | si->st0 = 1; |
| 742 | |
| 743 | if (!si->st0) { |
| 744 | if (stats_dump_http(s, res, s->be->uri_auth)) { |
| 745 | si->st0 = 1; |
| 746 | si->shutw(si); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
| 750 | if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST)) |
| 751 | si->shutw(si); |
| 752 | |
| 753 | if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && si->st0) { |
| 754 | si->shutr(si); |
| 755 | res->flags |= BF_READ_NULL; |
| 756 | } |
| 757 | |
| 758 | /* update all other flags and resync with the other side */ |
| 759 | si->update(si); |
| 760 | |
| 761 | /* we don't want to expire timeouts while we're processing requests */ |
| 762 | si->ib->rex = TICK_ETERNITY; |
| 763 | si->ob->wex = TICK_ETERNITY; |
| 764 | |
| 765 | out: |
| 766 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 767 | /* check that we have released everything then unregister */ |
| 768 | stream_int_unregister_handler(si); |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 773 | /* |
| 774 | * Produces statistics data for the session <s>. Expects to be called with |
Willy Tarreau | 1ae3a05 | 2008-08-16 10:56:30 +0200 | [diff] [blame] | 775 | * 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] | 776 | * 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] | 777 | * when there is free space in the buffer, of simply by letting an empty buffer |
| 778 | * upon return.s->data_ctx must have been zeroed before the first call, and the |
| 779 | * flags set. It returns 0 if it had to stop writing data and an I/O is needed, |
| 780 | * 1 if the dump is finished and the session must be closed, or -1 in case of |
| 781 | * any error. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 782 | */ |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 783 | 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] | 784 | { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 785 | struct proxy *px; |
| 786 | struct chunk msg; |
| 787 | unsigned int up; |
| 788 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 789 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 790 | |
| 791 | switch (s->data_state) { |
| 792 | case DATA_ST_INIT: |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 793 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 794 | "HTTP/1.0 200 OK\r\n" |
| 795 | "Cache-Control: no-cache\r\n" |
| 796 | "Connection: close\r\n" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 797 | "Content-Type: %s\r\n", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 798 | (s->data_ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 799 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 800 | 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] | 801 | chunk_printf(&msg, "Refresh: %d\r\n", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 802 | uri->refresh); |
| 803 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 804 | chunk_printf(&msg, "\r\n"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 805 | |
| 806 | s->txn.status = 200; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 807 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 56a560a | 2009-09-22 19:27:35 +0200 | [diff] [blame] | 808 | return 0; |
| 809 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 810 | if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is |
| 811 | s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy |
| 812 | if (!(s->flags & SN_FINST_MASK)) |
| 813 | s->flags |= SN_FINST_R; |
| 814 | |
| 815 | if (s->txn.meth == HTTP_METH_HEAD) { |
| 816 | /* that's all we return in case of HEAD request */ |
| 817 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 818 | return 1; |
| 819 | } |
| 820 | |
| 821 | s->data_state = DATA_ST_HEAD; /* let's start producing data */ |
| 822 | /* fall through */ |
| 823 | |
| 824 | case DATA_ST_HEAD: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 825 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 826 | /* WARNING! This must fit in the first buffer !!! */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 827 | chunk_printf(&msg, |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 828 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 829 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 830 | "<style type=\"text/css\"><!--\n" |
| 831 | "body {" |
Willy Tarreau | a94f2d2 | 2009-05-10 20:08:10 +0200 | [diff] [blame] | 832 | " font-family: arial, helvetica, sans-serif;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 833 | " font-size: 12px;" |
| 834 | " font-weight: normal;" |
| 835 | " color: black;" |
| 836 | " background: white;" |
| 837 | "}\n" |
| 838 | "th,td {" |
Willy Tarreau | a94f2d2 | 2009-05-10 20:08:10 +0200 | [diff] [blame] | 839 | " font-size: 10px;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 840 | " align: center;" |
| 841 | "}\n" |
| 842 | "h1 {" |
Willy Tarreau | da6721b | 2009-07-15 10:07:05 +0200 | [diff] [blame] | 843 | " font-size: x-large;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 844 | " margin-bottom: 0.5em;" |
| 845 | "}\n" |
| 846 | "h2 {" |
| 847 | " font-family: helvetica, arial;" |
| 848 | " font-size: x-large;" |
| 849 | " font-weight: bold;" |
| 850 | " font-style: italic;" |
| 851 | " color: #6020a0;" |
| 852 | " margin-top: 0em;" |
| 853 | " margin-bottom: 0em;" |
| 854 | "}\n" |
| 855 | "h3 {" |
| 856 | " font-family: helvetica, arial;" |
| 857 | " font-size: 16px;" |
| 858 | " font-weight: bold;" |
| 859 | " color: #b00040;" |
| 860 | " background: #e8e8d0;" |
| 861 | " margin-top: 0em;" |
| 862 | " margin-bottom: 0em;" |
| 863 | "}\n" |
| 864 | "li {" |
| 865 | " margin-top: 0.25em;" |
| 866 | " margin-right: 2em;" |
| 867 | "}\n" |
| 868 | ".hr {margin-top: 0.25em;" |
| 869 | " border-color: black;" |
| 870 | " border-bottom-style: solid;" |
| 871 | "}\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 872 | ".titre {background: #20D0D0;color: #000000; font-weight: bold;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 873 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 874 | ".frontend {background: #e8e8d0;}\n" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 875 | ".socket {background: #d0d0d0;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 876 | ".backend {background: #e8e8d0;}\n" |
| 877 | ".active0 {background: #ff9090;}\n" |
| 878 | ".active1 {background: #ffd020;}\n" |
| 879 | ".active2 {background: #ffffa0;}\n" |
| 880 | ".active3 {background: #c0ffc0;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 881 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 882 | ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */ |
| 883 | ".active6 {background: #e0e0e0;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 884 | ".backup0 {background: #ff9090;}\n" |
| 885 | ".backup1 {background: #ff80ff;}\n" |
| 886 | ".backup2 {background: #c060ff;}\n" |
| 887 | ".backup3 {background: #b0d0ff;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 888 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 889 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 890 | ".backup6 {background: #e0e0e0;}\n" |
Willy Tarreau | da6721b | 2009-07-15 10:07:05 +0200 | [diff] [blame] | 891 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 892 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 893 | "table.tbl td { border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray;}\n" |
| 894 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
Krzysztof Piotr Oledzki | 619caca | 2009-10-03 15:46:08 +0200 | [diff] [blame] | 895 | "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] | 896 | "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] | 897 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 898 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 899 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 900 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
| 901 | "-->\n" |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 902 | "</style></head>\n", |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 903 | (uri->flags&ST_SHNODE) ? " on " : "", |
| 904 | (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 905 | ); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 906 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 907 | print_csv_header(&msg); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 908 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 909 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 910 | return 0; |
| 911 | |
| 912 | s->data_state = DATA_ST_INFO; |
| 913 | /* fall through */ |
| 914 | |
| 915 | case DATA_ST_INFO: |
| 916 | up = (now.tv_sec - start_date.tv_sec); |
| 917 | |
| 918 | /* WARNING! this has to fit the first packet too. |
| 919 | * We are around 3.5 kB, add adding entries will |
| 920 | * become tricky if we want to support 4kB buffers ! |
| 921 | */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 922 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 923 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 924 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 925 | PRODUCT_NAME "%s</a></h1>\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 926 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 927 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 928 | "<h3>> General process information</h3>\n" |
| 929 | "<table border=0 cols=4><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 930 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 931 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 932 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 933 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 934 | "current conns = %d; current pipes = %d/%d<br>\n" |
| 935 | "Running tasks: %d/%d<br>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 936 | "</td><td align=\"center\" nowrap>\n" |
| 937 | "<table class=\"lgd\"><tr>\n" |
| 938 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 939 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 940 | "</tr><tr>\n" |
| 941 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 942 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 943 | "</tr><tr>\n" |
| 944 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 945 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 946 | "</tr><tr>\n" |
| 947 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 948 | "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 949 | "</tr></table>\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 950 | "Note: UP with load-balancing disabled is reported as \"NOLB\"." |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 951 | "</td>" |
| 952 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 953 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 954 | "", |
| 955 | (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING), |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 956 | pid, (uri->flags&ST_SHNODE) ? " on " : "", (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 957 | (uri->flags&ST_SHDESC)? ": " : "", (uri->flags&ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 958 | pid, relative_pid, global.nbproc, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 959 | up / 86400, (up % 86400) / 3600, |
| 960 | (up % 3600) / 60, (up % 60), |
| 961 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 962 | global.rlimit_memmax ? " MB" : "", |
| 963 | global.rlimit_nofile, |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 964 | global.maxsock, global.maxconn, global.maxpipes, |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 965 | actconn, pipes_used, pipes_used+pipes_free, |
| 966 | run_queue_cur, nb_tasks_cur |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 967 | ); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 968 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 969 | if (s->data_ctx.stats.flags & STAT_HIDE_DOWN) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 970 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 971 | "<li><a href=\"%s%s%s\">Show all servers</a><br>\n", |
| 972 | uri->uri_prefix, |
| 973 | "", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 974 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 975 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 976 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 977 | "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 978 | uri->uri_prefix, |
| 979 | ";up", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 980 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 981 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 982 | if (uri->refresh > 0) { |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 983 | if (s->data_ctx.stats.flags & STAT_NO_REFRESH) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 984 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 985 | "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n", |
| 986 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 987 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 988 | ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 989 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 990 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 991 | "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n", |
| 992 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 993 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 994 | ";norefresh"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 995 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 996 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 997 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 998 | "<li><a href=\"%s%s%s\">Refresh now</a><br>\n", |
| 999 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1000 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 1001 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1002 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1003 | chunk_printf(&msg, |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 1004 | "<li><a href=\"%s;csv%s\">CSV export</a><br>\n", |
| 1005 | uri->uri_prefix, |
| 1006 | (uri->refresh > 0) ? ";norefresh" : ""); |
| 1007 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1008 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1009 | "</td>" |
| 1010 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 1011 | "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 1012 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 1013 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 1014 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 1015 | "</ul>" |
| 1016 | "</td>" |
| 1017 | "</tr></table>\n" |
| 1018 | "" |
| 1019 | ); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1020 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1021 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1022 | return 0; |
| 1023 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1024 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1025 | s->data_ctx.stats.px = proxy; |
| 1026 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 1027 | s->data_state = DATA_ST_LIST; |
| 1028 | /* fall through */ |
| 1029 | |
| 1030 | case DATA_ST_LIST: |
| 1031 | /* dump proxies */ |
| 1032 | while (s->data_ctx.stats.px) { |
| 1033 | px = s->data_ctx.stats.px; |
| 1034 | /* skip the disabled proxies and non-networked ones */ |
| 1035 | 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] | 1036 | if (stats_dump_proxy(s, px, uri) == 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1037 | return 0; |
| 1038 | |
| 1039 | s->data_ctx.stats.px = px->next; |
| 1040 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 1041 | } |
| 1042 | /* here, we just have reached the last proxy */ |
| 1043 | |
| 1044 | s->data_state = DATA_ST_END; |
| 1045 | /* fall through */ |
| 1046 | |
| 1047 | case DATA_ST_END: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1048 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1049 | chunk_printf(&msg, "</body></html>\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1050 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1051 | return 0; |
| 1052 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1053 | |
| 1054 | s->data_state = DATA_ST_FIN; |
| 1055 | /* fall through */ |
| 1056 | |
| 1057 | case DATA_ST_FIN: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1058 | return 1; |
| 1059 | |
| 1060 | default: |
| 1061 | /* unknown state ! */ |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1062 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1063 | return -1; |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | /* |
| 1069 | * Dumps statistics for a proxy. |
| 1070 | * Returns 0 if it had to stop dumping data because of lack of buffer space, |
| 1071 | * ot non-zero if everything completed. |
| 1072 | */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1073 | 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] | 1074 | { |
| 1075 | struct buffer *rep = s->rep; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1076 | 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] | 1077 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1078 | struct chunk msg; |
| 1079 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1080 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1081 | |
| 1082 | switch (s->data_ctx.stats.px_st) { |
| 1083 | case DATA_ST_PX_INIT: |
| 1084 | /* we are on a new proxy */ |
| 1085 | |
| 1086 | if (uri && uri->scope) { |
| 1087 | /* we have a limited scope, we have to check the proxy name */ |
| 1088 | struct stat_scope *scope; |
| 1089 | int len; |
| 1090 | |
| 1091 | len = strlen(px->id); |
| 1092 | scope = uri->scope; |
| 1093 | |
| 1094 | while (scope) { |
| 1095 | /* match exact proxy name */ |
| 1096 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 1097 | break; |
| 1098 | |
| 1099 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 1100 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1101 | break; |
| 1102 | scope = scope->next; |
| 1103 | } |
| 1104 | |
| 1105 | /* proxy name not found : don't dump anything */ |
| 1106 | if (scope == NULL) |
| 1107 | return 1; |
| 1108 | } |
| 1109 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1110 | 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] | 1111 | (px->uuid != s->data_ctx.stats.iid)) |
| 1112 | return 1; |
| 1113 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1114 | s->data_ctx.stats.px_st = DATA_ST_PX_TH; |
| 1115 | /* fall through */ |
| 1116 | |
| 1117 | case DATA_ST_PX_TH: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1118 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1119 | /* print a new table */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1120 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1121 | "<table class=\"tbl\" width=\"100%%\">\n" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1122 | "<tr align=\"center\" class=\"titre\">" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1123 | "<th class=\"pxname\" width=\"10%%\">%s</th>" |
| 1124 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1125 | "</tr>\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1126 | "</table>\n" |
| 1127 | "<table cols=\"29\" class=\"tbl\" width=\"100%%\">\n" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1128 | "<tr align=\"center\" class=\"titre\">" |
| 1129 | "<th rowspan=2></th>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1130 | "<th colspan=3>Queue</th>" |
| 1131 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1132 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1133 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1134 | "<th colspan=9>Server</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1135 | "</tr>\n" |
| 1136 | "<tr align=\"center\" class=\"titre\">" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1137 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1138 | "<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] | 1139 | "<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] | 1140 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1141 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1142 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1143 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 1144 | "<th>Thrtle</th>\n" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1145 | "</tr>", |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1146 | px->id, |
| 1147 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1148 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1149 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1150 | return 0; |
| 1151 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1152 | |
| 1153 | s->data_ctx.stats.px_st = DATA_ST_PX_FE; |
| 1154 | /* fall through */ |
| 1155 | |
| 1156 | case DATA_ST_PX_FE: |
| 1157 | /* print the frontend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1158 | if ((px->cap & PR_CAP_FE) && |
| 1159 | (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_FE)))) { |
| 1160 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1161 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1162 | /* name, queue */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1163 | "<tr align=center class=\"frontend\"><td>Frontend</td><td colspan=3></td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1164 | /* sessions rate : current, max, limit */ |
| 1165 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
| 1166 | /* sessions : current, max, limit, total, lbtot */ |
| 1167 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1168 | "<td align=right>%s</td><td align=right></td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1169 | /* bytes : in, out */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1170 | "<td align=right>%s</td><td align=right>%s</td>" |
| 1171 | "", |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1172 | U2H0(read_freq_ctr(&px->fe_sess_per_sec)), |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 1173 | U2H1(px->counters.fe_sps_max), LIM2A2(px->fe_sps_lim, "-"), |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1174 | U2H3(px->feconn), U2H4(px->counters.feconn_max), U2H5(px->maxconn), |
| 1175 | U2H6(px->counters.cum_feconn), U2H7(px->counters.bytes_in), U2H8(px->counters.bytes_out)); |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1176 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1177 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1178 | /* denied: req, resp */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1179 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1180 | /* errors : request, connect, response */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1181 | "<td align=right>%s</td><td align=right></td><td align=right></td>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1182 | /* warnings: retries, redispatches */ |
| 1183 | "<td align=right></td><td align=right></td>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1184 | /* server status : reflect frontend status */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1185 | "<td align=center>%s</td>" |
| 1186 | /* rest of server: nothing */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1187 | "<td align=center colspan=8></td></tr>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1188 | "", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1189 | U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp), |
| 1190 | U2H2(px->counters.failed_req), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1191 | px->state == PR_STRUN ? "OPEN" : |
| 1192 | px->state == PR_STIDLE ? "FULL" : "STOP"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1193 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1194 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1195 | /* pxid, name, queue cur, queue max, */ |
| 1196 | "%s,FRONTEND,,," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1197 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1198 | "%d,%d,%d,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1199 | /* bytes : in, out */ |
| 1200 | "%lld,%lld," |
| 1201 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1202 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1203 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1204 | "%lld,,," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1205 | /* warnings: retries, redispatches */ |
| 1206 | ",," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1207 | /* server status : reflect frontend status */ |
| 1208 | "%s," |
| 1209 | /* rest of server: nothing */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1210 | ",,,,,,,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1211 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 1212 | "%d,%d,0,,,,%d," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1213 | /* rate, rate_lim, rate_max */ |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 1214 | "%u,%u,%u," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1215 | /* check_status, check_code, check_duration */ |
| 1216 | ",,," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1217 | "\n", |
| 1218 | px->id, |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1219 | px->feconn, px->counters.feconn_max, px->maxconn, px->counters.cum_feconn, |
| 1220 | px->counters.bytes_in, px->counters.bytes_out, |
| 1221 | px->counters.denied_req, px->counters.denied_resp, |
| 1222 | px->counters.failed_req, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1223 | px->state == PR_STRUN ? "OPEN" : |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 1224 | px->state == PR_STIDLE ? "FULL" : "STOP", |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 1225 | relative_pid, px->uuid, STATS_TYPE_FE, |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 1226 | read_freq_ctr(&px->fe_sess_per_sec), |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 1227 | px->fe_sps_lim, px->counters.fe_sps_max); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1228 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1229 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1230 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1231 | return 0; |
| 1232 | } |
| 1233 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1234 | s->data_ctx.stats.l = px->listen; /* may be NULL */ |
| 1235 | s->data_ctx.stats.px_st = DATA_ST_PX_LI; |
| 1236 | /* fall through */ |
| 1237 | |
| 1238 | case DATA_ST_PX_LI: |
| 1239 | /* stats.l has been initialized above */ |
| 1240 | for (; s->data_ctx.stats.l != NULL; s->data_ctx.stats.l = l->next) { |
| 1241 | l = s->data_ctx.stats.l; |
| 1242 | if (!l->counters) |
| 1243 | continue; |
| 1244 | |
| 1245 | if (s->data_ctx.stats.flags & STAT_BOUND) { |
| 1246 | if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SO))) |
| 1247 | break; |
| 1248 | |
| 1249 | if (s->data_ctx.stats.sid != -1 && l->luid != s->data_ctx.stats.sid) |
| 1250 | continue; |
| 1251 | } |
| 1252 | |
| 1253 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
| 1254 | chunk_printf(&msg, |
| 1255 | /* name, queue */ |
| 1256 | "<tr align=center class=\"socket\"><td>%s</td><td colspan=3></td>" |
| 1257 | /* sessions rate: current, max, limit */ |
| 1258 | "<td align=right colspan=3> </td>" |
| 1259 | /* sessions: current, max, limit, total, lbtot */ |
| 1260 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
| 1261 | "<td align=right>%s</td><td align=right> </td>" |
| 1262 | /* bytes: in, out */ |
| 1263 | "<td align=right>%s</td><td align=right>%s</td>" |
| 1264 | "", |
| 1265 | l->name, |
| 1266 | U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn), |
| 1267 | U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out)); |
| 1268 | |
| 1269 | chunk_printf(&msg, |
| 1270 | /* denied: req, resp */ |
| 1271 | "<td align=right>%s</td><td align=right>%s</td>" |
| 1272 | /* errors: request, connect, response */ |
| 1273 | "<td align=right>%s</td><td align=right></td><td align=right></td>" |
| 1274 | /* warnings: retries, redispatches */ |
| 1275 | "<td align=right></td><td align=right></td>" |
| 1276 | /* server status: reflect listener status */ |
| 1277 | "<td align=center>%s</td>" |
| 1278 | /* rest of server: nothing */ |
| 1279 | "<td align=center colspan=8></td></tr>" |
| 1280 | "", |
| 1281 | U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp), |
| 1282 | U2H2(l->counters->failed_req), |
| 1283 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL"); |
| 1284 | } else { |
| 1285 | chunk_printf(&msg, |
| 1286 | /* pxid, name, queue cur, queue max, */ |
| 1287 | "%s,%s,,," |
| 1288 | /* sessions: current, max, limit, total */ |
| 1289 | "%d,%d,%d,%lld," |
| 1290 | /* bytes: in, out */ |
| 1291 | "%lld,%lld," |
| 1292 | /* denied: req, resp */ |
| 1293 | "%lld,%lld," |
| 1294 | /* errors: request, connect, response */ |
| 1295 | "%lld,,," |
| 1296 | /* warnings: retries, redispatches */ |
| 1297 | ",," |
| 1298 | /* server status: reflect listener status */ |
| 1299 | "%s," |
| 1300 | /* rest of server: nothing */ |
| 1301 | ",,,,,,,," |
| 1302 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 1303 | "%d,%d,%d,,,,%d," |
| 1304 | /* rate, rate_lim, rate_max */ |
| 1305 | ",,," |
| 1306 | /* check_status, check_code, check_duration */ |
| 1307 | ",,," |
| 1308 | "\n", |
| 1309 | px->id, l->name, |
| 1310 | l->nbconn, l->counters->conn_max, |
| 1311 | l->maxconn, l->counters->cum_conn, |
| 1312 | l->counters->bytes_in, l->counters->bytes_out, |
| 1313 | l->counters->denied_req, l->counters->denied_resp, |
| 1314 | l->counters->failed_req, |
| 1315 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 1316 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 1317 | } |
| 1318 | |
| 1319 | if (buffer_feed_chunk(rep, &msg) >= 0) |
| 1320 | return 0; |
| 1321 | } |
| 1322 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1323 | s->data_ctx.stats.sv = px->srv; /* may be NULL */ |
| 1324 | s->data_ctx.stats.px_st = DATA_ST_PX_SV; |
| 1325 | /* fall through */ |
| 1326 | |
| 1327 | case DATA_ST_PX_SV: |
| 1328 | /* stats.sv has been initialized above */ |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1329 | for (; s->data_ctx.stats.sv != NULL; s->data_ctx.stats.sv = sv->next) { |
| 1330 | |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1331 | 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] | 1332 | |
| 1333 | sv = s->data_ctx.stats.sv; |
| 1334 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1335 | if (s->data_ctx.stats.flags & STAT_BOUND) { |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1336 | if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SV))) |
| 1337 | break; |
| 1338 | |
| 1339 | if (s->data_ctx.stats.sid != -1 && sv->puid != s->data_ctx.stats.sid) |
| 1340 | continue; |
| 1341 | } |
| 1342 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1343 | if (sv->tracked) |
| 1344 | svs = sv->tracked; |
| 1345 | else |
| 1346 | svs = sv; |
| 1347 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1348 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1349 | if (!(svs->state & SRV_CHECKED)) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1350 | sv_state = 6; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1351 | else if (svs->state & SRV_RUNNING) { |
| 1352 | if (svs->health == svs->rise + svs->fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1353 | sv_state = 3; /* UP */ |
| 1354 | else |
| 1355 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1356 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1357 | if (svs->state & SRV_GOINGDOWN) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1358 | sv_state += 2; |
| 1359 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1360 | else |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1361 | if (svs->health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1362 | sv_state = 1; /* going up */ |
| 1363 | else |
| 1364 | sv_state = 0; /* DOWN */ |
| 1365 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1366 | if ((sv_state == 0) && (s->data_ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1367 | /* do not report servers which are DOWN */ |
| 1368 | s->data_ctx.stats.sv = sv->next; |
| 1369 | continue; |
| 1370 | } |
| 1371 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1372 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1373 | static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d ↑", |
| 1374 | "UP %d/%d ↓", "UP", |
| 1375 | "NOLB %d/%d ↓", "NOLB", |
| 1376 | "<i>no check</i>" }; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1377 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1378 | /* name */ |
| 1379 | "<tr align=\"center\" class=\"%s%d\"><td>%s</td>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1380 | /* queue : current, max, limit */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1381 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1382 | /* sessions rate : current, max, limit */ |
| 1383 | "<td align=right>%s</td><td align=right>%s</td><td align=right></td>" |
| 1384 | /* sessions : current, max, limit, total, lbtot */ |
| 1385 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1386 | "<td align=right>%s</td><td align=right>%s</td>" |
| 1387 | "", |
| 1388 | (sv->state & SRV_BACKUP) ? "backup" : "active", |
| 1389 | sv_state, sv->id, |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 1390 | U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"), |
| 1391 | U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max), |
| 1392 | U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-"), |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1393 | U2H8(sv->counters.cum_sess), U2H9(sv->counters.cum_lbconn)); |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1394 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1395 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1396 | /* bytes : in, out */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1397 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1398 | /* denied: req, resp */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1399 | "<td align=right></td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1400 | /* errors : request, connect, response */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1401 | "<td align=right></td><td align=right>%s</td><td align=right>%s</td>\n" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1402 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1403 | "<td align=right>%lld</td><td align=right>%lld</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1404 | "", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1405 | U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out), |
| 1406 | U2H2(sv->counters.failed_secu), |
| 1407 | U2H3(sv->counters.failed_conns), U2H4(sv->counters.failed_resp), |
| 1408 | sv->counters.retries, sv->counters.redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1409 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1410 | /* status, lest check */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1411 | chunk_printf(&msg, "<td nowrap>"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1412 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1413 | if (sv->state & SRV_CHECKED) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1414 | chunk_printf(&msg, "%s ", |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1415 | human_time(now.tv_sec - sv->last_change, 1)); |
| 1416 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1417 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1418 | srv_hlt_st[sv_state], |
| 1419 | (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), |
| 1420 | (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); |
| 1421 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1422 | chunk_printf(&msg, "</td><td title=\"%s\" nowrap> %s%s", |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1423 | get_check_status_description(sv->check_status), |
| 1424 | tv_iszero(&sv->check_start)?"":"* ", |
| 1425 | get_check_status_info(sv->check_status)); |
| 1426 | |
| 1427 | if (sv->check_status >= HCHK_STATUS_L57DATA) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1428 | chunk_printf(&msg, "/%d", sv->check_code); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1429 | |
| 1430 | if (sv->check_status >= HCHK_STATUS_CHECKED) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1431 | chunk_printf(&msg, " in %lums", sv->check_duration); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1432 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1433 | chunk_printf(&msg, "</td><td>"); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1434 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1435 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1436 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1437 | /* weight */ |
| 1438 | "</td><td>%d</td>" |
| 1439 | /* act, bck */ |
| 1440 | "<td>%s</td><td>%s</td>" |
| 1441 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1442 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1443 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 1444 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 1445 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1446 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1447 | if (sv->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1448 | chunk_printf(&msg, |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1449 | "<td align=right>%lld</td><td align=right>%lld</td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1450 | "<td nowrap align=right>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1451 | "", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1452 | svs->counters.failed_checks, svs->counters.down_trans, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1453 | human_time(srv_downtime(sv), 1)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1454 | else if (sv != svs) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1455 | chunk_printf(&msg, |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1456 | "<td nowrap colspan=3>via %s/%s</td>", svs->proxy->id, svs->id); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1457 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1458 | chunk_printf(&msg, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1459 | "<td colspan=3></td>"); |
| 1460 | |
| 1461 | /* throttle */ |
| 1462 | if ((sv->state & SRV_WARMINGUP) && |
| 1463 | now.tv_sec < sv->last_change + sv->slowstart && |
| 1464 | now.tv_sec >= sv->last_change) { |
| 1465 | unsigned int ratio; |
| 1466 | 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] | 1467 | chunk_printf(&msg, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1468 | "<td>%d %%</td></tr>\n", ratio); |
| 1469 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1470 | chunk_printf(&msg, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1471 | "<td>-</td></tr>\n"); |
| 1472 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1473 | } else { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1474 | static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,", |
| 1475 | "UP %d/%d,", "UP,", |
| 1476 | "NOLB %d/%d,", "NOLB,", |
| 1477 | "no check," }; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1478 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1479 | /* pxid, name */ |
| 1480 | "%s,%s," |
| 1481 | /* queue : current, max */ |
| 1482 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1483 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1484 | "%d,%d,%s,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1485 | /* bytes : in, out */ |
| 1486 | "%lld,%lld," |
| 1487 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1488 | ",%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1489 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1490 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1491 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1492 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1493 | "", |
| 1494 | px->id, sv->id, |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 1495 | sv->nbpend, sv->counters.nbpend_max, |
| 1496 | 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] | 1497 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 1498 | sv->counters.failed_secu, |
| 1499 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 1500 | sv->counters.retries, sv->counters.redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1501 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1502 | /* status */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1503 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1504 | srv_hlt_st[sv_state], |
| 1505 | (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health), |
| 1506 | (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1507 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1508 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1509 | /* weight, active, backup */ |
| 1510 | "%d,%d,%d," |
| 1511 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1512 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1513 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 1514 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 1515 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1516 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1517 | if (sv->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1518 | chunk_printf(&msg, |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1519 | "%lld,%lld,%d,%d,", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1520 | sv->counters.failed_checks, sv->counters.down_trans, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1521 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1522 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1523 | chunk_printf(&msg, |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1524 | ",,,,"); |
| 1525 | |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1526 | /* queue limit, pid, iid, sid, */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1527 | chunk_printf(&msg, |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 1528 | "%s," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1529 | "%d,%d,%d,", |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 1530 | LIM2A0(sv->maxqueue, ""), |
| 1531 | relative_pid, px->uuid, sv->puid); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1532 | |
| 1533 | /* throttle */ |
| 1534 | if ((sv->state & SRV_WARMINGUP) && |
| 1535 | now.tv_sec < sv->last_change + sv->slowstart && |
| 1536 | now.tv_sec >= sv->last_change) { |
| 1537 | unsigned int ratio; |
| 1538 | 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] | 1539 | chunk_printf(&msg, "%d", ratio); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1540 | } |
| 1541 | |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1542 | /* sessions: lbtot */ |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1543 | chunk_printf(&msg, ",%lld,", sv->counters.cum_lbconn); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1544 | |
| 1545 | /* tracked */ |
| 1546 | if (sv->tracked) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1547 | chunk_printf(&msg, "%s/%s,", |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1548 | sv->tracked->proxy->id, sv->tracked->id); |
| 1549 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1550 | chunk_printf(&msg, ","); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1551 | |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 1552 | /* type */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1553 | chunk_printf(&msg, "%d,", STATS_TYPE_SV); |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 1554 | |
| 1555 | /* rate */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1556 | chunk_printf(&msg, "%u,,%u,", |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 1557 | read_freq_ctr(&sv->sess_per_sec), |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 1558 | sv->counters.sps_max); |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 1559 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1560 | if (sv->state & SRV_CHECKED) { |
| 1561 | /* check_status */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1562 | chunk_printf(&msg, "%s,", get_check_status_info(sv->check_status)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1563 | |
| 1564 | /* check_code */ |
| 1565 | if (sv->check_status >= HCHK_STATUS_L57DATA) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1566 | chunk_printf(&msg, "%u,", sv->check_code); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1567 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1568 | chunk_printf(&msg, ","); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1569 | |
| 1570 | /* check_duration */ |
| 1571 | if (sv->check_status >= HCHK_STATUS_CHECKED) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1572 | chunk_printf(&msg, "%lu,", sv->check_duration); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1573 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1574 | chunk_printf(&msg, ","); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1575 | |
| 1576 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1577 | chunk_printf(&msg, ",,,"); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1578 | } |
| 1579 | |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 1580 | /* finish with EOL */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1581 | chunk_printf(&msg, "\n"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1582 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1583 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1584 | return 0; |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1585 | } /* for sv */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1586 | |
| 1587 | s->data_ctx.stats.px_st = DATA_ST_PX_BE; |
| 1588 | /* fall through */ |
| 1589 | |
| 1590 | case DATA_ST_PX_BE: |
| 1591 | /* print the backend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1592 | if ((px->cap & PR_CAP_BE) && |
| 1593 | (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_BE)))) { |
| 1594 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1595 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1596 | /* name */ |
| 1597 | "<tr align=center class=\"backend\"><td>Backend</td>" |
| 1598 | /* queue : current, max */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1599 | "<td align=right>%s</td><td align=right>%s</td><td></td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1600 | /* sessions rate : current, max, limit */ |
| 1601 | "<td align=right>%s</td><td align=right>%s</td><td align=right></td>" |
| 1602 | "", |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 1603 | U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->counters.nbpend_max), |
| 1604 | 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] | 1605 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1606 | chunk_printf(&msg, |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1607 | /* sessions : current, max, limit, total, lbtot */ |
| 1608 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1609 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1610 | /* bytes : in, out */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1611 | "<td align=right>%s</td><td align=right>%s</td>" |
| 1612 | "", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1613 | U2H2(px->beconn), U2H3(px->counters.beconn_max), U2H4(px->fullconn), |
| 1614 | U2H6(px->counters.cum_beconn), U2H7(px->counters.cum_lbconn), |
| 1615 | U2H8(px->counters.bytes_in), U2H9(px->counters.bytes_out)); |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1616 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1617 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1618 | /* denied: req, resp */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1619 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1620 | /* errors : request, connect, response */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1621 | "<td align=right></td><td align=right>%s</td><td align=right>%s</td>\n" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1622 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1623 | "<td align=right>%lld</td><td align=right>%lld</td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1624 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1625 | * 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] | 1626 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1627 | * active and backups. */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1628 | "<td align=center nowrap>%s %s</td><td align=center> </td><td align=center>%d</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1629 | "<td align=center>%d</td><td align=center>%d</td>" |
| 1630 | "", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1631 | U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp), |
| 1632 | U2H2(px->counters.failed_conns), U2H3(px->counters.failed_resp), |
| 1633 | px->counters.retries, px->counters.redispatches, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1634 | human_time(now.tv_sec - px->last_change, 1), |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1635 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 1636 | "<font color=\"red\"><b>DOWN</b></font>", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1637 | (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] | 1638 | px->srv_act, px->srv_bck); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1639 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1640 | chunk_printf(&msg, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1641 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1642 | "<td align=center> </td><td align=\"right\">%d</td>" |
| 1643 | "<td align=\"right\" nowrap>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1644 | "<td></td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1645 | "</tr>", |
| 1646 | px->down_trans, |
| 1647 | px->srv?human_time(be_downtime(px), 1):" "); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1648 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1649 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1650 | /* pxid, name */ |
| 1651 | "%s,BACKEND," |
| 1652 | /* queue : current, max */ |
| 1653 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1654 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1655 | "%d,%d,%d,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1656 | /* bytes : in, out */ |
| 1657 | "%lld,%lld," |
| 1658 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1659 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1660 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1661 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1662 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1663 | "%lld,%lld," |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1664 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1665 | * 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] | 1666 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1667 | * active and backups. */ |
| 1668 | "%s," |
| 1669 | "%d,%d,%d," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1670 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1671 | ",%d,%d,%d,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1672 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1673 | "%d,%d,0,,%lld,,%d," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 1674 | /* rate, rate_lim, rate_max, */ |
| 1675 | "%u,,%u," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1676 | /* check_status, check_code, check_duration */ |
| 1677 | ",,," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1678 | "\n", |
| 1679 | px->id, |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 1680 | px->nbpend /* or px->totpend ? */, px->counters.nbpend_max, |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1681 | px->beconn, px->counters.beconn_max, px->fullconn, px->counters.cum_beconn, |
| 1682 | px->counters.bytes_in, px->counters.bytes_out, |
| 1683 | px->counters.denied_req, px->counters.denied_resp, |
| 1684 | px->counters.failed_conns, px->counters.failed_resp, |
| 1685 | px->counters.retries, px->counters.redispatches, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 1686 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1687 | (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] | 1688 | px->srv_act, px->srv_bck, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1689 | px->down_trans, (int)(now.tv_sec - px->last_change), |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 1690 | px->srv?be_downtime(px):0, |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1691 | relative_pid, px->uuid, |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1692 | px->counters.cum_lbconn, STATS_TYPE_BE, |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 1693 | read_freq_ctr(&px->be_sess_per_sec), |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 1694 | px->counters.be_sps_max); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1695 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1696 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1697 | return 0; |
| 1698 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1699 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1700 | s->data_ctx.stats.px_st = DATA_ST_PX_END; |
| 1701 | /* fall through */ |
| 1702 | |
| 1703 | case DATA_ST_PX_END: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1704 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1705 | chunk_printf(&msg, "</table><p>\n"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1706 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1707 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1708 | return 0; |
| 1709 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1710 | |
| 1711 | s->data_ctx.stats.px_st = DATA_ST_PX_FIN; |
| 1712 | /* fall through */ |
| 1713 | |
| 1714 | case DATA_ST_PX_FIN: |
| 1715 | return 1; |
| 1716 | |
| 1717 | default: |
| 1718 | /* unknown state, we should put an abort() here ! */ |
| 1719 | return 1; |
| 1720 | } |
| 1721 | } |
| 1722 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1723 | |
| 1724 | /* This function is called to send output to the response buffer. |
| 1725 | * It dumps the sessions states onto the output buffer <rep>. |
| 1726 | * Expects to be called with client socket shut down on input. |
| 1727 | * 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] | 1728 | * 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] | 1729 | */ |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 1730 | int stats_dump_sess_to_buffer(struct session *s, struct buffer *rep) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1731 | { |
| 1732 | struct chunk msg; |
| 1733 | |
| 1734 | if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) { |
| 1735 | /* If we're forced to shut down, we might have to remove our |
| 1736 | * reference to the last session being dumped. |
| 1737 | */ |
| 1738 | if (s->data_state == DATA_ST_LIST) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1739 | if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1740 | LIST_DEL(&s->data_ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1741 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1742 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1743 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 1744 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1745 | } |
| 1746 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1747 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1748 | |
| 1749 | switch (s->data_state) { |
| 1750 | case DATA_ST_INIT: |
| 1751 | /* the function had not been called yet, let's prepare the |
| 1752 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1753 | * pointer to the first in the global list. When a target |
| 1754 | * session is being destroyed, it is responsible for updating |
| 1755 | * this pointer. We know we have reached the end when this |
| 1756 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1757 | */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1758 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1759 | s->data_ctx.sess.bref.ref = sessions.n; |
| 1760 | s->data_state = DATA_ST_LIST; |
| 1761 | /* fall through */ |
| 1762 | |
| 1763 | case DATA_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1764 | /* first, let's detach the back-ref from a possible previous session */ |
| 1765 | if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) { |
| 1766 | LIST_DEL(&s->data_ctx.sess.bref.users); |
| 1767 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1768 | } |
| 1769 | |
| 1770 | /* and start from where we stopped */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1771 | while (s->data_ctx.sess.bref.ref != &sessions) { |
| 1772 | char pn[INET6_ADDRSTRLEN + strlen(":65535")]; |
| 1773 | struct session *curr_sess; |
| 1774 | |
| 1775 | curr_sess = LIST_ELEM(s->data_ctx.sess.bref.ref, struct session *, list); |
| 1776 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1777 | chunk_printf(&msg, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1778 | "%p: proto=%s", |
| 1779 | curr_sess, |
| 1780 | curr_sess->listener->proto->name); |
| 1781 | |
| 1782 | switch (curr_sess->listener->proto->sock_family) { |
| 1783 | case AF_INET: |
| 1784 | inet_ntop(AF_INET, |
| 1785 | (const void *)&((struct sockaddr_in *)&curr_sess->cli_addr)->sin_addr, |
| 1786 | pn, sizeof(pn)); |
| 1787 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1788 | chunk_printf(&msg, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1789 | " src=%s:%d fe=%s be=%s srv=%s", |
| 1790 | pn, |
| 1791 | ntohs(((struct sockaddr_in *)&curr_sess->cli_addr)->sin_port), |
| 1792 | curr_sess->fe->id, |
| 1793 | curr_sess->be->id, |
| 1794 | curr_sess->srv ? curr_sess->srv->id : "<none>" |
| 1795 | ); |
| 1796 | break; |
| 1797 | case AF_INET6: |
| 1798 | inet_ntop(AF_INET6, |
| 1799 | (const void *)&((struct sockaddr_in6 *)(&curr_sess->cli_addr))->sin6_addr, |
| 1800 | pn, sizeof(pn)); |
| 1801 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1802 | chunk_printf(&msg, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1803 | " src=%s:%d fe=%s be=%s srv=%s", |
| 1804 | pn, |
| 1805 | ntohs(((struct sockaddr_in6 *)&curr_sess->cli_addr)->sin6_port), |
| 1806 | curr_sess->fe->id, |
| 1807 | curr_sess->be->id, |
| 1808 | curr_sess->srv ? curr_sess->srv->id : "<none>" |
| 1809 | ); |
| 1810 | |
| 1811 | break; |
| 1812 | case AF_UNIX: |
| 1813 | /* no more information to print right now */ |
| 1814 | break; |
| 1815 | } |
| 1816 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1817 | chunk_printf(&msg, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 1818 | " ts=%02x age=%s calls=%d", |
| 1819 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 1820 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 1821 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1822 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1823 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1824 | " rq[f=%06xh,l=%d,an=%02xh,rx=%s", |
| 1825 | curr_sess->req->flags, |
| 1826 | curr_sess->req->l, |
| 1827 | curr_sess->req->analysers, |
| 1828 | curr_sess->req->rex ? |
| 1829 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 1830 | TICKS_TO_MS(1000)) : ""); |
| 1831 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1832 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1833 | ",wx=%s", |
| 1834 | curr_sess->req->wex ? |
| 1835 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 1836 | TICKS_TO_MS(1000)) : ""); |
| 1837 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1838 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1839 | ",ax=%s]", |
| 1840 | curr_sess->req->analyse_exp ? |
| 1841 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 1842 | TICKS_TO_MS(1000)) : ""); |
| 1843 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1844 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1845 | " rp[f=%06xh,l=%d,an=%02xh,rx=%s", |
| 1846 | curr_sess->rep->flags, |
| 1847 | curr_sess->rep->l, |
| 1848 | curr_sess->rep->analysers, |
| 1849 | curr_sess->rep->rex ? |
| 1850 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 1851 | TICKS_TO_MS(1000)) : ""); |
| 1852 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1853 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1854 | ",wx=%s", |
| 1855 | curr_sess->rep->wex ? |
| 1856 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 1857 | TICKS_TO_MS(1000)) : ""); |
| 1858 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1859 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1860 | ",ax=%s]", |
| 1861 | curr_sess->rep->analyse_exp ? |
| 1862 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 1863 | TICKS_TO_MS(1000)) : ""); |
| 1864 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1865 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1866 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 1867 | curr_sess->si[0].state, |
| 1868 | curr_sess->si[0].flags, |
| 1869 | curr_sess->si[0].fd, |
| 1870 | curr_sess->si[0].exp ? |
| 1871 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 1872 | TICKS_TO_MS(1000)) : ""); |
| 1873 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1874 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1875 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 1876 | curr_sess->si[1].state, |
| 1877 | curr_sess->si[1].flags, |
| 1878 | curr_sess->si[1].fd, |
| 1879 | curr_sess->si[1].exp ? |
| 1880 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 1881 | TICKS_TO_MS(1000)) : ""); |
| 1882 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1883 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1884 | " exp=%s", |
| 1885 | curr_sess->task->expire ? |
| 1886 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 1887 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 1888 | if (task_in_rq(curr_sess->task)) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1889 | chunk_printf(&msg, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1890 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1891 | chunk_printf(&msg, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1892 | |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 1893 | if (buffer_feed_chunk(rep, &msg) >= 0) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1894 | /* let's try again later from this session. We add ourselves into |
| 1895 | * this session's users so that it can remove us upon termination. |
| 1896 | */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1897 | LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 1898 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | s->data_ctx.sess.bref.ref = curr_sess->list.n; |
| 1902 | } |
| 1903 | s->data_state = DATA_ST_FIN; |
| 1904 | /* fall through */ |
| 1905 | |
| 1906 | default: |
| 1907 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 1908 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1909 | } |
| 1910 | } |
| 1911 | |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1912 | /* print a line of error buffer (limited to 70 bytes) to <out>. The format is : |
| 1913 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 1914 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 1915 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 1916 | * lines are respected within the limit of 70 output chars. Lines that are |
| 1917 | * continuation of a previous truncated line begin with "+" instead of " " |
| 1918 | * after the offset. The new pointer is returned. |
| 1919 | */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1920 | static int dump_error_line(struct chunk *out, struct error_snapshot *err, |
| 1921 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1922 | { |
| 1923 | int end; |
| 1924 | unsigned char c; |
| 1925 | |
| 1926 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1927 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1928 | return ptr; |
| 1929 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1930 | chunk_printf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1931 | |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 1932 | while (ptr < err->len && ptr < sizeof(err->buf)) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1933 | c = err->buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 1934 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1935 | if (out->len > end - 2) |
| 1936 | break; |
| 1937 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 1938 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1939 | if (out->len > end - 3) |
| 1940 | break; |
| 1941 | out->str[out->len++] = '\\'; |
| 1942 | switch (c) { |
| 1943 | case '\t': c = 't'; break; |
| 1944 | case '\n': c = 'n'; break; |
| 1945 | case '\r': c = 'r'; break; |
| 1946 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 1947 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1948 | } |
| 1949 | out->str[out->len++] = c; |
| 1950 | } else { |
| 1951 | if (out->len > end - 5) |
| 1952 | break; |
| 1953 | out->str[out->len++] = '\\'; |
| 1954 | out->str[out->len++] = 'x'; |
| 1955 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 1956 | out->str[out->len++] = hextab[c & 0xF]; |
| 1957 | } |
| 1958 | if (err->buf[ptr++] == '\n') { |
| 1959 | /* we had a line break, let's return now */ |
| 1960 | out->str[out->len++] = '\n'; |
| 1961 | *line = ptr; |
| 1962 | return ptr; |
| 1963 | } |
| 1964 | } |
| 1965 | /* we have an incomplete line, we return it as-is */ |
| 1966 | out->str[out->len++] = '\n'; |
| 1967 | return ptr; |
| 1968 | } |
| 1969 | |
| 1970 | /* This function is called to send output to the response buffer. |
| 1971 | * It dumps the errors logged in proxies onto the output buffer <rep>. |
| 1972 | * Expects to be called with client socket shut down on input. |
| 1973 | * 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] | 1974 | * 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] | 1975 | */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 1976 | int stats_dump_errors_to_buffer(struct session *s, struct buffer *rep) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1977 | { |
| 1978 | extern const char *monthname[12]; |
| 1979 | struct chunk msg; |
| 1980 | |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 1981 | if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) |
| 1982 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1983 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1984 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1985 | |
| 1986 | if (!s->data_ctx.errors.px) { |
| 1987 | /* the function had not been called yet, let's prepare the |
| 1988 | * buffer for a response. |
| 1989 | */ |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1990 | s->data_ctx.errors.px = proxy; |
| 1991 | s->data_ctx.errors.buf = 0; |
| 1992 | s->data_ctx.errors.bol = 0; |
| 1993 | s->data_ctx.errors.ptr = -1; |
| 1994 | } |
| 1995 | |
| 1996 | /* we have two inner loops here, one for the proxy, the other one for |
| 1997 | * the buffer. |
| 1998 | */ |
| 1999 | while (s->data_ctx.errors.px) { |
| 2000 | struct error_snapshot *es; |
| 2001 | |
| 2002 | if (s->data_ctx.errors.buf == 0) |
| 2003 | es = &s->data_ctx.errors.px->invalid_req; |
| 2004 | else |
| 2005 | es = &s->data_ctx.errors.px->invalid_rep; |
| 2006 | |
| 2007 | if (!es->when.tv_sec) |
| 2008 | goto next; |
| 2009 | |
| 2010 | if (s->data_ctx.errors.iid >= 0 && |
| 2011 | s->data_ctx.errors.px->uuid != s->data_ctx.errors.iid && |
| 2012 | es->oe->uuid != s->data_ctx.errors.iid) |
| 2013 | goto next; |
| 2014 | |
| 2015 | if (s->data_ctx.errors.ptr < 0) { |
| 2016 | /* just print headers now */ |
| 2017 | |
| 2018 | char pn[INET6_ADDRSTRLEN]; |
| 2019 | struct tm tm; |
| 2020 | |
| 2021 | get_localtime(es->when.tv_sec, &tm); |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2022 | chunk_printf(&msg, "\n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2023 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 2024 | 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] | 2025 | |
| 2026 | |
| 2027 | if (es->src.ss_family == AF_INET) |
| 2028 | inet_ntop(AF_INET, |
| 2029 | (const void *)&((struct sockaddr_in *)&es->src)->sin_addr, |
| 2030 | pn, sizeof(pn)); |
| 2031 | else |
| 2032 | inet_ntop(AF_INET6, |
| 2033 | (const void *)&((struct sockaddr_in6 *)(&es->src))->sin6_addr, |
| 2034 | pn, sizeof(pn)); |
| 2035 | |
| 2036 | switch (s->data_ctx.errors.buf) { |
| 2037 | case 0: |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2038 | chunk_printf(&msg, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2039 | " frontend %s (#%d): invalid request\n" |
| 2040 | " src %s, session #%d, backend %s (#%d), server %s (#%d)\n" |
| 2041 | " request length %d bytes, error at position %d:\n\n", |
| 2042 | s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid, |
| 2043 | pn, es->sid, es->oe->id, es->oe->uuid, |
| 2044 | es->srv ? es->srv->id : "<NONE>", |
| 2045 | es->srv ? es->srv->puid : -1, |
| 2046 | es->len, es->pos); |
| 2047 | break; |
| 2048 | case 1: |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2049 | chunk_printf(&msg, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2050 | " backend %s (#%d) : invalid response\n" |
| 2051 | " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n" |
| 2052 | " response length %d bytes, error at position %d:\n\n", |
| 2053 | s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid, |
| 2054 | pn, es->sid, es->oe->id, es->oe->uuid, |
| 2055 | es->srv ? es->srv->id : "<NONE>", |
| 2056 | es->srv ? es->srv->puid : -1, |
| 2057 | es->len, es->pos); |
| 2058 | break; |
| 2059 | } |
| 2060 | |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 2061 | if (buffer_feed_chunk(rep, &msg) >= 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2062 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 2063 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2064 | } |
| 2065 | s->data_ctx.errors.ptr = 0; |
| 2066 | s->data_ctx.errors.sid = es->sid; |
| 2067 | } |
| 2068 | |
| 2069 | if (s->data_ctx.errors.sid != es->sid) { |
| 2070 | /* the snapshot changed while we were dumping it */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2071 | chunk_printf(&msg, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2072 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 2073 | if (buffer_feed_chunk(rep, &msg) >= 0) |
| 2074 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2075 | goto next; |
| 2076 | } |
| 2077 | |
| 2078 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 2079 | 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] | 2080 | int newptr; |
| 2081 | int newline; |
| 2082 | |
| 2083 | newline = s->data_ctx.errors.bol; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2084 | newptr = dump_error_line(&msg, es, &newline, s->data_ctx.errors.ptr); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2085 | if (newptr == s->data_ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 2086 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2087 | |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 2088 | if (buffer_feed_chunk(rep, &msg) >= 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2089 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 2090 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2091 | } |
| 2092 | s->data_ctx.errors.ptr = newptr; |
| 2093 | s->data_ctx.errors.bol = newline; |
| 2094 | }; |
| 2095 | next: |
| 2096 | s->data_ctx.errors.bol = 0; |
| 2097 | s->data_ctx.errors.ptr = -1; |
| 2098 | s->data_ctx.errors.buf++; |
| 2099 | if (s->data_ctx.errors.buf > 1) { |
| 2100 | s->data_ctx.errors.buf = 0; |
| 2101 | s->data_ctx.errors.px = s->data_ctx.errors.px->next; |
| 2102 | } |
| 2103 | } |
| 2104 | |
| 2105 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 2106 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2107 | } |
| 2108 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2109 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 2110 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 2111 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 2112 | { 0, NULL, NULL }, |
| 2113 | }}; |
| 2114 | |
| 2115 | __attribute__((constructor)) |
| 2116 | static void __dumpstats_module_init(void) |
| 2117 | { |
| 2118 | cfg_register_keywords(&cfg_kws); |
| 2119 | } |
| 2120 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2121 | /* |
| 2122 | * Local variables: |
| 2123 | * c-indent-level: 8 |
| 2124 | * c-basic-offset: 8 |
| 2125 | * End: |
| 2126 | */ |