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> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <ctype.h> |
| 14 | #include <errno.h> |
| 15 | #include <fcntl.h> |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 19 | #include <pwd.h> |
| 20 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 21 | |
| 22 | #include <sys/socket.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/types.h> |
| 25 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 26 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 27 | #include <common/compat.h> |
| 28 | #include <common/config.h> |
| 29 | #include <common/debug.h> |
| 30 | #include <common/memory.h> |
| 31 | #include <common/mini-clist.h> |
| 32 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 33 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 34 | #include <common/time.h> |
| 35 | #include <common/uri_auth.h> |
| 36 | #include <common/version.h> |
| 37 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 38 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | |
| 40 | #include <proto/backend.h> |
| 41 | #include <proto/buffers.h> |
| 42 | #include <proto/dumpstats.h> |
| 43 | #include <proto/fd.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 44 | #include <proto/pipe.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 45 | #include <proto/proto_uxst.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 46 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 47 | #include <proto/server.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 48 | #include <proto/stream_interface.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 49 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 50 | /* This function parses a "stats" statement in the "global" section. It returns |
| 51 | * -1 if there is any error, otherwise zero. If it returns -1, it may write an |
| 52 | * error message into ther <err> buffer, for at most <errlen> bytes, trailing |
| 53 | * zero included. The trailing '\n' must not be written. The function must be |
| 54 | * called with <args> pointing to the first word after "stats". |
| 55 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 56 | static int stats_parse_global(char **args, int section_type, struct proxy *curpx, |
| 57 | struct proxy *defpx, char *err, int errlen) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 58 | { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 59 | args++; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 60 | if (!strcmp(args[0], "socket")) { |
| 61 | struct sockaddr_un su; |
| 62 | int cur_arg; |
| 63 | |
| 64 | if (*args[1] == 0) { |
| 65 | snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket"); |
| 66 | return -1; |
| 67 | } |
| 68 | |
| 69 | if (global.stats_sock.state != LI_NEW) { |
| 70 | snprintf(err, errlen, "'stats socket' already specified in global section"); |
| 71 | return -1; |
| 72 | } |
| 73 | |
| 74 | su.sun_family = AF_UNIX; |
| 75 | strncpy(su.sun_path, args[1], sizeof(su.sun_path)); |
| 76 | su.sun_path[sizeof(su.sun_path) - 1] = 0; |
| 77 | memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit |
| 78 | |
| 79 | global.stats_sock.state = LI_INIT; |
Willy Tarreau | 6fb42e0 | 2007-10-28 17:02:33 +0100 | [diff] [blame] | 80 | global.stats_sock.options = LI_O_NONE; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 81 | global.stats_sock.accept = uxst_event_accept; |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 82 | global.stats_sock.handler = uxst_process_session; |
| 83 | global.stats_sock.analysers = AN_REQ_UNIX_STATS; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 84 | global.stats_sock.private = NULL; |
| 85 | |
| 86 | cur_arg = 2; |
| 87 | while (*args[cur_arg]) { |
| 88 | if (!strcmp(args[cur_arg], "uid")) { |
| 89 | global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]); |
| 90 | cur_arg += 2; |
| 91 | } |
| 92 | else if (!strcmp(args[cur_arg], "gid")) { |
| 93 | global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]); |
| 94 | cur_arg += 2; |
| 95 | } |
| 96 | else if (!strcmp(args[cur_arg], "mode")) { |
| 97 | global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 98 | cur_arg += 2; |
| 99 | } |
| 100 | else if (!strcmp(args[cur_arg], "user")) { |
| 101 | struct passwd *user; |
| 102 | user = getpwnam(args[cur_arg + 1]); |
| 103 | if (!user) { |
| 104 | snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')", |
| 105 | args[cur_arg + 1]); |
| 106 | return -1; |
| 107 | } |
| 108 | global.stats_sock.perm.ux.uid = user->pw_uid; |
| 109 | cur_arg += 2; |
| 110 | } |
| 111 | else if (!strcmp(args[cur_arg], "group")) { |
| 112 | struct group *group; |
| 113 | group = getgrnam(args[cur_arg + 1]); |
| 114 | if (!group) { |
| 115 | snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')", |
| 116 | args[cur_arg + 1]); |
| 117 | return -1; |
| 118 | } |
| 119 | global.stats_sock.perm.ux.gid = group->gr_gid; |
| 120 | cur_arg += 2; |
| 121 | } |
| 122 | else { |
| 123 | snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', and 'mode'"); |
| 124 | return -1; |
| 125 | } |
| 126 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 127 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 128 | uxst_add_listener(&global.stats_sock); |
| 129 | global.maxsock++; |
| 130 | } |
| 131 | else if (!strcmp(args[0], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 132 | unsigned timeout; |
| 133 | const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS); |
| 134 | |
| 135 | if (res) { |
| 136 | snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res); |
| 137 | return -1; |
| 138 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 139 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 140 | if (!timeout) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 141 | snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'"); |
| 142 | return -1; |
| 143 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 144 | global.stats_timeout = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 145 | } |
| 146 | else if (!strcmp(args[0], "maxconn")) { |
| 147 | int maxconn = atol(args[1]); |
| 148 | |
| 149 | if (maxconn <= 0) { |
| 150 | snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'"); |
| 151 | return -1; |
| 152 | } |
| 153 | global.maxsock -= global.stats_sock.maxconn; |
| 154 | global.stats_sock.maxconn = maxconn; |
| 155 | global.maxsock += global.stats_sock.maxconn; |
| 156 | } |
| 157 | else { |
| 158 | snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section"); |
| 159 | return -1; |
| 160 | } |
| 161 | return 0; |
| 162 | } |
| 163 | |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 164 | int print_csv_header(struct chunk *msg, int size) |
| 165 | { |
| 166 | return chunk_printf(msg, size, |
| 167 | "# pxname,svname," |
| 168 | "qcur,qmax," |
| 169 | "scur,smax,slim,stot," |
| 170 | "bin,bout," |
| 171 | "dreq,dresp," |
| 172 | "ereq,econ,eresp," |
| 173 | "wretr,wredis," |
| 174 | "status,weight,act,bck," |
| 175 | "chkfail,chkdown,lastchg,downtime,qlimit," |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 176 | "pid,iid,sid,throttle,lbtot,tracked,type," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 177 | "\n"); |
| 178 | } |
| 179 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 180 | /* |
| 181 | * Produces statistics data for the session <s>. Expects to be called with |
Willy Tarreau | 1ae3a05 | 2008-08-16 10:56:30 +0200 | [diff] [blame] | 182 | * client socket shut down on input. It *may* make use of informations from |
| 183 | * <uri>. s->data_ctx must have been zeroed first, and the flags properly set. |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 184 | * It returns 0 if it had to stop writing data and an I/O is needed, 1 if the |
| 185 | * dump is finished and the session must be closed, or -1 in case of any error. |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 186 | * It automatically clears the HIJACK bit from the response buffer. |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 187 | */ |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 188 | int stats_dump_raw(struct session *s, struct buffer *rep, struct uri_auth *uri) |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 189 | { |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 190 | struct proxy *px; |
| 191 | struct chunk msg; |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 192 | unsigned int up; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 193 | |
| 194 | msg.len = 0; |
| 195 | msg.str = trash; |
| 196 | |
| 197 | switch (s->data_state) { |
| 198 | case DATA_ST_INIT: |
| 199 | /* the function had not been called yet, let's prepare the |
| 200 | * buffer for a response. |
| 201 | */ |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 202 | stream_int_retnclose(rep->cons, &msg); |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 203 | s->data_state = DATA_ST_HEAD; |
| 204 | /* fall through */ |
| 205 | |
| 206 | case DATA_ST_HEAD: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 207 | if (s->data_ctx.stats.flags & STAT_SHOW_STAT) { |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 208 | print_csv_header(&msg, sizeof(trash)); |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 209 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 210 | return 0; |
| 211 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 212 | |
| 213 | s->data_state = DATA_ST_INFO; |
| 214 | /* fall through */ |
| 215 | |
| 216 | case DATA_ST_INFO: |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 217 | up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 218 | if (s->data_ctx.stats.flags & STAT_SHOW_INFO) { |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 219 | chunk_printf(&msg, sizeof(trash), |
| 220 | "Name: " PRODUCT_NAME "\n" |
| 221 | "Version: " HAPROXY_VERSION "\n" |
| 222 | "Release_date: " HAPROXY_DATE "\n" |
| 223 | "Nbproc: %d\n" |
| 224 | "Process_num: %d\n" |
| 225 | "Pid: %d\n" |
| 226 | "Uptime: %dd %dh%02dm%02ds\n" |
| 227 | "Uptime_sec: %d\n" |
| 228 | "Memmax_MB: %d\n" |
| 229 | "Ulimit-n: %d\n" |
| 230 | "Maxsock: %d\n" |
| 231 | "Maxconn: %d\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 232 | "Maxpipes: %d\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 233 | "CurrConns: %d\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 234 | "PipesUsed: %d\n" |
| 235 | "PipesFree: %d\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 236 | "", |
| 237 | global.nbproc, |
| 238 | relative_pid, |
| 239 | pid, |
| 240 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 241 | up, |
| 242 | global.rlimit_memmax, |
| 243 | global.rlimit_nofile, |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 244 | global.maxsock, global.maxconn, global.maxpipes, |
| 245 | actconn, pipes_used, pipes_free |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 246 | ); |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 247 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 248 | return 0; |
| 249 | } |
| 250 | |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 251 | s->data_ctx.stats.px = proxy; |
| 252 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 253 | |
| 254 | s->data_ctx.stats.sv = NULL; |
| 255 | s->data_ctx.stats.sv_st = 0; |
| 256 | |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 257 | s->data_state = DATA_ST_LIST; |
| 258 | /* fall through */ |
| 259 | |
| 260 | case DATA_ST_LIST: |
| 261 | /* dump proxies */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 262 | if (s->data_ctx.stats.flags & STAT_SHOW_STAT) { |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 263 | while (s->data_ctx.stats.px) { |
| 264 | px = s->data_ctx.stats.px; |
| 265 | /* skip the disabled proxies and non-networked ones */ |
| 266 | if (px->state != PR_STSTOPPED && |
| 267 | (px->cap & (PR_CAP_FE | PR_CAP_BE))) |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 268 | if (stats_dump_proxy(s, px, NULL) == 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 269 | return 0; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 270 | |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 271 | s->data_ctx.stats.px = px->next; |
| 272 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 273 | } |
| 274 | /* here, we just have reached the last proxy */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 275 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 276 | |
| 277 | s->data_state = DATA_ST_END; |
| 278 | /* fall through */ |
| 279 | |
| 280 | case DATA_ST_END: |
| 281 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 282 | /* fall through */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 283 | |
| 284 | case DATA_ST_FIN: |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 285 | buffer_stop_hijack(rep); |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 286 | return 1; |
| 287 | |
| 288 | default: |
| 289 | /* unknown state ! */ |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 290 | buffer_stop_hijack(rep); |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 291 | return -1; |
| 292 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | |
| 296 | /* This function is called to send output to the response buffer. It simply |
| 297 | * calls stats_dump_raw(), and releases the buffer's hijack bit when the dump |
Willy Tarreau | 01bf867 | 2008-12-07 18:03:29 +0100 | [diff] [blame] | 298 | * is finished. |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 299 | */ |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 300 | void stats_dump_raw_to_buffer(struct session *s, struct buffer *rep) |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 301 | { |
| 302 | if (s->ana_state != STATS_ST_REP) |
Willy Tarreau | 01bf867 | 2008-12-07 18:03:29 +0100 | [diff] [blame] | 303 | return; |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 304 | |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 305 | if (stats_dump_raw(s, rep, NULL) != 0) |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 306 | s->ana_state = STATS_ST_CLOSE; |
Willy Tarreau | 01bf867 | 2008-12-07 18:03:29 +0100 | [diff] [blame] | 307 | return; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | |
| 311 | /* |
| 312 | * Produces statistics data for the session <s>. Expects to be called with |
Willy Tarreau | 1ae3a05 | 2008-08-16 10:56:30 +0200 | [diff] [blame] | 313 | * 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] | 314 | * 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] | 315 | * when there is free space in the buffer, of simply by letting an empty buffer |
| 316 | * upon return.s->data_ctx must have been zeroed before the first call, and the |
| 317 | * flags set. It returns 0 if it had to stop writing data and an I/O is needed, |
| 318 | * 1 if the dump is finished and the session must be closed, or -1 in case of |
| 319 | * any error. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 320 | */ |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 321 | 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] | 322 | { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 323 | struct proxy *px; |
| 324 | struct chunk msg; |
| 325 | unsigned int up; |
| 326 | |
| 327 | msg.len = 0; |
| 328 | msg.str = trash; |
| 329 | |
| 330 | switch (s->data_state) { |
| 331 | case DATA_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 332 | chunk_printf(&msg, sizeof(trash), |
| 333 | "HTTP/1.0 200 OK\r\n" |
| 334 | "Cache-Control: no-cache\r\n" |
| 335 | "Connection: close\r\n" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 336 | "Content-Type: %s\r\n", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 337 | (s->data_ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 338 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 339 | if (uri->refresh > 0 && !(s->data_ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 340 | chunk_printf(&msg, sizeof(trash), "Refresh: %d\r\n", |
| 341 | uri->refresh); |
| 342 | |
| 343 | chunk_printf(&msg, sizeof(trash), "\r\n"); |
| 344 | |
| 345 | s->txn.status = 200; |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 346 | stream_int_retnclose(rep->cons, &msg); // send the start of the response. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 347 | msg.len = 0; |
| 348 | |
| 349 | if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is |
| 350 | s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy |
| 351 | if (!(s->flags & SN_FINST_MASK)) |
| 352 | s->flags |= SN_FINST_R; |
| 353 | |
| 354 | if (s->txn.meth == HTTP_METH_HEAD) { |
| 355 | /* that's all we return in case of HEAD request */ |
| 356 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 72b179a | 2008-08-28 16:01:32 +0200 | [diff] [blame] | 357 | buffer_stop_hijack(rep); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 358 | return 1; |
| 359 | } |
| 360 | |
| 361 | s->data_state = DATA_ST_HEAD; /* let's start producing data */ |
| 362 | /* fall through */ |
| 363 | |
| 364 | case DATA_ST_HEAD: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 365 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 366 | /* WARNING! This must fit in the first buffer !!! */ |
| 367 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 368 | "<html><head><title>Statistics Report for " PRODUCT_NAME "</title>\n" |
| 369 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 370 | "<style type=\"text/css\"><!--\n" |
| 371 | "body {" |
| 372 | " font-family: helvetica, arial;" |
| 373 | " font-size: 12px;" |
| 374 | " font-weight: normal;" |
| 375 | " color: black;" |
| 376 | " background: white;" |
| 377 | "}\n" |
| 378 | "th,td {" |
| 379 | " font-size: 0.8em;" |
| 380 | " align: center;" |
| 381 | "}\n" |
| 382 | "h1 {" |
| 383 | " font-size: xx-large;" |
| 384 | " margin-bottom: 0.5em;" |
| 385 | "}\n" |
| 386 | "h2 {" |
| 387 | " font-family: helvetica, arial;" |
| 388 | " font-size: x-large;" |
| 389 | " font-weight: bold;" |
| 390 | " font-style: italic;" |
| 391 | " color: #6020a0;" |
| 392 | " margin-top: 0em;" |
| 393 | " margin-bottom: 0em;" |
| 394 | "}\n" |
| 395 | "h3 {" |
| 396 | " font-family: helvetica, arial;" |
| 397 | " font-size: 16px;" |
| 398 | " font-weight: bold;" |
| 399 | " color: #b00040;" |
| 400 | " background: #e8e8d0;" |
| 401 | " margin-top: 0em;" |
| 402 | " margin-bottom: 0em;" |
| 403 | "}\n" |
| 404 | "li {" |
| 405 | " margin-top: 0.25em;" |
| 406 | " margin-right: 2em;" |
| 407 | "}\n" |
| 408 | ".hr {margin-top: 0.25em;" |
| 409 | " border-color: black;" |
| 410 | " border-bottom-style: solid;" |
| 411 | "}\n" |
| 412 | ".pxname {background: #b00040;color: #ffff40;font-weight: bold;}\n" |
| 413 | ".titre {background: #20D0D0;color: #000000;font-weight: bold;}\n" |
| 414 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 415 | ".frontend {background: #e8e8d0;}\n" |
| 416 | ".backend {background: #e8e8d0;}\n" |
| 417 | ".active0 {background: #ff9090;}\n" |
| 418 | ".active1 {background: #ffd020;}\n" |
| 419 | ".active2 {background: #ffffa0;}\n" |
| 420 | ".active3 {background: #c0ffc0;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 421 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 422 | ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */ |
| 423 | ".active6 {background: #e0e0e0;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 424 | ".backup0 {background: #ff9090;}\n" |
| 425 | ".backup1 {background: #ff80ff;}\n" |
| 426 | ".backup2 {background: #c060ff;}\n" |
| 427 | ".backup3 {background: #b0d0ff;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 428 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 429 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 430 | ".backup6 {background: #e0e0e0;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 431 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 432 | "table.tbl td { border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray;}\n" |
| 433 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 434 | "table.tbl th.empty { border-style: none; empty-cells: hide;}\n" |
| 435 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 436 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 437 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
| 438 | "-->\n" |
| 439 | "</style></head>\n"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 440 | } else { |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 441 | print_csv_header(&msg, sizeof(trash)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 442 | } |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 443 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 444 | return 0; |
| 445 | |
| 446 | s->data_state = DATA_ST_INFO; |
| 447 | /* fall through */ |
| 448 | |
| 449 | case DATA_ST_INFO: |
| 450 | up = (now.tv_sec - start_date.tv_sec); |
| 451 | |
| 452 | /* WARNING! this has to fit the first packet too. |
| 453 | * We are around 3.5 kB, add adding entries will |
| 454 | * become tricky if we want to support 4kB buffers ! |
| 455 | */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 456 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 457 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 458 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 459 | PRODUCT_NAME "%s</a></h1>\n" |
| 460 | "<h2>Statistics Report for pid %d</h2>\n" |
| 461 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 462 | "<h3>> General process information</h3>\n" |
| 463 | "<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] | 464 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 465 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 466 | "<b>system limits :</b> memmax = %s%s ; ulimit-n = %d<br>\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 467 | "<b>maxsock = </b> %d ; <b>maxconn = </b> %d ; <b>maxpipes = </b> %d<br>\n" |
| 468 | "current conns = %d ; current pipes = %d/%d<br>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 469 | "</td><td align=\"center\" nowrap>\n" |
| 470 | "<table class=\"lgd\"><tr>\n" |
| 471 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 472 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 473 | "</tr><tr>\n" |
| 474 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 475 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 476 | "</tr><tr>\n" |
| 477 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 478 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 479 | "</tr><tr>\n" |
| 480 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 481 | "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 482 | "</tr></table>\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 483 | "Note: UP with load-balancing disabled is reported as \"NOLB\"." |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 484 | "</td>" |
| 485 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 486 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 487 | "", |
| 488 | (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING), |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 489 | pid, pid, |
| 490 | relative_pid, global.nbproc, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 491 | up / 86400, (up % 86400) / 3600, |
| 492 | (up % 3600) / 60, (up % 60), |
| 493 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 494 | global.rlimit_memmax ? " MB" : "", |
| 495 | global.rlimit_nofile, |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 496 | global.maxsock, global.maxconn, global.maxpipes, |
| 497 | actconn, pipes_used, pipes_used+pipes_free |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 498 | ); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 499 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 500 | if (s->data_ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 501 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 502 | "<li><a href=\"%s%s%s\">Show all servers</a><br>\n", |
| 503 | uri->uri_prefix, |
| 504 | "", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 505 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 506 | else |
| 507 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 508 | "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 509 | uri->uri_prefix, |
| 510 | ";up", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 511 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 512 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 513 | if (uri->refresh > 0) { |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 514 | if (s->data_ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 515 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 516 | "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n", |
| 517 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 518 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 519 | ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 520 | else |
| 521 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 522 | "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n", |
| 523 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 524 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 525 | ";norefresh"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 526 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 527 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 528 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 529 | "<li><a href=\"%s%s%s\">Refresh now</a><br>\n", |
| 530 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 531 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 532 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 533 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 534 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 535 | "<li><a href=\"%s;csv%s\">CSV export</a><br>\n", |
| 536 | uri->uri_prefix, |
| 537 | (uri->refresh > 0) ? ";norefresh" : ""); |
| 538 | |
| 539 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 540 | "</td>" |
| 541 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 542 | "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 543 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 544 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 545 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 546 | "</ul>" |
| 547 | "</td>" |
| 548 | "</tr></table>\n" |
| 549 | "" |
| 550 | ); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 551 | |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 552 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 553 | return 0; |
| 554 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 555 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 556 | s->data_ctx.stats.px = proxy; |
| 557 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 558 | s->data_state = DATA_ST_LIST; |
| 559 | /* fall through */ |
| 560 | |
| 561 | case DATA_ST_LIST: |
| 562 | /* dump proxies */ |
| 563 | while (s->data_ctx.stats.px) { |
| 564 | px = s->data_ctx.stats.px; |
| 565 | /* skip the disabled proxies and non-networked ones */ |
| 566 | 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] | 567 | if (stats_dump_proxy(s, px, uri) == 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 568 | return 0; |
| 569 | |
| 570 | s->data_ctx.stats.px = px->next; |
| 571 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 572 | } |
| 573 | /* here, we just have reached the last proxy */ |
| 574 | |
| 575 | s->data_state = DATA_ST_END; |
| 576 | /* fall through */ |
| 577 | |
| 578 | case DATA_ST_END: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 579 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 580 | chunk_printf(&msg, sizeof(trash), "</body></html>\n"); |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 581 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 582 | return 0; |
| 583 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 584 | |
| 585 | s->data_state = DATA_ST_FIN; |
| 586 | /* fall through */ |
| 587 | |
| 588 | case DATA_ST_FIN: |
Willy Tarreau | 72b179a | 2008-08-28 16:01:32 +0200 | [diff] [blame] | 589 | buffer_stop_hijack(rep); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 590 | return 1; |
| 591 | |
| 592 | default: |
| 593 | /* unknown state ! */ |
Willy Tarreau | 72b179a | 2008-08-28 16:01:32 +0200 | [diff] [blame] | 594 | buffer_stop_hijack(rep); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 595 | return -1; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | |
| 600 | /* |
| 601 | * Dumps statistics for a proxy. |
| 602 | * Returns 0 if it had to stop dumping data because of lack of buffer space, |
| 603 | * ot non-zero if everything completed. |
| 604 | */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 605 | 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] | 606 | { |
| 607 | struct buffer *rep = s->rep; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 608 | struct server *sv, *svs; /* server and server-state, server-state=server or server->tracked */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 609 | struct chunk msg; |
| 610 | |
| 611 | msg.len = 0; |
| 612 | msg.str = trash; |
| 613 | |
| 614 | switch (s->data_ctx.stats.px_st) { |
| 615 | case DATA_ST_PX_INIT: |
| 616 | /* we are on a new proxy */ |
| 617 | |
| 618 | if (uri && uri->scope) { |
| 619 | /* we have a limited scope, we have to check the proxy name */ |
| 620 | struct stat_scope *scope; |
| 621 | int len; |
| 622 | |
| 623 | len = strlen(px->id); |
| 624 | scope = uri->scope; |
| 625 | |
| 626 | while (scope) { |
| 627 | /* match exact proxy name */ |
| 628 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 629 | break; |
| 630 | |
| 631 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 632 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 633 | break; |
| 634 | scope = scope->next; |
| 635 | } |
| 636 | |
| 637 | /* proxy name not found : don't dump anything */ |
| 638 | if (scope == NULL) |
| 639 | return 1; |
| 640 | } |
| 641 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 642 | 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] | 643 | (px->uuid != s->data_ctx.stats.iid)) |
| 644 | return 1; |
| 645 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 646 | s->data_ctx.stats.px_st = DATA_ST_PX_TH; |
| 647 | /* fall through */ |
| 648 | |
| 649 | case DATA_ST_PX_TH: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 650 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 651 | /* print a new table */ |
| 652 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 653 | "<table cols=\"26\" class=\"tbl\" width=\"100%%\">\n" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 654 | "<tr align=\"center\" class=\"titre\">" |
| 655 | "<th colspan=2 class=\"pxname\">%s</th>" |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 656 | "<th colspan=24 class=\"empty\"></th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 657 | "</tr>\n" |
| 658 | "<tr align=\"center\" class=\"titre\">" |
| 659 | "<th rowspan=2></th>" |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 660 | "<th colspan=3>Queue</th><th colspan=5>Sessions</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 661 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 662 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 663 | "<th colspan=8>Server</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 664 | "</tr>\n" |
| 665 | "<tr align=\"center\" class=\"titre\">" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 666 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 667 | "<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] | 668 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 669 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 670 | "<th>Status</th><th>Wght</th><th>Act</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 671 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 672 | "<th>Thrtle</th>\n" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 673 | "</tr>", |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 674 | px->id); |
| 675 | |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 676 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 677 | return 0; |
| 678 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 679 | |
| 680 | s->data_ctx.stats.px_st = DATA_ST_PX_FE; |
| 681 | /* fall through */ |
| 682 | |
| 683 | case DATA_ST_PX_FE: |
| 684 | /* print the frontend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 685 | if ((px->cap & PR_CAP_FE) && |
| 686 | (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_FE)))) { |
| 687 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 688 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 689 | /* name, queue */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 690 | "<tr align=center class=\"frontend\"><td>Frontend</td><td colspan=3></td>" |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 691 | /* sessions : current, max, limit, total, lbtot */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 692 | "<td align=right>%d</td><td align=right>%d</td>" |
| 693 | "<td align=right>%d</td><td align=right>%d</td>" |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 694 | "<td align=right></td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 695 | /* bytes : in, out */ |
| 696 | "<td align=right>%lld</td><td align=right>%lld</td>" |
| 697 | /* denied: req, resp */ |
| 698 | "<td align=right>%d</td><td align=right>%d</td>" |
| 699 | /* errors : request, connect, response */ |
| 700 | "<td align=right>%d</td><td align=right></td><td align=right></td>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 701 | /* warnings: retries, redispatches */ |
| 702 | "<td align=right></td><td align=right></td>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 703 | /* server status : reflect frontend status */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 704 | "<td align=center>%s</td>" |
| 705 | /* rest of server: nothing */ |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 706 | "<td align=center colspan=7></td></tr>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 707 | "", |
| 708 | px->feconn, px->feconn_max, px->maxconn, px->cum_feconn, |
| 709 | px->bytes_in, px->bytes_out, |
| 710 | px->denied_req, px->denied_resp, |
| 711 | px->failed_req, |
| 712 | px->state == PR_STRUN ? "OPEN" : |
| 713 | px->state == PR_STIDLE ? "FULL" : "STOP"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 714 | } else { |
| 715 | chunk_printf(&msg, sizeof(trash), |
| 716 | /* pxid, name, queue cur, queue max, */ |
| 717 | "%s,FRONTEND,,," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 718 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 719 | "%d,%d,%d,%d," |
| 720 | /* bytes : in, out */ |
| 721 | "%lld,%lld," |
| 722 | /* denied: req, resp */ |
| 723 | "%d,%d," |
| 724 | /* errors : request, connect, response */ |
| 725 | "%d,,," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 726 | /* warnings: retries, redispatches */ |
| 727 | ",," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 728 | /* server status : reflect frontend status */ |
| 729 | "%s," |
| 730 | /* rest of server: nothing */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 731 | ",,,,,,,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 732 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 733 | "%d,%d,0,,,,%d," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 734 | "\n", |
| 735 | px->id, |
| 736 | px->feconn, px->feconn_max, px->maxconn, px->cum_feconn, |
| 737 | px->bytes_in, px->bytes_out, |
| 738 | px->denied_req, px->denied_resp, |
| 739 | px->failed_req, |
| 740 | px->state == PR_STRUN ? "OPEN" : |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 741 | px->state == PR_STIDLE ? "FULL" : "STOP", |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 742 | relative_pid, px->uuid, STATS_TYPE_FE); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 743 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 744 | |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 745 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 746 | return 0; |
| 747 | } |
| 748 | |
| 749 | s->data_ctx.stats.sv = px->srv; /* may be NULL */ |
| 750 | s->data_ctx.stats.px_st = DATA_ST_PX_SV; |
| 751 | /* fall through */ |
| 752 | |
| 753 | case DATA_ST_PX_SV: |
| 754 | /* stats.sv has been initialized above */ |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 755 | for (; s->data_ctx.stats.sv != NULL; s->data_ctx.stats.sv = sv->next) { |
| 756 | |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 757 | 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] | 758 | |
| 759 | sv = s->data_ctx.stats.sv; |
| 760 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 761 | if (s->data_ctx.stats.flags & STAT_BOUND) { |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 762 | if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SV))) |
| 763 | break; |
| 764 | |
| 765 | if (s->data_ctx.stats.sid != -1 && sv->puid != s->data_ctx.stats.sid) |
| 766 | continue; |
| 767 | } |
| 768 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 769 | if (sv->tracked) |
| 770 | svs = sv->tracked; |
| 771 | else |
| 772 | svs = sv; |
| 773 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 774 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 775 | if (!(svs->state & SRV_CHECKED)) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 776 | sv_state = 6; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 777 | else if (svs->state & SRV_RUNNING) { |
| 778 | if (svs->health == svs->rise + svs->fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 779 | sv_state = 3; /* UP */ |
| 780 | else |
| 781 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 782 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 783 | if (svs->state & SRV_GOINGDOWN) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 784 | sv_state += 2; |
| 785 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 786 | else |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 787 | if (svs->health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 788 | sv_state = 1; /* going up */ |
| 789 | else |
| 790 | sv_state = 0; /* DOWN */ |
| 791 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 792 | if ((sv_state == 0) && (s->data_ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 793 | /* do not report servers which are DOWN */ |
| 794 | s->data_ctx.stats.sv = sv->next; |
| 795 | continue; |
| 796 | } |
| 797 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 798 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 799 | static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d ↑", |
| 800 | "UP %d/%d ↓", "UP", |
| 801 | "NOLB %d/%d ↓", "NOLB", |
| 802 | "<i>no check</i>" }; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 803 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 804 | /* name */ |
| 805 | "<tr align=\"center\" class=\"%s%d\"><td>%s</td>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 806 | /* queue : current, max, limit */ |
| 807 | "<td align=right>%d</td><td align=right>%d</td><td align=right>%s</td>" |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 808 | /* sessions : current, max, limit, total, lbtot */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 809 | "<td align=right>%d</td><td align=right>%d</td>" |
| 810 | "<td align=right>%s</td><td align=right>%d</td>" |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 811 | "<td align=right>%d</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 812 | /* bytes : in, out */ |
| 813 | "<td align=right>%lld</td><td align=right>%lld</td>" |
| 814 | /* denied: req, resp */ |
| 815 | "<td align=right></td><td align=right>%d</td>" |
| 816 | /* errors : request, connect, response */ |
| 817 | "<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 818 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 819 | "<td align=right>%u</td><td align=right>%u</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 820 | "", |
| 821 | (sv->state & SRV_BACKUP) ? "backup" : "active", |
| 822 | sv_state, sv->id, |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 823 | sv->nbpend, sv->nbpend_max, LIM2A0(sv->maxqueue, "-"), |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 824 | sv->cur_sess, sv->cur_sess_max, LIM2A1(sv->maxconn, "-"), |
| 825 | sv->cum_sess, sv->cum_lbconn, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 826 | sv->bytes_in, sv->bytes_out, |
| 827 | sv->failed_secu, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 828 | sv->failed_conns, sv->failed_resp, |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 829 | sv->retries, sv->redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 830 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 831 | /* status */ |
| 832 | chunk_printf(&msg, sizeof(trash), "<td nowrap>"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 833 | |
| 834 | if (sv->state & SRV_CHECKED) |
| 835 | chunk_printf(&msg, sizeof(trash), "%s ", |
| 836 | human_time(now.tv_sec - sv->last_change, 1)); |
| 837 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 838 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 839 | srv_hlt_st[sv_state], |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 840 | (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), |
| 841 | (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 842 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 843 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 844 | /* weight */ |
| 845 | "</td><td>%d</td>" |
| 846 | /* act, bck */ |
| 847 | "<td>%s</td><td>%s</td>" |
| 848 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 849 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 850 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 851 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 852 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 853 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 854 | if (sv->state & SRV_CHECKED) |
| 855 | chunk_printf(&msg, sizeof(trash), |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 856 | "<td align=right>%d</td><td align=right>%d</td>" |
| 857 | "<td nowrap align=right>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 858 | "", |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 859 | svs->failed_checks, svs->down_trans, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 860 | human_time(srv_downtime(sv), 1)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 861 | else if (sv != svs) |
| 862 | chunk_printf(&msg, sizeof(trash), |
| 863 | "<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] | 864 | else |
| 865 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 866 | "<td colspan=3></td>"); |
| 867 | |
| 868 | /* throttle */ |
| 869 | if ((sv->state & SRV_WARMINGUP) && |
| 870 | now.tv_sec < sv->last_change + sv->slowstart && |
| 871 | now.tv_sec >= sv->last_change) { |
| 872 | unsigned int ratio; |
| 873 | ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); |
| 874 | chunk_printf(&msg, sizeof(trash), |
| 875 | "<td>%d %%</td></tr>\n", ratio); |
| 876 | } else { |
| 877 | chunk_printf(&msg, sizeof(trash), |
| 878 | "<td>-</td></tr>\n"); |
| 879 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 880 | } else { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 881 | static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,", |
| 882 | "UP %d/%d,", "UP,", |
| 883 | "NOLB %d/%d,", "NOLB,", |
| 884 | "no check," }; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 885 | chunk_printf(&msg, sizeof(trash), |
| 886 | /* pxid, name */ |
| 887 | "%s,%s," |
| 888 | /* queue : current, max */ |
| 889 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 890 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 891 | "%d,%d,%s,%d," |
| 892 | /* bytes : in, out */ |
| 893 | "%lld,%lld," |
| 894 | /* denied: req, resp */ |
| 895 | ",%d," |
| 896 | /* errors : request, connect, response */ |
| 897 | ",%d,%d," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 898 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 899 | "%u,%u," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 900 | "", |
| 901 | px->id, sv->id, |
| 902 | sv->nbpend, sv->nbpend_max, |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 903 | sv->cur_sess, sv->cur_sess_max, LIM2A0(sv->maxconn, ""), sv->cum_sess, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 904 | sv->bytes_in, sv->bytes_out, |
| 905 | sv->failed_secu, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 906 | sv->failed_conns, sv->failed_resp, |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 907 | sv->retries, sv->redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 908 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 909 | /* status */ |
| 910 | chunk_printf(&msg, sizeof(trash), |
| 911 | srv_hlt_st[sv_state], |
| 912 | (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health), |
| 913 | (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 914 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 915 | chunk_printf(&msg, sizeof(trash), |
| 916 | /* weight, active, backup */ |
| 917 | "%d,%d,%d," |
| 918 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 919 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 920 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 921 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 922 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 923 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 924 | if (sv->state & SRV_CHECKED) |
| 925 | chunk_printf(&msg, sizeof(trash), |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 926 | "%d,%d,%d,%d,", |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 927 | sv->failed_checks, sv->down_trans, |
| 928 | now.tv_sec - sv->last_change, srv_downtime(sv)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 929 | else |
| 930 | chunk_printf(&msg, sizeof(trash), |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 931 | ",,,,"); |
| 932 | |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 933 | /* queue limit, pid, iid, sid, */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 934 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 935 | "%s," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 936 | "%d,%d,%d,", |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 937 | LIM2A0(sv->maxqueue, ""), |
| 938 | relative_pid, px->uuid, sv->puid); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 939 | |
| 940 | /* throttle */ |
| 941 | if ((sv->state & SRV_WARMINGUP) && |
| 942 | now.tv_sec < sv->last_change + sv->slowstart && |
| 943 | now.tv_sec >= sv->last_change) { |
| 944 | unsigned int ratio; |
| 945 | ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 946 | chunk_printf(&msg, sizeof(trash), "%d", ratio); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 947 | } |
| 948 | |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 949 | /* sessions: lbtot */ |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 950 | chunk_printf(&msg, sizeof(trash), ",%d,", sv->cum_lbconn); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 951 | |
| 952 | /* tracked */ |
| 953 | if (sv->tracked) |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 954 | chunk_printf(&msg, sizeof(trash), "%s/%s,", |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 955 | sv->tracked->proxy->id, sv->tracked->id); |
| 956 | else |
| 957 | chunk_printf(&msg, sizeof(trash), ","); |
| 958 | |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 959 | /* type, then EOL */ |
| 960 | chunk_printf(&msg, sizeof(trash), "%d,\n", STATS_TYPE_SV); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 961 | } |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 962 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 963 | return 0; |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 964 | } /* for sv */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 965 | |
| 966 | s->data_ctx.stats.px_st = DATA_ST_PX_BE; |
| 967 | /* fall through */ |
| 968 | |
| 969 | case DATA_ST_PX_BE: |
| 970 | /* print the backend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 971 | if ((px->cap & PR_CAP_BE) && |
| 972 | (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_BE)))) { |
| 973 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 974 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 975 | /* name */ |
| 976 | "<tr align=center class=\"backend\"><td>Backend</td>" |
| 977 | /* queue : current, max */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 978 | "<td align=right>%d</td><td align=right>%d</td><td></td>" |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 979 | /* sessions : current, max, limit, total, lbtot */ |
| 980 | "<td align=right>%d</td><td align=right>%d</td>" |
| 981 | "<td align=right>%d</td><td align=right>%d</td>" |
| 982 | "<td align=right>%d</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 983 | /* bytes : in, out */ |
| 984 | "<td align=right>%lld</td><td align=right>%lld</td>" |
| 985 | /* denied: req, resp */ |
| 986 | "<td align=right>%d</td><td align=right>%d</td>" |
| 987 | /* errors : request, connect, response */ |
| 988 | "<td align=right></td><td align=right>%d</td><td align=right>%d</td>\n" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 989 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 990 | "<td align=right>%u</td><td align=right>%u</td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 991 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 992 | * 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] | 993 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 994 | * active and backups. */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 995 | "<td align=center nowrap>%s %s</td><td align=center>%d</td>" |
| 996 | "<td align=center>%d</td><td align=center>%d</td>", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 997 | px->nbpend /* or px->totpend ? */, px->nbpend_max, |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 998 | px->beconn, px->beconn_max, px->fullconn, px->cum_beconn, px->cum_lbconn, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 999 | px->bytes_in, px->bytes_out, |
| 1000 | px->denied_req, px->denied_resp, |
| 1001 | px->failed_conns, px->failed_resp, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1002 | px->retries, px->redispatches, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1003 | human_time(now.tv_sec - px->last_change, 1), |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1004 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 1005 | "<font color=\"red\"><b>DOWN</b></font>", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1006 | (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] | 1007 | px->srv_act, px->srv_bck); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1008 | |
| 1009 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1010 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1011 | "<td align=center> </td><td align=\"right\">%d</td>" |
| 1012 | "<td align=\"right\" nowrap>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1013 | "<td></td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1014 | "</tr>", |
| 1015 | px->down_trans, |
| 1016 | px->srv?human_time(be_downtime(px), 1):" "); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1017 | } else { |
| 1018 | chunk_printf(&msg, sizeof(trash), |
| 1019 | /* pxid, name */ |
| 1020 | "%s,BACKEND," |
| 1021 | /* queue : current, max */ |
| 1022 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1023 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1024 | "%d,%d,%d,%d," |
| 1025 | /* bytes : in, out */ |
| 1026 | "%lld,%lld," |
| 1027 | /* denied: req, resp */ |
| 1028 | "%d,%d," |
| 1029 | /* errors : request, connect, response */ |
| 1030 | ",%d,%d," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1031 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 1032 | "%u,%u," |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1033 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1034 | * 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] | 1035 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1036 | * active and backups. */ |
| 1037 | "%s," |
| 1038 | "%d,%d,%d," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1039 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1040 | ",%d,%d,%d,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1041 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 1042 | "%d,%d,0,,%d,,%d," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1043 | "\n", |
| 1044 | px->id, |
| 1045 | px->nbpend /* or px->totpend ? */, px->nbpend_max, |
| 1046 | px->beconn, px->beconn_max, px->fullconn, px->cum_beconn, |
| 1047 | px->bytes_in, px->bytes_out, |
| 1048 | px->denied_req, px->denied_resp, |
| 1049 | px->failed_conns, px->failed_resp, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1050 | px->retries, px->redispatches, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 1051 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1052 | (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] | 1053 | px->srv_act, px->srv_bck, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1054 | px->down_trans, now.tv_sec - px->last_change, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 1055 | px->srv?be_downtime(px):0, |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1056 | relative_pid, px->uuid, |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1057 | px->cum_lbconn, STATS_TYPE_BE); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1058 | } |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 1059 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1060 | return 0; |
| 1061 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1062 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1063 | s->data_ctx.stats.px_st = DATA_ST_PX_END; |
| 1064 | /* fall through */ |
| 1065 | |
| 1066 | case DATA_ST_PX_END: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1067 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1068 | chunk_printf(&msg, sizeof(trash), "</table><p>\n"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1069 | |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 1070 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1071 | return 0; |
| 1072 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1073 | |
| 1074 | s->data_ctx.stats.px_st = DATA_ST_PX_FIN; |
| 1075 | /* fall through */ |
| 1076 | |
| 1077 | case DATA_ST_PX_FIN: |
| 1078 | return 1; |
| 1079 | |
| 1080 | default: |
| 1081 | /* unknown state, we should put an abort() here ! */ |
| 1082 | return 1; |
| 1083 | } |
| 1084 | } |
| 1085 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1086 | |
| 1087 | /* This function is called to send output to the response buffer. |
| 1088 | * It dumps the sessions states onto the output buffer <rep>. |
| 1089 | * Expects to be called with client socket shut down on input. |
| 1090 | * s->data_ctx must have been zeroed first, and the flags properly set. |
| 1091 | * It automatically clears the HIJACK bit from the response buffer. |
| 1092 | */ |
| 1093 | void stats_dump_sess_to_buffer(struct session *s, struct buffer *rep) |
| 1094 | { |
| 1095 | struct chunk msg; |
| 1096 | |
| 1097 | if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) { |
| 1098 | /* If we're forced to shut down, we might have to remove our |
| 1099 | * reference to the last session being dumped. |
| 1100 | */ |
| 1101 | if (s->data_state == DATA_ST_LIST) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1102 | if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1103 | LIST_DEL(&s->data_ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1104 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1105 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1106 | } |
| 1107 | s->data_state = DATA_ST_FIN; |
| 1108 | buffer_stop_hijack(rep); |
| 1109 | s->ana_state = STATS_ST_CLOSE; |
| 1110 | return; |
| 1111 | } |
| 1112 | |
| 1113 | if (s->ana_state != STATS_ST_REP) |
| 1114 | return; |
| 1115 | |
| 1116 | msg.len = 0; |
| 1117 | msg.str = trash; |
| 1118 | |
| 1119 | switch (s->data_state) { |
| 1120 | case DATA_ST_INIT: |
| 1121 | /* the function had not been called yet, let's prepare the |
| 1122 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1123 | * pointer to the first in the global list. When a target |
| 1124 | * session is being destroyed, it is responsible for updating |
| 1125 | * this pointer. We know we have reached the end when this |
| 1126 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1127 | */ |
| 1128 | stream_int_retnclose(rep->cons, &msg); |
| 1129 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1130 | s->data_ctx.sess.bref.ref = sessions.n; |
| 1131 | s->data_state = DATA_ST_LIST; |
| 1132 | /* fall through */ |
| 1133 | |
| 1134 | case DATA_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1135 | /* first, let's detach the back-ref from a possible previous session */ |
| 1136 | if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) { |
| 1137 | LIST_DEL(&s->data_ctx.sess.bref.users); |
| 1138 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1139 | } |
| 1140 | |
| 1141 | /* and start from where we stopped */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1142 | while (s->data_ctx.sess.bref.ref != &sessions) { |
| 1143 | char pn[INET6_ADDRSTRLEN + strlen(":65535")]; |
| 1144 | struct session *curr_sess; |
| 1145 | |
| 1146 | curr_sess = LIST_ELEM(s->data_ctx.sess.bref.ref, struct session *, list); |
| 1147 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1148 | chunk_printf(&msg, sizeof(trash), |
| 1149 | "%p: proto=%s", |
| 1150 | curr_sess, |
| 1151 | curr_sess->listener->proto->name); |
| 1152 | |
| 1153 | switch (curr_sess->listener->proto->sock_family) { |
| 1154 | case AF_INET: |
| 1155 | inet_ntop(AF_INET, |
| 1156 | (const void *)&((struct sockaddr_in *)&curr_sess->cli_addr)->sin_addr, |
| 1157 | pn, sizeof(pn)); |
| 1158 | |
| 1159 | chunk_printf(&msg, sizeof(trash), |
| 1160 | " src=%s:%d fe=%s be=%s srv=%s", |
| 1161 | pn, |
| 1162 | ntohs(((struct sockaddr_in *)&curr_sess->cli_addr)->sin_port), |
| 1163 | curr_sess->fe->id, |
| 1164 | curr_sess->be->id, |
| 1165 | curr_sess->srv ? curr_sess->srv->id : "<none>" |
| 1166 | ); |
| 1167 | break; |
| 1168 | case AF_INET6: |
| 1169 | inet_ntop(AF_INET6, |
| 1170 | (const void *)&((struct sockaddr_in6 *)(&curr_sess->cli_addr))->sin6_addr, |
| 1171 | pn, sizeof(pn)); |
| 1172 | |
| 1173 | chunk_printf(&msg, sizeof(trash), |
| 1174 | " src=%s:%d fe=%s be=%s srv=%s", |
| 1175 | pn, |
| 1176 | ntohs(((struct sockaddr_in6 *)&curr_sess->cli_addr)->sin6_port), |
| 1177 | curr_sess->fe->id, |
| 1178 | curr_sess->be->id, |
| 1179 | curr_sess->srv ? curr_sess->srv->id : "<none>" |
| 1180 | ); |
| 1181 | |
| 1182 | break; |
| 1183 | case AF_UNIX: |
| 1184 | /* no more information to print right now */ |
| 1185 | break; |
| 1186 | } |
| 1187 | |
| 1188 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 8a5c626 | 2008-12-08 00:16:21 +0100 | [diff] [blame] | 1189 | " si=(%d,%d) as=%d ts=%02x age=%s", |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1190 | curr_sess->si[0].state, curr_sess->si[1].state, |
Willy Tarreau | 8a5c626 | 2008-12-08 00:16:21 +0100 | [diff] [blame] | 1191 | curr_sess->ana_state, curr_sess->task->state, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1192 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1)); |
| 1193 | |
Willy Tarreau | 8a5c626 | 2008-12-08 00:16:21 +0100 | [diff] [blame] | 1194 | if (curr_sess->task->state & TASK_IN_RUNQUEUE) |
| 1195 | chunk_printf(&msg, sizeof(trash), " run(nice=%d)\n", curr_sess->task->nice); |
| 1196 | else |
| 1197 | chunk_printf(&msg, sizeof(trash), |
| 1198 | " exp=%s\n", |
| 1199 | curr_sess->task->expire ? |
| 1200 | human_time(TICKS_TO_MS(tick_remain(now_ms, curr_sess->task->expire)), |
| 1201 | TICKS_TO_MS(1000)) |
| 1202 | : "never"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1203 | |
| 1204 | if (buffer_write_chunk(rep, &msg) >= 0) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1205 | /* let's try again later from this session. We add ourselves into |
| 1206 | * this session's users so that it can remove us upon termination. |
| 1207 | */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1208 | LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users); |
| 1209 | return; |
| 1210 | } |
| 1211 | |
| 1212 | s->data_ctx.sess.bref.ref = curr_sess->list.n; |
| 1213 | } |
| 1214 | s->data_state = DATA_ST_FIN; |
| 1215 | /* fall through */ |
| 1216 | |
| 1217 | default: |
| 1218 | s->data_state = DATA_ST_FIN; |
| 1219 | buffer_stop_hijack(rep); |
| 1220 | s->ana_state = STATS_ST_CLOSE; |
| 1221 | return; |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 1226 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 1227 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 1228 | { 0, NULL, NULL }, |
| 1229 | }}; |
| 1230 | |
| 1231 | __attribute__((constructor)) |
| 1232 | static void __dumpstats_module_init(void) |
| 1233 | { |
| 1234 | cfg_register_keywords(&cfg_kws); |
| 1235 | } |
| 1236 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1237 | /* |
| 1238 | * Local variables: |
| 1239 | * c-indent-level: 8 |
| 1240 | * c-basic-offset: 8 |
| 1241 | * End: |
| 1242 | */ |