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 {" |
| 378 | " font-family: helvetica, arial;" |
| 379 | " font-size: 12px;" |
| 380 | " font-weight: normal;" |
| 381 | " color: black;" |
| 382 | " background: white;" |
| 383 | "}\n" |
| 384 | "th,td {" |
| 385 | " font-size: 0.8em;" |
| 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 | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 662 | "<table cols=\"27\" 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 | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 665 | "<th colspan=25 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 | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 669 | "<th colspan=3>Queue</th><th colspan=6>Sessions</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 670 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 671 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 672 | "<th colspan=8>Server</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 673 | "</tr>\n" |
| 674 | "<tr align=\"center\" class=\"titre\">" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 675 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 676 | "<th>Limit</th><th>Rate</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] | 677 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 678 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 679 | "<th>Status</th><th>Wght</th><th>Act</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 680 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 681 | "<th>Thrtle</th>\n" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 682 | "</tr>", |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 683 | px->id); |
| 684 | |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 685 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 686 | return 0; |
| 687 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 688 | |
| 689 | s->data_ctx.stats.px_st = DATA_ST_PX_FE; |
| 690 | /* fall through */ |
| 691 | |
| 692 | case DATA_ST_PX_FE: |
| 693 | /* print the frontend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 694 | if ((px->cap & PR_CAP_FE) && |
| 695 | (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_FE)))) { |
| 696 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 697 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 698 | /* name, queue */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 699 | "<tr align=center class=\"frontend\"><td>Frontend</td><td colspan=3></td>" |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 700 | /* sessions : current, max, limit, rate, total, lbtot */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 701 | "<td align=right>%s</td><td align=right>%s</td>" |
| 702 | "<td align=right>%s</td><td align=right>%s</td>" |
| 703 | "<td align=right>%s</td><td align=right></td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 704 | /* bytes : in, out */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 705 | "<td align=right>%s</td><td align=right>%s</td>" |
| 706 | "", |
| 707 | U2H0(px->feconn), U2H1(px->feconn_max), U2H2(px->maxconn), |
| 708 | U2H3(read_freq_ctr(&px->fe_sess_per_sec)), U2H4(px->cum_feconn), |
| 709 | U2H5(px->bytes_in), U2H6(px->bytes_out)); |
| 710 | |
| 711 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 712 | /* denied: req, resp */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 713 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 714 | /* errors : request, connect, response */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 715 | "<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] | 716 | /* warnings: retries, redispatches */ |
| 717 | "<td align=right></td><td align=right></td>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 718 | /* server status : reflect frontend status */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 719 | "<td align=center>%s</td>" |
| 720 | /* rest of server: nothing */ |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 721 | "<td align=center colspan=7></td></tr>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 722 | "", |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 723 | U2H0(px->denied_req), U2H1(px->denied_resp), |
| 724 | U2H2(px->failed_req), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 725 | px->state == PR_STRUN ? "OPEN" : |
| 726 | px->state == PR_STIDLE ? "FULL" : "STOP"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 727 | } else { |
| 728 | chunk_printf(&msg, sizeof(trash), |
| 729 | /* pxid, name, queue cur, queue max, */ |
| 730 | "%s,FRONTEND,,," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 731 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 732 | "%d,%d,%d,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 733 | /* bytes : in, out */ |
| 734 | "%lld,%lld," |
| 735 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 736 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 737 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 738 | "%lld,,," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 739 | /* warnings: retries, redispatches */ |
| 740 | ",," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 741 | /* server status : reflect frontend status */ |
| 742 | "%s," |
| 743 | /* rest of server: nothing */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 744 | ",,,,,,,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 745 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 746 | "%d,%d,0,,,,%d," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame^] | 747 | /* rate, rate_lim, rate_max, */ |
| 748 | "%u,%u,%u," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 749 | "\n", |
| 750 | px->id, |
| 751 | px->feconn, px->feconn_max, px->maxconn, px->cum_feconn, |
| 752 | px->bytes_in, px->bytes_out, |
| 753 | px->denied_req, px->denied_resp, |
| 754 | px->failed_req, |
| 755 | px->state == PR_STRUN ? "OPEN" : |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 756 | px->state == PR_STIDLE ? "FULL" : "STOP", |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 757 | relative_pid, px->uuid, STATS_TYPE_FE, |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame^] | 758 | read_freq_ctr(&px->fe_sess_per_sec), |
| 759 | px->fe_sps_lim, px->fe_sps_max); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 760 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 761 | |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 762 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | s->data_ctx.stats.sv = px->srv; /* may be NULL */ |
| 767 | s->data_ctx.stats.px_st = DATA_ST_PX_SV; |
| 768 | /* fall through */ |
| 769 | |
| 770 | case DATA_ST_PX_SV: |
| 771 | /* stats.sv has been initialized above */ |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 772 | for (; s->data_ctx.stats.sv != NULL; s->data_ctx.stats.sv = sv->next) { |
| 773 | |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 774 | 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] | 775 | |
| 776 | sv = s->data_ctx.stats.sv; |
| 777 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 778 | if (s->data_ctx.stats.flags & STAT_BOUND) { |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 779 | if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SV))) |
| 780 | break; |
| 781 | |
| 782 | if (s->data_ctx.stats.sid != -1 && sv->puid != s->data_ctx.stats.sid) |
| 783 | continue; |
| 784 | } |
| 785 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 786 | if (sv->tracked) |
| 787 | svs = sv->tracked; |
| 788 | else |
| 789 | svs = sv; |
| 790 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 791 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 792 | if (!(svs->state & SRV_CHECKED)) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 793 | sv_state = 6; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 794 | else if (svs->state & SRV_RUNNING) { |
| 795 | if (svs->health == svs->rise + svs->fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 796 | sv_state = 3; /* UP */ |
| 797 | else |
| 798 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 799 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 800 | if (svs->state & SRV_GOINGDOWN) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 801 | sv_state += 2; |
| 802 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 803 | else |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 804 | if (svs->health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 805 | sv_state = 1; /* going up */ |
| 806 | else |
| 807 | sv_state = 0; /* DOWN */ |
| 808 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 809 | if ((sv_state == 0) && (s->data_ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 810 | /* do not report servers which are DOWN */ |
| 811 | s->data_ctx.stats.sv = sv->next; |
| 812 | continue; |
| 813 | } |
| 814 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 815 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 816 | static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d ↑", |
| 817 | "UP %d/%d ↓", "UP", |
| 818 | "NOLB %d/%d ↓", "NOLB", |
| 819 | "<i>no check</i>" }; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 820 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 821 | /* name */ |
| 822 | "<tr align=\"center\" class=\"%s%d\"><td>%s</td>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 823 | /* queue : current, max, limit */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 824 | "<td align=right>%s</td><td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 825 | /* sessions : current, max, limit, rate, total, lbtot */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 826 | "<td align=right>%s</td><td align=right>%s</td>" |
| 827 | "<td align=right>%s</td><td align=right>%s</td>" |
| 828 | "<td align=right>%s</td><td align=right>%s</td>" |
| 829 | "", |
| 830 | (sv->state & SRV_BACKUP) ? "backup" : "active", |
| 831 | sv_state, sv->id, |
| 832 | U2H0(sv->nbpend), U2H1(sv->nbpend_max), LIM2A2(sv->maxqueue, "-"), |
| 833 | U2H3(sv->cur_sess), U2H4(sv->cur_sess_max), LIM2A5(sv->maxconn, "-"), |
| 834 | U2H6(read_freq_ctr(&sv->sess_per_sec)), |
| 835 | U2H7(sv->cum_sess), U2H8(sv->cum_lbconn)); |
| 836 | |
| 837 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 838 | /* bytes : in, out */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 839 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 840 | /* denied: req, resp */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 841 | "<td align=right></td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 842 | /* errors : request, connect, response */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 843 | "<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] | 844 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 845 | "<td align=right>%lld</td><td align=right>%lld</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 846 | "", |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 847 | U2H0(sv->bytes_in), U2H1(sv->bytes_out), |
| 848 | U2H2(sv->failed_secu), |
| 849 | U2H3(sv->failed_conns), U2H4(sv->failed_resp), |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 850 | sv->retries, sv->redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 851 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 852 | /* status */ |
| 853 | chunk_printf(&msg, sizeof(trash), "<td nowrap>"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 854 | |
| 855 | if (sv->state & SRV_CHECKED) |
| 856 | chunk_printf(&msg, sizeof(trash), "%s ", |
| 857 | human_time(now.tv_sec - sv->last_change, 1)); |
| 858 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 859 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 860 | srv_hlt_st[sv_state], |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 861 | (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), |
| 862 | (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 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 | /* weight */ |
| 866 | "</td><td>%d</td>" |
| 867 | /* act, bck */ |
| 868 | "<td>%s</td><td>%s</td>" |
| 869 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 870 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 871 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 872 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 873 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 874 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 875 | if (sv->state & SRV_CHECKED) |
| 876 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 877 | "<td align=right>%lld</td><td align=right>%lld</td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 878 | "<td nowrap align=right>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 879 | "", |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 880 | svs->failed_checks, svs->down_trans, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 881 | human_time(srv_downtime(sv), 1)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 882 | else if (sv != svs) |
| 883 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 884 | "<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] | 885 | else |
| 886 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 887 | "<td colspan=3></td>"); |
| 888 | |
| 889 | /* throttle */ |
| 890 | if ((sv->state & SRV_WARMINGUP) && |
| 891 | now.tv_sec < sv->last_change + sv->slowstart && |
| 892 | now.tv_sec >= sv->last_change) { |
| 893 | unsigned int ratio; |
| 894 | ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); |
| 895 | chunk_printf(&msg, sizeof(trash), |
| 896 | "<td>%d %%</td></tr>\n", ratio); |
| 897 | } else { |
| 898 | chunk_printf(&msg, sizeof(trash), |
| 899 | "<td>-</td></tr>\n"); |
| 900 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 901 | } else { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 902 | static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,", |
| 903 | "UP %d/%d,", "UP,", |
| 904 | "NOLB %d/%d,", "NOLB,", |
| 905 | "no check," }; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 906 | chunk_printf(&msg, sizeof(trash), |
| 907 | /* pxid, name */ |
| 908 | "%s,%s," |
| 909 | /* queue : current, max */ |
| 910 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 911 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 912 | "%d,%d,%s,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 913 | /* bytes : in, out */ |
| 914 | "%lld,%lld," |
| 915 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 916 | ",%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 917 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 918 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 919 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 920 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 921 | "", |
| 922 | px->id, sv->id, |
| 923 | sv->nbpend, sv->nbpend_max, |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 924 | 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] | 925 | sv->bytes_in, sv->bytes_out, |
| 926 | sv->failed_secu, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 927 | sv->failed_conns, sv->failed_resp, |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 928 | sv->retries, sv->redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 929 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 930 | /* status */ |
| 931 | chunk_printf(&msg, sizeof(trash), |
| 932 | srv_hlt_st[sv_state], |
| 933 | (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health), |
| 934 | (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 935 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 936 | chunk_printf(&msg, sizeof(trash), |
| 937 | /* weight, active, backup */ |
| 938 | "%d,%d,%d," |
| 939 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 940 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 941 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 942 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 943 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 944 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 945 | if (sv->state & SRV_CHECKED) |
| 946 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 947 | "%lld,%lld,%d,%d,", |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 948 | sv->failed_checks, sv->down_trans, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 949 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 950 | else |
| 951 | chunk_printf(&msg, sizeof(trash), |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 952 | ",,,,"); |
| 953 | |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 954 | /* queue limit, pid, iid, sid, */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 955 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 956 | "%s," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 957 | "%d,%d,%d,", |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 958 | LIM2A0(sv->maxqueue, ""), |
| 959 | relative_pid, px->uuid, sv->puid); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 960 | |
| 961 | /* throttle */ |
| 962 | if ((sv->state & SRV_WARMINGUP) && |
| 963 | now.tv_sec < sv->last_change + sv->slowstart && |
| 964 | now.tv_sec >= sv->last_change) { |
| 965 | unsigned int ratio; |
| 966 | 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] | 967 | chunk_printf(&msg, sizeof(trash), "%d", ratio); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 968 | } |
| 969 | |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 970 | /* sessions: lbtot */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 971 | chunk_printf(&msg, sizeof(trash), ",%lld,", sv->cum_lbconn); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 972 | |
| 973 | /* tracked */ |
| 974 | if (sv->tracked) |
Krzysztof Piotr Oledzki | f58a962 | 2008-02-23 01:19:10 +0100 | [diff] [blame] | 975 | chunk_printf(&msg, sizeof(trash), "%s/%s,", |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 976 | sv->tracked->proxy->id, sv->tracked->id); |
| 977 | else |
| 978 | chunk_printf(&msg, sizeof(trash), ","); |
| 979 | |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 980 | /* type */ |
| 981 | chunk_printf(&msg, sizeof(trash), "%d,", STATS_TYPE_SV); |
| 982 | |
| 983 | /* rate */ |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame^] | 984 | chunk_printf(&msg, sizeof(trash), "%u,,%u,", |
| 985 | read_freq_ctr(&sv->sess_per_sec), |
| 986 | sv->sps_max); |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 987 | |
| 988 | /* finish with EOL */ |
| 989 | chunk_printf(&msg, sizeof(trash), "\n"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 990 | } |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 991 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 992 | return 0; |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 993 | } /* for sv */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 994 | |
| 995 | s->data_ctx.stats.px_st = DATA_ST_PX_BE; |
| 996 | /* fall through */ |
| 997 | |
| 998 | case DATA_ST_PX_BE: |
| 999 | /* print the backend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1000 | if ((px->cap & PR_CAP_BE) && |
| 1001 | (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_BE)))) { |
| 1002 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1003 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1004 | /* name */ |
| 1005 | "<tr align=center class=\"backend\"><td>Backend</td>" |
| 1006 | /* queue : current, max */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1007 | "<td align=right>%s</td><td align=right>%s</td><td></td>" |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 1008 | /* sessions : current, max, limit, rate, total, lbtot */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1009 | "<td align=right>%s</td><td align=right>%s</td>" |
| 1010 | "<td align=right>%s</td><td align=right>%s</td>" |
| 1011 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1012 | /* bytes : in, out */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1013 | "<td align=right>%s</td><td align=right>%s</td>" |
| 1014 | "", |
| 1015 | U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->nbpend_max), |
| 1016 | U2H2(px->beconn), U2H3(px->beconn_max), U2H4(px->fullconn), |
| 1017 | U2H5(read_freq_ctr(&px->be_sess_per_sec)), |
| 1018 | U2H6(px->cum_beconn), U2H7(px->cum_lbconn), |
| 1019 | U2H8(px->bytes_in), U2H9(px->bytes_out)); |
| 1020 | |
| 1021 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1022 | /* denied: req, resp */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1023 | "<td align=right>%s</td><td align=right>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1024 | /* errors : request, connect, response */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1025 | "<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] | 1026 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1027 | "<td align=right>%lld</td><td align=right>%lld</td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1028 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1029 | * 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] | 1030 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1031 | * active and backups. */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1032 | "<td align=center nowrap>%s %s</td><td align=center>%d</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1033 | "<td align=center>%d</td><td align=center>%d</td>" |
| 1034 | "", |
| 1035 | U2H0(px->denied_req), U2H1(px->denied_resp), |
| 1036 | U2H2(px->failed_conns), U2H3(px->failed_resp), |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1037 | px->retries, px->redispatches, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1038 | human_time(now.tv_sec - px->last_change, 1), |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1039 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 1040 | "<font color=\"red\"><b>DOWN</b></font>", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1041 | (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] | 1042 | px->srv_act, px->srv_bck); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1043 | |
| 1044 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1045 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1046 | "<td align=center> </td><td align=\"right\">%d</td>" |
| 1047 | "<td align=\"right\" nowrap>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1048 | "<td></td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1049 | "</tr>", |
| 1050 | px->down_trans, |
| 1051 | px->srv?human_time(be_downtime(px), 1):" "); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1052 | } else { |
| 1053 | chunk_printf(&msg, sizeof(trash), |
| 1054 | /* pxid, name */ |
| 1055 | "%s,BACKEND," |
| 1056 | /* queue : current, max */ |
| 1057 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1058 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1059 | "%d,%d,%d,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1060 | /* bytes : in, out */ |
| 1061 | "%lld,%lld," |
| 1062 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1063 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1064 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1065 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1066 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1067 | "%lld,%lld," |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1068 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1069 | * 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] | 1070 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1071 | * active and backups. */ |
| 1072 | "%s," |
| 1073 | "%d,%d,%d," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1074 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1075 | ",%d,%d,%d,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1076 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1077 | "%d,%d,0,,%lld,,%d," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame^] | 1078 | /* rate, rate_lim, rate_max, */ |
| 1079 | "%u,,%u," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1080 | "\n", |
| 1081 | px->id, |
| 1082 | px->nbpend /* or px->totpend ? */, px->nbpend_max, |
| 1083 | px->beconn, px->beconn_max, px->fullconn, px->cum_beconn, |
| 1084 | px->bytes_in, px->bytes_out, |
| 1085 | px->denied_req, px->denied_resp, |
| 1086 | px->failed_conns, px->failed_resp, |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1087 | px->retries, px->redispatches, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 1088 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1089 | (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] | 1090 | px->srv_act, px->srv_bck, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1091 | px->down_trans, (int)(now.tv_sec - px->last_change), |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 1092 | px->srv?be_downtime(px):0, |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1093 | relative_pid, px->uuid, |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 1094 | px->cum_lbconn, STATS_TYPE_BE, |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame^] | 1095 | read_freq_ctr(&px->be_sess_per_sec), |
| 1096 | px->be_sps_max); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1097 | } |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 1098 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1099 | return 0; |
| 1100 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1101 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1102 | s->data_ctx.stats.px_st = DATA_ST_PX_END; |
| 1103 | /* fall through */ |
| 1104 | |
| 1105 | case DATA_ST_PX_END: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1106 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1107 | chunk_printf(&msg, sizeof(trash), "</table><p>\n"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1108 | |
Krzysztof Piotr Oledzki | 8e4b21d | 2008-04-20 21:34:47 +0200 | [diff] [blame] | 1109 | if (buffer_write_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1110 | return 0; |
| 1111 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1112 | |
| 1113 | s->data_ctx.stats.px_st = DATA_ST_PX_FIN; |
| 1114 | /* fall through */ |
| 1115 | |
| 1116 | case DATA_ST_PX_FIN: |
| 1117 | return 1; |
| 1118 | |
| 1119 | default: |
| 1120 | /* unknown state, we should put an abort() here ! */ |
| 1121 | return 1; |
| 1122 | } |
| 1123 | } |
| 1124 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1125 | |
| 1126 | /* This function is called to send output to the response buffer. |
| 1127 | * It dumps the sessions states onto the output buffer <rep>. |
| 1128 | * Expects to be called with client socket shut down on input. |
| 1129 | * s->data_ctx must have been zeroed first, and the flags properly set. |
| 1130 | * It automatically clears the HIJACK bit from the response buffer. |
| 1131 | */ |
| 1132 | void stats_dump_sess_to_buffer(struct session *s, struct buffer *rep) |
| 1133 | { |
| 1134 | struct chunk msg; |
| 1135 | |
| 1136 | if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) { |
| 1137 | /* If we're forced to shut down, we might have to remove our |
| 1138 | * reference to the last session being dumped. |
| 1139 | */ |
| 1140 | if (s->data_state == DATA_ST_LIST) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1141 | if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1142 | LIST_DEL(&s->data_ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1143 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1144 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1145 | } |
| 1146 | s->data_state = DATA_ST_FIN; |
| 1147 | buffer_stop_hijack(rep); |
| 1148 | s->ana_state = STATS_ST_CLOSE; |
| 1149 | return; |
| 1150 | } |
| 1151 | |
| 1152 | if (s->ana_state != STATS_ST_REP) |
| 1153 | return; |
| 1154 | |
| 1155 | msg.len = 0; |
| 1156 | msg.str = trash; |
| 1157 | |
| 1158 | switch (s->data_state) { |
| 1159 | case DATA_ST_INIT: |
| 1160 | /* the function had not been called yet, let's prepare the |
| 1161 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1162 | * pointer to the first in the global list. When a target |
| 1163 | * session is being destroyed, it is responsible for updating |
| 1164 | * this pointer. We know we have reached the end when this |
| 1165 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1166 | */ |
| 1167 | stream_int_retnclose(rep->cons, &msg); |
| 1168 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1169 | s->data_ctx.sess.bref.ref = sessions.n; |
| 1170 | s->data_state = DATA_ST_LIST; |
| 1171 | /* fall through */ |
| 1172 | |
| 1173 | case DATA_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1174 | /* first, let's detach the back-ref from a possible previous session */ |
| 1175 | if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) { |
| 1176 | LIST_DEL(&s->data_ctx.sess.bref.users); |
| 1177 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 1178 | } |
| 1179 | |
| 1180 | /* and start from where we stopped */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1181 | while (s->data_ctx.sess.bref.ref != &sessions) { |
| 1182 | char pn[INET6_ADDRSTRLEN + strlen(":65535")]; |
| 1183 | struct session *curr_sess; |
| 1184 | |
| 1185 | curr_sess = LIST_ELEM(s->data_ctx.sess.bref.ref, struct session *, list); |
| 1186 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1187 | chunk_printf(&msg, sizeof(trash), |
| 1188 | "%p: proto=%s", |
| 1189 | curr_sess, |
| 1190 | curr_sess->listener->proto->name); |
| 1191 | |
| 1192 | switch (curr_sess->listener->proto->sock_family) { |
| 1193 | case AF_INET: |
| 1194 | inet_ntop(AF_INET, |
| 1195 | (const void *)&((struct sockaddr_in *)&curr_sess->cli_addr)->sin_addr, |
| 1196 | pn, sizeof(pn)); |
| 1197 | |
| 1198 | chunk_printf(&msg, sizeof(trash), |
| 1199 | " src=%s:%d fe=%s be=%s srv=%s", |
| 1200 | pn, |
| 1201 | ntohs(((struct sockaddr_in *)&curr_sess->cli_addr)->sin_port), |
| 1202 | curr_sess->fe->id, |
| 1203 | curr_sess->be->id, |
| 1204 | curr_sess->srv ? curr_sess->srv->id : "<none>" |
| 1205 | ); |
| 1206 | break; |
| 1207 | case AF_INET6: |
| 1208 | inet_ntop(AF_INET6, |
| 1209 | (const void *)&((struct sockaddr_in6 *)(&curr_sess->cli_addr))->sin6_addr, |
| 1210 | pn, sizeof(pn)); |
| 1211 | |
| 1212 | chunk_printf(&msg, sizeof(trash), |
| 1213 | " src=%s:%d fe=%s be=%s srv=%s", |
| 1214 | pn, |
| 1215 | ntohs(((struct sockaddr_in6 *)&curr_sess->cli_addr)->sin6_port), |
| 1216 | curr_sess->fe->id, |
| 1217 | curr_sess->be->id, |
| 1218 | curr_sess->srv ? curr_sess->srv->id : "<none>" |
| 1219 | ); |
| 1220 | |
| 1221 | break; |
| 1222 | case AF_UNIX: |
| 1223 | /* no more information to print right now */ |
| 1224 | break; |
| 1225 | } |
| 1226 | |
| 1227 | chunk_printf(&msg, sizeof(trash), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1228 | " as=%d ts=%02x age=%s calls=%d", |
Willy Tarreau | 8a5c626 | 2008-12-08 00:16:21 +0100 | [diff] [blame] | 1229 | curr_sess->ana_state, curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 1230 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 1231 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1232 | |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1233 | chunk_printf(&msg, sizeof(trash), |
| 1234 | " rq[f=%06xh,l=%d,an=%02xh,rx=%s", |
| 1235 | curr_sess->req->flags, |
| 1236 | curr_sess->req->l, |
| 1237 | curr_sess->req->analysers, |
| 1238 | curr_sess->req->rex ? |
| 1239 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 1240 | TICKS_TO_MS(1000)) : ""); |
| 1241 | |
| 1242 | chunk_printf(&msg, sizeof(trash), |
| 1243 | ",wx=%s", |
| 1244 | curr_sess->req->wex ? |
| 1245 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 1246 | TICKS_TO_MS(1000)) : ""); |
| 1247 | |
| 1248 | chunk_printf(&msg, sizeof(trash), |
| 1249 | ",ax=%s]", |
| 1250 | curr_sess->req->analyse_exp ? |
| 1251 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 1252 | TICKS_TO_MS(1000)) : ""); |
| 1253 | |
| 1254 | chunk_printf(&msg, sizeof(trash), |
| 1255 | " rp[f=%06xh,l=%d,an=%02xh,rx=%s", |
| 1256 | curr_sess->rep->flags, |
| 1257 | curr_sess->rep->l, |
| 1258 | curr_sess->rep->analysers, |
| 1259 | curr_sess->rep->rex ? |
| 1260 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 1261 | TICKS_TO_MS(1000)) : ""); |
| 1262 | |
| 1263 | chunk_printf(&msg, sizeof(trash), |
| 1264 | ",wx=%s", |
| 1265 | curr_sess->rep->wex ? |
| 1266 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 1267 | TICKS_TO_MS(1000)) : ""); |
| 1268 | |
| 1269 | chunk_printf(&msg, sizeof(trash), |
| 1270 | ",ax=%s]", |
| 1271 | curr_sess->rep->analyse_exp ? |
| 1272 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 1273 | TICKS_TO_MS(1000)) : ""); |
| 1274 | |
| 1275 | chunk_printf(&msg, sizeof(trash), |
| 1276 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 1277 | curr_sess->si[0].state, |
| 1278 | curr_sess->si[0].flags, |
| 1279 | curr_sess->si[0].fd, |
| 1280 | curr_sess->si[0].exp ? |
| 1281 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 1282 | TICKS_TO_MS(1000)) : ""); |
| 1283 | |
| 1284 | chunk_printf(&msg, sizeof(trash), |
| 1285 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 1286 | curr_sess->si[1].state, |
| 1287 | curr_sess->si[1].flags, |
| 1288 | curr_sess->si[1].fd, |
| 1289 | curr_sess->si[1].exp ? |
| 1290 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 1291 | TICKS_TO_MS(1000)) : ""); |
| 1292 | |
| 1293 | chunk_printf(&msg, sizeof(trash), |
| 1294 | " exp=%s", |
| 1295 | curr_sess->task->expire ? |
| 1296 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 1297 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 1298 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 1299 | chunk_printf(&msg, sizeof(trash), " run(nice=%d)", curr_sess->task->nice); |
| 1300 | |
| 1301 | chunk_printf(&msg, sizeof(trash), "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1302 | |
| 1303 | if (buffer_write_chunk(rep, &msg) >= 0) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 1304 | /* let's try again later from this session. We add ourselves into |
| 1305 | * this session's users so that it can remove us upon termination. |
| 1306 | */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1307 | LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users); |
| 1308 | return; |
| 1309 | } |
| 1310 | |
| 1311 | s->data_ctx.sess.bref.ref = curr_sess->list.n; |
| 1312 | } |
| 1313 | s->data_state = DATA_ST_FIN; |
| 1314 | /* fall through */ |
| 1315 | |
| 1316 | default: |
| 1317 | s->data_state = DATA_ST_FIN; |
| 1318 | buffer_stop_hijack(rep); |
| 1319 | s->ana_state = STATS_ST_CLOSE; |
| 1320 | return; |
| 1321 | } |
| 1322 | } |
| 1323 | |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1324 | /* print a line of error buffer (limited to 70 bytes) to <out>. The format is : |
| 1325 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 1326 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 1327 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 1328 | * lines are respected within the limit of 70 output chars. Lines that are |
| 1329 | * continuation of a previous truncated line begin with "+" instead of " " |
| 1330 | * after the offset. The new pointer is returned. |
| 1331 | */ |
| 1332 | static int dump_error_line(struct chunk *out, int size, |
| 1333 | struct error_snapshot *err, int *line, int ptr) |
| 1334 | { |
| 1335 | int end; |
| 1336 | unsigned char c; |
| 1337 | |
| 1338 | end = out->len + 80; |
| 1339 | if (end > size) |
| 1340 | return ptr; |
| 1341 | |
| 1342 | chunk_printf(out, size, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
| 1343 | |
| 1344 | while (ptr < err->len) { |
| 1345 | c = err->buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 1346 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1347 | if (out->len > end - 2) |
| 1348 | break; |
| 1349 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 1350 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1351 | if (out->len > end - 3) |
| 1352 | break; |
| 1353 | out->str[out->len++] = '\\'; |
| 1354 | switch (c) { |
| 1355 | case '\t': c = 't'; break; |
| 1356 | case '\n': c = 'n'; break; |
| 1357 | case '\r': c = 'r'; break; |
| 1358 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 1359 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 1360 | } |
| 1361 | out->str[out->len++] = c; |
| 1362 | } else { |
| 1363 | if (out->len > end - 5) |
| 1364 | break; |
| 1365 | out->str[out->len++] = '\\'; |
| 1366 | out->str[out->len++] = 'x'; |
| 1367 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 1368 | out->str[out->len++] = hextab[c & 0xF]; |
| 1369 | } |
| 1370 | if (err->buf[ptr++] == '\n') { |
| 1371 | /* we had a line break, let's return now */ |
| 1372 | out->str[out->len++] = '\n'; |
| 1373 | *line = ptr; |
| 1374 | return ptr; |
| 1375 | } |
| 1376 | } |
| 1377 | /* we have an incomplete line, we return it as-is */ |
| 1378 | out->str[out->len++] = '\n'; |
| 1379 | return ptr; |
| 1380 | } |
| 1381 | |
| 1382 | /* This function is called to send output to the response buffer. |
| 1383 | * It dumps the errors logged in proxies onto the output buffer <rep>. |
| 1384 | * Expects to be called with client socket shut down on input. |
| 1385 | * s->data_ctx must have been zeroed first, and the flags properly set. |
| 1386 | * It automatically clears the HIJACK bit from the response buffer. |
| 1387 | */ |
| 1388 | void stats_dump_errors_to_buffer(struct session *s, struct buffer *rep) |
| 1389 | { |
| 1390 | extern const char *monthname[12]; |
| 1391 | struct chunk msg; |
| 1392 | |
| 1393 | if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) { |
| 1394 | s->data_state = DATA_ST_FIN; |
| 1395 | buffer_stop_hijack(rep); |
| 1396 | s->ana_state = STATS_ST_CLOSE; |
| 1397 | return; |
| 1398 | } |
| 1399 | |
| 1400 | if (s->ana_state != STATS_ST_REP) |
| 1401 | return; |
| 1402 | |
| 1403 | msg.len = 0; |
| 1404 | msg.str = trash; |
| 1405 | |
| 1406 | if (!s->data_ctx.errors.px) { |
| 1407 | /* the function had not been called yet, let's prepare the |
| 1408 | * buffer for a response. |
| 1409 | */ |
| 1410 | stream_int_retnclose(rep->cons, &msg); |
| 1411 | s->data_ctx.errors.px = proxy; |
| 1412 | s->data_ctx.errors.buf = 0; |
| 1413 | s->data_ctx.errors.bol = 0; |
| 1414 | s->data_ctx.errors.ptr = -1; |
| 1415 | } |
| 1416 | |
| 1417 | /* we have two inner loops here, one for the proxy, the other one for |
| 1418 | * the buffer. |
| 1419 | */ |
| 1420 | while (s->data_ctx.errors.px) { |
| 1421 | struct error_snapshot *es; |
| 1422 | |
| 1423 | if (s->data_ctx.errors.buf == 0) |
| 1424 | es = &s->data_ctx.errors.px->invalid_req; |
| 1425 | else |
| 1426 | es = &s->data_ctx.errors.px->invalid_rep; |
| 1427 | |
| 1428 | if (!es->when.tv_sec) |
| 1429 | goto next; |
| 1430 | |
| 1431 | if (s->data_ctx.errors.iid >= 0 && |
| 1432 | s->data_ctx.errors.px->uuid != s->data_ctx.errors.iid && |
| 1433 | es->oe->uuid != s->data_ctx.errors.iid) |
| 1434 | goto next; |
| 1435 | |
| 1436 | if (s->data_ctx.errors.ptr < 0) { |
| 1437 | /* just print headers now */ |
| 1438 | |
| 1439 | char pn[INET6_ADDRSTRLEN]; |
| 1440 | struct tm tm; |
| 1441 | |
| 1442 | get_localtime(es->when.tv_sec, &tm); |
| 1443 | chunk_printf(&msg, sizeof(trash), "\n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
| 1444 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 1445 | 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] | 1446 | |
| 1447 | |
| 1448 | if (es->src.ss_family == AF_INET) |
| 1449 | inet_ntop(AF_INET, |
| 1450 | (const void *)&((struct sockaddr_in *)&es->src)->sin_addr, |
| 1451 | pn, sizeof(pn)); |
| 1452 | else |
| 1453 | inet_ntop(AF_INET6, |
| 1454 | (const void *)&((struct sockaddr_in6 *)(&es->src))->sin6_addr, |
| 1455 | pn, sizeof(pn)); |
| 1456 | |
| 1457 | switch (s->data_ctx.errors.buf) { |
| 1458 | case 0: |
| 1459 | chunk_printf(&msg, sizeof(trash), |
| 1460 | " frontend %s (#%d): invalid request\n" |
| 1461 | " src %s, session #%d, backend %s (#%d), server %s (#%d)\n" |
| 1462 | " request length %d bytes, error at position %d:\n\n", |
| 1463 | s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid, |
| 1464 | pn, es->sid, es->oe->id, es->oe->uuid, |
| 1465 | es->srv ? es->srv->id : "<NONE>", |
| 1466 | es->srv ? es->srv->puid : -1, |
| 1467 | es->len, es->pos); |
| 1468 | break; |
| 1469 | case 1: |
| 1470 | chunk_printf(&msg, sizeof(trash), |
| 1471 | " backend %s (#%d) : invalid response\n" |
| 1472 | " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n" |
| 1473 | " response length %d bytes, error at position %d:\n\n", |
| 1474 | s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid, |
| 1475 | pn, es->sid, es->oe->id, es->oe->uuid, |
| 1476 | es->srv ? es->srv->id : "<NONE>", |
| 1477 | es->srv ? es->srv->puid : -1, |
| 1478 | es->len, es->pos); |
| 1479 | break; |
| 1480 | } |
| 1481 | |
| 1482 | if (buffer_write_chunk(rep, &msg) >= 0) { |
| 1483 | /* Socket buffer full. Let's try again later from the same point */ |
| 1484 | return; |
| 1485 | } |
| 1486 | s->data_ctx.errors.ptr = 0; |
| 1487 | s->data_ctx.errors.sid = es->sid; |
| 1488 | } |
| 1489 | |
| 1490 | if (s->data_ctx.errors.sid != es->sid) { |
| 1491 | /* the snapshot changed while we were dumping it */ |
| 1492 | chunk_printf(&msg, sizeof(trash), |
| 1493 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
| 1494 | if (buffer_write_chunk(rep, &msg) >= 0) |
| 1495 | return; |
| 1496 | goto next; |
| 1497 | } |
| 1498 | |
| 1499 | /* OK, ptr >= 0, so we have to dump the current line */ |
| 1500 | while (s->data_ctx.errors.ptr < es->len) { |
| 1501 | int newptr; |
| 1502 | int newline; |
| 1503 | |
| 1504 | newline = s->data_ctx.errors.bol; |
| 1505 | newptr = dump_error_line(&msg, sizeof(trash), es, &newline, s->data_ctx.errors.ptr); |
| 1506 | if (newptr == s->data_ctx.errors.ptr) |
| 1507 | return; |
| 1508 | |
| 1509 | if (buffer_write_chunk(rep, &msg) >= 0) { |
| 1510 | /* Socket buffer full. Let's try again later from the same point */ |
| 1511 | return; |
| 1512 | } |
| 1513 | s->data_ctx.errors.ptr = newptr; |
| 1514 | s->data_ctx.errors.bol = newline; |
| 1515 | }; |
| 1516 | next: |
| 1517 | s->data_ctx.errors.bol = 0; |
| 1518 | s->data_ctx.errors.ptr = -1; |
| 1519 | s->data_ctx.errors.buf++; |
| 1520 | if (s->data_ctx.errors.buf > 1) { |
| 1521 | s->data_ctx.errors.buf = 0; |
| 1522 | s->data_ctx.errors.px = s->data_ctx.errors.px->next; |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | /* dump complete */ |
| 1527 | buffer_stop_hijack(rep); |
| 1528 | s->ana_state = STATS_ST_CLOSE; |
| 1529 | } |
| 1530 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 1531 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 1532 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 1533 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 1534 | { 0, NULL, NULL }, |
| 1535 | }}; |
| 1536 | |
| 1537 | __attribute__((constructor)) |
| 1538 | static void __dumpstats_module_init(void) |
| 1539 | { |
| 1540 | cfg_register_keywords(&cfg_kws); |
| 1541 | } |
| 1542 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1543 | /* |
| 1544 | * Local variables: |
| 1545 | * c-indent-level: 8 |
| 1546 | * c-basic-offset: 8 |
| 1547 | * End: |
| 1548 | */ |