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