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