Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 2 | * Functions dedicated to statistics output and the stats socket |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 4 | * Copyright 2000-2010 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 27 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 28 | #include <common/compat.h> |
| 29 | #include <common/config.h> |
| 30 | #include <common/debug.h> |
| 31 | #include <common/memory.h> |
| 32 | #include <common/mini-clist.h> |
| 33 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 34 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 35 | #include <common/time.h> |
| 36 | #include <common/uri_auth.h> |
| 37 | #include <common/version.h> |
| 38 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | #include <types/global.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 40 | |
| 41 | #include <proto/backend.h> |
| 42 | #include <proto/buffers.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 43 | #include <proto/checks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 44 | #include <proto/dumpstats.h> |
| 45 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 46 | #include <proto/freq_ctr.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 47 | #include <proto/log.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 48 | #include <proto/pipe.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 49 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 50 | #include <proto/proxy.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 51 | #include <proto/session.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 52 | #include <proto/server.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 53 | #include <proto/stream_interface.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 54 | #include <proto/stream_sock.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 55 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 56 | |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 57 | const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 58 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 59 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 60 | " help : this message\n" |
| 61 | " prompt : toggle interactive mode with prompt\n" |
| 62 | " quit : disconnect\n" |
| 63 | " show info : report information about the running process\n" |
| 64 | " show stat : report counters for each proxy and server\n" |
| 65 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 66 | " show sess [id] : report the list of current sessions or dump this session\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 67 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 68 | " set weight : change a server's weight\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 69 | " set timeout : change a timeout setting\n" |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 70 | " disable server : set a server in maintenance mode\n" |
| 71 | " enable server : re-enable a server that was previously in maintenance mode\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 72 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 73 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 74 | const char stats_permission_denied_msg[] = |
| 75 | "Permission denied\n" |
| 76 | ""; |
| 77 | |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 78 | /* This function is called from the protocol layer accept() in order to instanciate |
| 79 | * a new stats socket. It returns a positive value upon success, 0 if the connection |
| 80 | * needs to be closed and ignored, or a negative value upon critical failure. |
| 81 | */ |
| 82 | int stats_accept(struct listener *l, int cfd, struct sockaddr_storage *addr) |
| 83 | { |
| 84 | struct proxy *p = l->frontend; /* attached frontend */ |
| 85 | struct session *s; |
| 86 | struct task *t; |
| 87 | |
| 88 | if ((s = pool_alloc2(pool2_session)) == NULL) { |
| 89 | Alert("out of memory in stats_accept().\n"); |
| 90 | goto out_close; |
| 91 | } |
| 92 | |
| 93 | LIST_ADDQ(&sessions, &s->list); |
| 94 | LIST_INIT(&s->back_refs); |
| 95 | |
| 96 | s->flags = 0; |
| 97 | s->term_trace = 0; |
| 98 | s->cli_addr = *addr; |
| 99 | |
| 100 | if ((t = task_new()) == NULL) { |
| 101 | Alert("out of memory in stats_accept().\n"); |
| 102 | goto out_free_session; |
| 103 | } |
| 104 | |
| 105 | t->process = l->handler; |
| 106 | t->context = s; |
| 107 | t->nice = l->nice; |
| 108 | |
| 109 | s->task = t; |
| 110 | s->listener = l; |
| 111 | s->fe = s->be = p; |
| 112 | |
| 113 | s->req = s->rep = NULL; /* will be allocated later */ |
| 114 | |
| 115 | s->si[0].state = s->si[0].prev_state = SI_ST_EST; |
| 116 | s->si[0].err_type = SI_ET_NONE; |
| 117 | s->si[0].err_loc = NULL; |
| 118 | s->si[0].owner = t; |
| 119 | s->si[0].update = stream_sock_data_finish; |
| 120 | s->si[0].shutr = stream_sock_shutr; |
| 121 | s->si[0].shutw = stream_sock_shutw; |
| 122 | s->si[0].chk_rcv = stream_sock_chk_rcv; |
| 123 | s->si[0].chk_snd = stream_sock_chk_snd; |
| 124 | s->si[0].connect = NULL; |
| 125 | s->si[0].iohandler = NULL; |
| 126 | s->si[0].fd = cfd; |
| 127 | s->si[0].flags = SI_FL_NONE; |
| 128 | if (s->fe->options2 & PR_O2_INDEPSTR) |
| 129 | s->si[0].flags |= SI_FL_INDEP_STR; |
| 130 | s->si[0].exp = TICK_ETERNITY; |
| 131 | |
| 132 | s->si[1].state = s->si[1].prev_state = SI_ST_INI; |
| 133 | s->si[1].err_type = SI_ET_NONE; |
| 134 | s->si[1].err_loc = NULL; |
| 135 | s->si[1].owner = t; |
| 136 | s->si[1].exp = TICK_ETERNITY; |
| 137 | s->si[1].fd = -1; /* just to help with debugging */ |
| 138 | s->si[1].flags = SI_FL_NONE; |
| 139 | if (s->be->options2 & PR_O2_INDEPSTR) |
| 140 | s->si[1].flags |= SI_FL_INDEP_STR; |
| 141 | |
| 142 | stream_int_register_handler(&s->si[1], stats_io_handler); |
| 143 | s->si[1].private = s; |
| 144 | s->si[1].st1 = 0; |
| 145 | s->si[1].st0 = STAT_CLI_INIT; |
| 146 | |
| 147 | s->srv = s->prev_srv = s->srv_conn = NULL; |
| 148 | s->pend_pos = NULL; |
| 149 | |
| 150 | s->store_count = 0; |
| 151 | |
| 152 | memset(&s->logs, 0, sizeof(s->logs)); |
| 153 | memset(&s->txn, 0, sizeof(s->txn)); |
| 154 | |
| 155 | s->logs.accept_date = date; /* user-visible date for logging */ |
| 156 | s->logs.tv_accept = now; /* corrected date for internal use */ |
| 157 | |
| 158 | s->data_state = DATA_ST_INIT; |
| 159 | s->data_source = DATA_SRC_NONE; |
| 160 | s->uniq_id = totalconn; |
| 161 | proxy_inc_fe_ctr(l, p); /* note: cum_beconn will be increased once assigned */ |
| 162 | |
| 163 | if (fcntl(cfd, F_SETFL, O_NONBLOCK) == -1) { |
| 164 | Alert("accept(): cannot set the socket in non blocking mode. Giving up.\n"); |
| 165 | goto out_free_task; |
| 166 | } |
| 167 | |
| 168 | if ((s->req = pool_alloc2(pool2_buffer)) == NULL) |
| 169 | goto out_free_task; |
| 170 | |
| 171 | s->req->size = global.tune.bufsize; |
| 172 | buffer_init(s->req); |
| 173 | s->req->prod = &s->si[0]; |
| 174 | s->req->cons = &s->si[1]; |
| 175 | s->si[0].ib = s->si[1].ob = s->req; |
| 176 | s->req->flags |= BF_READ_ATTACHED; /* the producer is already connected */ |
| 177 | s->req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */ |
| 178 | |
| 179 | s->req->analysers = l->analysers; |
| 180 | |
| 181 | s->req->wto = TICK_ETERNITY; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 182 | s->req->rto = TICK_ETERNITY; |
| 183 | |
| 184 | if ((s->rep = pool_alloc2(pool2_buffer)) == NULL) |
| 185 | goto out_free_req; |
| 186 | |
| 187 | s->rep->size = global.tune.bufsize; |
| 188 | buffer_init(s->rep); |
| 189 | |
| 190 | s->rep->prod = &s->si[1]; |
| 191 | s->rep->cons = &s->si[0]; |
| 192 | s->si[0].ob = s->si[1].ib = s->rep; |
| 193 | |
| 194 | s->rep->rto = TICK_ETERNITY; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 195 | s->rep->wto = TICK_ETERNITY; |
| 196 | |
| 197 | s->req->rex = TICK_ETERNITY; |
| 198 | s->req->wex = TICK_ETERNITY; |
| 199 | s->req->analyse_exp = TICK_ETERNITY; |
| 200 | s->rep->rex = TICK_ETERNITY; |
| 201 | s->rep->wex = TICK_ETERNITY; |
| 202 | s->rep->analyse_exp = TICK_ETERNITY; |
| 203 | |
| 204 | t->expire = TICK_ETERNITY; |
| 205 | |
| 206 | if (l->timeout) { |
| 207 | s->req->rto = *l->timeout; |
| 208 | s->rep->wto = *l->timeout; |
| 209 | } |
| 210 | |
| 211 | fd_insert(cfd); |
| 212 | fdtab[cfd].owner = &s->si[0]; |
| 213 | fdtab[cfd].state = FD_STREADY; |
| 214 | fdtab[cfd].cb[DIR_RD].f = l->proto->read; |
| 215 | fdtab[cfd].cb[DIR_RD].b = s->req; |
| 216 | fdtab[cfd].cb[DIR_WR].f = l->proto->write; |
| 217 | fdtab[cfd].cb[DIR_WR].b = s->rep; |
| 218 | fdinfo[cfd].peeraddr = (struct sockaddr *)&s->cli_addr; |
| 219 | fdinfo[cfd].peerlen = sizeof(s->cli_addr); |
| 220 | |
| 221 | EV_FD_SET(cfd, DIR_RD); |
| 222 | |
| 223 | task_wakeup(t, TASK_WOKEN_INIT); |
| 224 | return 1; |
| 225 | |
| 226 | out_free_req: |
| 227 | pool_free2(pool2_buffer, s->req); |
| 228 | out_free_task: |
| 229 | task_free(t); |
| 230 | out_free_session: |
| 231 | LIST_DEL(&s->list); |
| 232 | pool_free2(pool2_session, s); |
| 233 | out_close: |
| 234 | return -1; |
| 235 | } |
| 236 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 237 | /* This function parses a "stats" statement in the "global" section. It returns |
| 238 | * -1 if there is any error, otherwise zero. If it returns -1, it may write an |
| 239 | * error message into ther <err> buffer, for at most <errlen> bytes, trailing |
| 240 | * zero included. The trailing '\n' must not be written. The function must be |
| 241 | * called with <args> pointing to the first word after "stats". |
| 242 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 243 | static int stats_parse_global(char **args, int section_type, struct proxy *curpx, |
| 244 | struct proxy *defpx, char *err, int errlen) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 245 | { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 246 | args++; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 247 | if (!strcmp(args[0], "socket")) { |
| 248 | struct sockaddr_un su; |
| 249 | int cur_arg; |
| 250 | |
| 251 | if (*args[1] == 0) { |
| 252 | snprintf(err, errlen, "'stats socket' in global section expects a path to a UNIX socket"); |
| 253 | return -1; |
| 254 | } |
| 255 | |
| 256 | if (global.stats_sock.state != LI_NEW) { |
| 257 | snprintf(err, errlen, "'stats socket' already specified in global section"); |
| 258 | return -1; |
| 259 | } |
| 260 | |
| 261 | su.sun_family = AF_UNIX; |
| 262 | strncpy(su.sun_path, args[1], sizeof(su.sun_path)); |
| 263 | su.sun_path[sizeof(su.sun_path) - 1] = 0; |
| 264 | memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit |
| 265 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 266 | if (!global.stats_fe) { |
| 267 | if ((global.stats_fe = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { |
| 268 | snprintf(err, errlen, "out of memory"); |
| 269 | return -1; |
| 270 | } |
| 271 | |
| 272 | LIST_INIT(&global.stats_fe->pendconns); |
| 273 | LIST_INIT(&global.stats_fe->acl); |
| 274 | LIST_INIT(&global.stats_fe->block_cond); |
| 275 | LIST_INIT(&global.stats_fe->redirect_rules); |
| 276 | LIST_INIT(&global.stats_fe->mon_fail_cond); |
| 277 | LIST_INIT(&global.stats_fe->switching_rules); |
| 278 | LIST_INIT(&global.stats_fe->tcp_req.inspect_rules); |
| 279 | |
| 280 | /* Timeouts are defined as -1, so we cannot use the zeroed area |
| 281 | * as a default value. |
| 282 | */ |
| 283 | proxy_reset_timeouts(global.stats_fe); |
| 284 | |
| 285 | global.stats_fe->last_change = now.tv_sec; |
| 286 | global.stats_fe->id = strdup("GLOBAL"); |
| 287 | global.stats_fe->cap = PR_CAP_FE; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 288 | global.stats_fe->maxconn = global.stats_sock.maxconn; |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 291 | global.stats_sock.state = LI_INIT; |
Willy Tarreau | 6fb42e0 | 2007-10-28 17:02:33 +0100 | [diff] [blame] | 292 | global.stats_sock.options = LI_O_NONE; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 293 | global.stats_sock.accept = stats_accept; |
Willy Tarreau | 104eb36 | 2009-08-16 18:51:29 +0200 | [diff] [blame] | 294 | global.stats_sock.handler = process_session; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 295 | global.stats_sock.analysers = 0; |
Willy Tarreau | 2c9f5b1 | 2009-08-16 19:12:36 +0200 | [diff] [blame] | 296 | global.stats_sock.nice = -64; /* we want to boost priority for local stats */ |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 297 | global.stats_sock.frontend = global.stats_fe; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 298 | global.stats_sock.perm.ux.level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 299 | |
| 300 | global.stats_fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
| 301 | global.stats_sock.timeout = &global.stats_fe->timeout.client; |
| 302 | |
| 303 | global.stats_sock.next = global.stats_fe->listen; |
| 304 | global.stats_fe->listen = &global.stats_sock; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 305 | |
| 306 | cur_arg = 2; |
| 307 | while (*args[cur_arg]) { |
| 308 | if (!strcmp(args[cur_arg], "uid")) { |
| 309 | global.stats_sock.perm.ux.uid = atol(args[cur_arg + 1]); |
| 310 | cur_arg += 2; |
| 311 | } |
| 312 | else if (!strcmp(args[cur_arg], "gid")) { |
| 313 | global.stats_sock.perm.ux.gid = atol(args[cur_arg + 1]); |
| 314 | cur_arg += 2; |
| 315 | } |
| 316 | else if (!strcmp(args[cur_arg], "mode")) { |
| 317 | global.stats_sock.perm.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 318 | cur_arg += 2; |
| 319 | } |
| 320 | else if (!strcmp(args[cur_arg], "user")) { |
| 321 | struct passwd *user; |
| 322 | user = getpwnam(args[cur_arg + 1]); |
| 323 | if (!user) { |
| 324 | snprintf(err, errlen, "unknown user '%s' in 'global' section ('stats user')", |
| 325 | args[cur_arg + 1]); |
| 326 | return -1; |
| 327 | } |
| 328 | global.stats_sock.perm.ux.uid = user->pw_uid; |
| 329 | cur_arg += 2; |
| 330 | } |
| 331 | else if (!strcmp(args[cur_arg], "group")) { |
| 332 | struct group *group; |
| 333 | group = getgrnam(args[cur_arg + 1]); |
| 334 | if (!group) { |
| 335 | snprintf(err, errlen, "unknown group '%s' in 'global' section ('stats group')", |
| 336 | args[cur_arg + 1]); |
| 337 | return -1; |
| 338 | } |
| 339 | global.stats_sock.perm.ux.gid = group->gr_gid; |
| 340 | cur_arg += 2; |
| 341 | } |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 342 | else if (!strcmp(args[cur_arg], "level")) { |
| 343 | if (!strcmp(args[cur_arg+1], "user")) |
| 344 | global.stats_sock.perm.ux.level = ACCESS_LVL_USER; |
| 345 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 346 | global.stats_sock.perm.ux.level = ACCESS_LVL_OPER; |
| 347 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 348 | global.stats_sock.perm.ux.level = ACCESS_LVL_ADMIN; |
| 349 | else { |
| 350 | snprintf(err, errlen, "'stats socket level' only supports 'user', 'operator', and 'admin'"); |
| 351 | return -1; |
| 352 | } |
| 353 | cur_arg += 2; |
| 354 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 355 | else { |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 356 | snprintf(err, errlen, "'stats socket' only supports 'user', 'uid', 'group', 'gid', 'level', and 'mode'"); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 357 | return -1; |
| 358 | } |
| 359 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 360 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 361 | uxst_add_listener(&global.stats_sock); |
| 362 | global.maxsock++; |
| 363 | } |
| 364 | else if (!strcmp(args[0], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 365 | unsigned timeout; |
| 366 | const char *res = parse_time_err(args[1], &timeout, TIME_UNIT_MS); |
| 367 | |
| 368 | if (res) { |
| 369 | snprintf(err, errlen, "unexpected character '%c' in 'stats timeout' in 'global' section", *res); |
| 370 | return -1; |
| 371 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 372 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 373 | if (!timeout) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 374 | snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'"); |
| 375 | return -1; |
| 376 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 377 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 378 | } |
| 379 | else if (!strcmp(args[0], "maxconn")) { |
| 380 | int maxconn = atol(args[1]); |
| 381 | |
| 382 | if (maxconn <= 0) { |
| 383 | snprintf(err, errlen, "a positive value is expected for 'stats maxconn' in 'global section'"); |
| 384 | return -1; |
| 385 | } |
| 386 | global.maxsock -= global.stats_sock.maxconn; |
| 387 | global.stats_sock.maxconn = maxconn; |
| 388 | global.maxsock += global.stats_sock.maxconn; |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 389 | if (global.stats_fe) |
| 390 | global.stats_fe->maxconn = global.stats_sock.maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 391 | } |
| 392 | else { |
| 393 | snprintf(err, errlen, "'stats' only supports 'socket', 'maxconn' and 'timeout' in 'global' section"); |
| 394 | return -1; |
| 395 | } |
| 396 | return 0; |
| 397 | } |
| 398 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 399 | int print_csv_header(struct chunk *msg) |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 400 | { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 401 | return chunk_printf(msg, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 402 | "# pxname,svname," |
| 403 | "qcur,qmax," |
| 404 | "scur,smax,slim,stot," |
| 405 | "bin,bout," |
| 406 | "dreq,dresp," |
| 407 | "ereq,econ,eresp," |
| 408 | "wretr,wredis," |
| 409 | "status,weight,act,bck," |
| 410 | "chkfail,chkdown,lastchg,downtime,qlimit," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 411 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 412 | "rate,rate_lim,rate_max," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 413 | "check_status,check_code,check_duration," |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 414 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 415 | "req_rate,req_rate_max,req_tot," |
| 416 | "cli_abrt,srv_abrt," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 417 | "\n"); |
| 418 | } |
| 419 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 420 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 421 | * called from an applet running in a stream interface. The function returns 1 |
| 422 | * if the request was understood, otherwise zero. It sets si->st0 to a value |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 423 | * designating the function which will have to process the request, which can |
| 424 | * also be the print function to display the return message set into cli.msg. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 425 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 426 | int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 427 | { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 428 | struct session *s = si->private; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 429 | char *args[MAX_STATS_ARGS + 1]; |
| 430 | int arg; |
| 431 | |
| 432 | while (isspace((unsigned char)*line)) |
| 433 | line++; |
| 434 | |
| 435 | arg = 0; |
| 436 | args[arg] = line; |
| 437 | |
| 438 | while (*line && arg < MAX_STATS_ARGS) { |
| 439 | if (isspace((unsigned char)*line)) { |
| 440 | *line++ = '\0'; |
| 441 | |
| 442 | while (isspace((unsigned char)*line)) |
| 443 | line++; |
| 444 | |
| 445 | args[++arg] = line; |
| 446 | continue; |
| 447 | } |
| 448 | |
| 449 | line++; |
| 450 | } |
| 451 | |
| 452 | while (++arg <= MAX_STATS_ARGS) |
| 453 | args[arg] = line; |
| 454 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 455 | s->data_ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 456 | if (strcmp(args[0], "show") == 0) { |
| 457 | if (strcmp(args[1], "stat") == 0) { |
| 458 | if (*args[2] && *args[3] && *args[4]) { |
| 459 | s->data_ctx.stats.flags |= STAT_BOUND; |
| 460 | s->data_ctx.stats.iid = atoi(args[2]); |
| 461 | s->data_ctx.stats.type = atoi(args[3]); |
| 462 | s->data_ctx.stats.sid = atoi(args[4]); |
| 463 | } |
| 464 | |
| 465 | s->data_ctx.stats.flags |= STAT_SHOW_STAT; |
| 466 | s->data_ctx.stats.flags |= STAT_FMT_CSV; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 467 | s->data_state = DATA_ST_INIT; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 468 | si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 469 | } |
| 470 | else if (strcmp(args[1], "info") == 0) { |
| 471 | s->data_ctx.stats.flags |= STAT_SHOW_INFO; |
| 472 | s->data_ctx.stats.flags |= STAT_FMT_CSV; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 473 | s->data_state = DATA_ST_INIT; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 474 | si->st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 475 | } |
| 476 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 477 | s->data_state = DATA_ST_INIT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 478 | if (s->listener->perm.ux.level < ACCESS_LVL_OPER) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 479 | s->data_ctx.cli.msg = stats_permission_denied_msg; |
| 480 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 481 | return 1; |
| 482 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 483 | if (*args[2]) |
| 484 | s->data_ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
| 485 | else |
| 486 | s->data_ctx.sess.target = NULL; |
| 487 | s->data_ctx.sess.section = 0; /* start with session status */ |
| 488 | s->data_ctx.sess.pos = 0; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 489 | si->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 490 | } |
| 491 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 492 | if (s->listener->perm.ux.level < ACCESS_LVL_OPER) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 493 | s->data_ctx.cli.msg = stats_permission_denied_msg; |
| 494 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 495 | return 1; |
| 496 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 497 | if (*args[2]) |
| 498 | s->data_ctx.errors.iid = atoi(args[2]); |
| 499 | else |
| 500 | s->data_ctx.errors.iid = -1; |
| 501 | s->data_ctx.errors.px = NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 502 | s->data_state = DATA_ST_INIT; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 503 | si->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 504 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 505 | else { /* neither "stat" nor "info" nor "sess" nor "errors"*/ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 506 | return 0; |
| 507 | } |
| 508 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 509 | else if (strcmp(args[0], "clear") == 0) { |
| 510 | if (strcmp(args[1], "counters") == 0) { |
| 511 | struct proxy *px; |
| 512 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 513 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 514 | int clrall = 0; |
| 515 | |
| 516 | if (strcmp(args[2], "all") == 0) |
| 517 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 518 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 519 | /* check permissions */ |
| 520 | if (s->listener->perm.ux.level < ACCESS_LVL_OPER || |
| 521 | (clrall && s->listener->perm.ux.level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 522 | s->data_ctx.cli.msg = stats_permission_denied_msg; |
| 523 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 524 | return 1; |
| 525 | } |
| 526 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 527 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 528 | if (clrall) |
| 529 | memset(&px->counters, 0, sizeof(px->counters)); |
| 530 | else { |
| 531 | px->counters.feconn_max = 0; |
| 532 | px->counters.beconn_max = 0; |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 533 | px->counters.fe_rps_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 534 | px->counters.fe_sps_max = 0; |
| 535 | px->counters.be_sps_max = 0; |
| 536 | px->counters.nbpend_max = 0; |
| 537 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 538 | |
| 539 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 540 | if (clrall) |
| 541 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 542 | else { |
| 543 | sv->counters.cur_sess_max = 0; |
| 544 | sv->counters.nbpend_max = 0; |
| 545 | sv->counters.sps_max = 0; |
| 546 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 547 | |
| 548 | for (li = px->listen; li; li = li->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 549 | if (li->counters) { |
| 550 | if (clrall) |
| 551 | memset(li->counters, 0, sizeof(*li->counters)); |
| 552 | else |
| 553 | li->counters->conn_max = 0; |
| 554 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | return 1; |
| 558 | } |
| 559 | else { |
| 560 | return 0; |
| 561 | } |
| 562 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 563 | else if (strcmp(args[0], "get") == 0) { |
| 564 | if (strcmp(args[1], "weight") == 0) { |
| 565 | struct proxy *px; |
| 566 | struct server *sv; |
| 567 | |
| 568 | /* split "backend/server" and make <line> point to server */ |
| 569 | for (line = args[2]; *line; line++) |
| 570 | if (*line == '/') { |
| 571 | *line++ = '\0'; |
| 572 | break; |
| 573 | } |
| 574 | |
| 575 | if (!*line) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 576 | s->data_ctx.cli.msg = "Require 'backend/server'.\n"; |
| 577 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 578 | return 1; |
| 579 | } |
| 580 | |
| 581 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 582 | s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 583 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 584 | return 1; |
| 585 | } |
| 586 | |
| 587 | /* return server's effective weight at the moment */ |
| 588 | snprintf(trash, sizeof(trash), "%d (initial %d)\n", sv->uweight, sv->iweight); |
| 589 | buffer_feed(si->ib, trash); |
| 590 | return 1; |
| 591 | } |
| 592 | else { /* not "get weight" */ |
| 593 | return 0; |
| 594 | } |
| 595 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 596 | else if (strcmp(args[0], "set") == 0) { |
| 597 | if (strcmp(args[1], "weight") == 0) { |
| 598 | struct proxy *px; |
| 599 | struct server *sv; |
| 600 | int w; |
| 601 | |
| 602 | if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 603 | s->data_ctx.cli.msg = stats_permission_denied_msg; |
| 604 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 605 | return 1; |
| 606 | } |
| 607 | |
| 608 | /* split "backend/server" and make <line> point to server */ |
| 609 | for (line = args[2]; *line; line++) |
| 610 | if (*line == '/') { |
| 611 | *line++ = '\0'; |
| 612 | break; |
| 613 | } |
| 614 | |
| 615 | if (!*line || !*args[3]) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 616 | s->data_ctx.cli.msg = "Require 'backend/server' and 'weight' or 'weight%'.\n"; |
| 617 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 618 | return 1; |
| 619 | } |
| 620 | |
| 621 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 622 | s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 623 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 624 | return 1; |
| 625 | } |
| 626 | |
| 627 | /* if the weight is terminated with '%', it is set relative to |
| 628 | * the initial weight, otherwise it is absolute. |
| 629 | */ |
| 630 | w = atoi(args[3]); |
| 631 | if (strchr(args[3], '%') != NULL) { |
| 632 | if (w < 0 || w > 100) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 633 | s->data_ctx.cli.msg = "Relative weight can only be set between 0 and 100% inclusive.\n"; |
| 634 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 635 | return 1; |
| 636 | } |
| 637 | w = sv->iweight * w / 100; |
| 638 | } |
| 639 | else { |
| 640 | if (w < 0 || w > 256) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 641 | s->data_ctx.cli.msg = "Absolute weight can only be between 0 and 256 inclusive.\n"; |
| 642 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 643 | return 1; |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | if (w && w != sv->iweight && !(px->lbprm.algo & BE_LB_PROP_DYN)) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 648 | s->data_ctx.cli.msg = "Backend is using a static LB algorithm and only accepts weights '0%' and '100%'.\n"; |
| 649 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 650 | return 1; |
| 651 | } |
| 652 | |
| 653 | sv->uweight = w; |
| 654 | |
| 655 | if (px->lbprm.algo & BE_LB_PROP_DYN) { |
| 656 | /* we must take care of not pushing the server to full throttle during slow starts */ |
| 657 | if ((sv->state & SRV_WARMINGUP) && (px->lbprm.algo & BE_LB_PROP_DYN)) |
| 658 | sv->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - sv->last_change) + sv->slowstart - 1) / sv->slowstart; |
| 659 | else |
| 660 | sv->eweight = BE_WEIGHT_SCALE; |
| 661 | sv->eweight *= sv->uweight; |
| 662 | } else { |
| 663 | sv->eweight = sv->uweight; |
| 664 | } |
| 665 | |
| 666 | /* static LB algorithms are a bit harder to update */ |
| 667 | if (px->lbprm.update_server_eweight) |
| 668 | px->lbprm.update_server_eweight(sv); |
| 669 | else if (sv->eweight) |
| 670 | px->lbprm.set_server_status_up(sv); |
| 671 | else |
| 672 | px->lbprm.set_server_status_down(sv); |
| 673 | |
| 674 | return 1; |
| 675 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 676 | else if (strcmp(args[1], "timeout") == 0) { |
| 677 | if (strcmp(args[2], "cli") == 0) { |
| 678 | unsigned timeout; |
| 679 | const char *res; |
| 680 | |
| 681 | if (!*args[3]) { |
| 682 | s->data_ctx.cli.msg = "Expects an integer value.\n"; |
| 683 | si->st0 = STAT_CLI_PRINT; |
| 684 | return 1; |
| 685 | } |
| 686 | |
| 687 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 688 | if (res || timeout < 1) { |
| 689 | s->data_ctx.cli.msg = "Invalid timeout value.\n"; |
| 690 | si->st0 = STAT_CLI_PRINT; |
| 691 | return 1; |
| 692 | } |
| 693 | |
| 694 | s->req->rto = s->rep->wto = 1 + MS_TO_TICKS(timeout*1000); |
| 695 | return 1; |
| 696 | } |
| 697 | else { |
| 698 | s->data_ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 699 | si->st0 = STAT_CLI_PRINT; |
| 700 | return 1; |
| 701 | } |
| 702 | } |
| 703 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 704 | return 0; |
| 705 | } |
| 706 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 707 | else if (strcmp(args[0], "enable") == 0) { |
| 708 | if (strcmp(args[1], "server") == 0) { |
| 709 | struct proxy *px; |
| 710 | struct server *sv; |
| 711 | |
| 712 | if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) { |
| 713 | s->data_ctx.cli.msg = stats_permission_denied_msg; |
| 714 | si->st0 = STAT_CLI_PRINT; |
| 715 | return 1; |
| 716 | } |
| 717 | |
| 718 | /* split "backend/server" and make <line> point to server */ |
| 719 | for (line = args[2]; *line; line++) |
| 720 | if (*line == '/') { |
| 721 | *line++ = '\0'; |
| 722 | break; |
| 723 | } |
| 724 | |
| 725 | if (!*line || !*args[2]) { |
| 726 | s->data_ctx.cli.msg = "Require 'backend/server'.\n"; |
| 727 | si->st0 = STAT_CLI_PRINT; |
| 728 | return 1; |
| 729 | } |
| 730 | |
| 731 | if (!get_backend_server(args[2], line, &px, &sv)) { |
| 732 | s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 733 | si->st0 = STAT_CLI_PRINT; |
| 734 | return 1; |
| 735 | } |
| 736 | |
| 737 | if (sv->state & SRV_MAINTAIN) { |
| 738 | /* The server is really in maintenance, we can change the server state */ |
| 739 | if (sv->tracked) { |
| 740 | /* If this server tracks the status of another one, |
| 741 | * we must restore the good status. |
| 742 | */ |
| 743 | if (sv->tracked->state & SRV_RUNNING) { |
| 744 | set_server_up(sv); |
| 745 | } else { |
| 746 | sv->state &= ~SRV_MAINTAIN; |
| 747 | set_server_down(sv); |
| 748 | } |
| 749 | } else { |
| 750 | set_server_up(sv); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | return 1; |
| 755 | } |
| 756 | else { /* unknown "enable" parameter */ |
| 757 | return 0; |
| 758 | } |
| 759 | } |
| 760 | else if (strcmp(args[0], "disable") == 0) { |
| 761 | if (strcmp(args[1], "server") == 0) { |
| 762 | struct proxy *px; |
| 763 | struct server *sv; |
| 764 | |
| 765 | if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) { |
| 766 | s->data_ctx.cli.msg = stats_permission_denied_msg; |
| 767 | si->st0 = STAT_CLI_PRINT; |
| 768 | return 1; |
| 769 | } |
| 770 | |
| 771 | /* split "backend/server" and make <line> point to server */ |
| 772 | for (line = args[2]; *line; line++) |
| 773 | if (*line == '/') { |
| 774 | *line++ = '\0'; |
| 775 | break; |
| 776 | } |
| 777 | |
| 778 | if (!*line || !*args[2]) { |
| 779 | s->data_ctx.cli.msg = "Require 'backend/server'.\n"; |
| 780 | si->st0 = STAT_CLI_PRINT; |
| 781 | return 1; |
| 782 | } |
| 783 | |
| 784 | if (!get_backend_server(args[2], line, &px, &sv)) { |
| 785 | s->data_ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 786 | si->st0 = STAT_CLI_PRINT; |
| 787 | return 1; |
| 788 | } |
| 789 | |
| 790 | if (! (sv->state & SRV_MAINTAIN)) { |
| 791 | /* Not already in maintenance, we can change the server state */ |
| 792 | sv->state |= SRV_MAINTAIN; |
| 793 | set_server_down(sv); |
| 794 | } |
| 795 | |
| 796 | return 1; |
| 797 | } |
| 798 | else { /* unknown "disable" parameter */ |
| 799 | return 0; |
| 800 | } |
| 801 | } |
| 802 | else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 803 | return 0; |
| 804 | } |
| 805 | return 1; |
| 806 | } |
| 807 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 808 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 809 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 810 | * state machine handling requests and various responses. We read a request, |
| 811 | * then we process it and send the response, and we possibly display a prompt. |
| 812 | * Then we can read again. The state is stored in si->st0 and is one of the |
| 813 | * STAT_CLI_* constants. si->st1 is used to indicate whether prompt is enabled |
| 814 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 815 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 816 | void stats_io_handler(struct stream_interface *si) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 817 | { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 818 | struct session *s = si->private; |
| 819 | struct buffer *req = si->ob; |
| 820 | struct buffer *res = si->ib; |
| 821 | int reql; |
| 822 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 823 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 824 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 825 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 826 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 827 | while (1) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 828 | if (si->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 829 | /* Stats output not initialized yet */ |
| 830 | memset(&s->data_ctx.stats, 0, sizeof(s->data_ctx.stats)); |
| 831 | s->data_source = DATA_SRC_STATS; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 832 | si->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 833 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 834 | else if (si->st0 == STAT_CLI_END) { |
| 835 | /* Let's close for real now. We just close the request |
| 836 | * side, the conditions below will complete if needed. |
| 837 | */ |
| 838 | si->shutw(si); |
| 839 | break; |
| 840 | } |
| 841 | else if (si->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 842 | /* ensure we have some output room left in the event we |
| 843 | * would want to return some info right after parsing. |
| 844 | */ |
| 845 | if (buffer_almost_full(si->ib)) |
| 846 | break; |
| 847 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 848 | reql = buffer_si_peekline(si->ob, trash, sizeof(trash)); |
| 849 | if (reql <= 0) { /* closed or EOL not found */ |
| 850 | if (reql == 0) |
| 851 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 852 | si->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 853 | continue; |
| 854 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 855 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 856 | /* seek for a possible semi-colon. If we find one, we |
| 857 | * replace it with an LF and skip only this part. |
| 858 | */ |
| 859 | for (len = 0; len < reql; len++) |
| 860 | if (trash[len] == ';') { |
| 861 | trash[len] = '\n'; |
| 862 | reql = len + 1; |
| 863 | break; |
| 864 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 865 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 866 | /* now it is time to check that we have a full line, |
| 867 | * remove the trailing \n and possibly \r, then cut the |
| 868 | * line. |
| 869 | */ |
| 870 | len = reql - 1; |
| 871 | if (trash[len] != '\n') { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 872 | si->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 873 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 874 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 875 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 876 | if (len && trash[len-1] == '\r') |
| 877 | len--; |
| 878 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 879 | trash[len] = '\0'; |
| 880 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 881 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 882 | if (len) { |
| 883 | if (strcmp(trash, "quit") == 0) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 884 | si->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 885 | continue; |
| 886 | } |
| 887 | else if (strcmp(trash, "prompt") == 0) |
| 888 | si->st1 = !si->st1; |
| 889 | else if (strcmp(trash, "help") == 0 || |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 890 | !stats_sock_parse_request(si, trash)) { |
| 891 | s->data_ctx.cli.msg = stats_sock_usage_msg; |
| 892 | si->st0 = STAT_CLI_PRINT; |
| 893 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 894 | /* NB: stats_sock_parse_request() may have put |
| 895 | * another STAT_CLI_O_* into si->st0. |
| 896 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 897 | } |
| 898 | else if (!si->st1) { |
| 899 | /* if prompt is disabled, print help on empty lines, |
| 900 | * so that the user at least knows how to enable |
| 901 | * prompt and find help. |
| 902 | */ |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 903 | s->data_ctx.cli.msg = stats_sock_usage_msg; |
| 904 | si->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | /* re-adjust req buffer */ |
| 908 | buffer_skip(si->ob, reql); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 909 | req->flags |= BF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 910 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 911 | else { /* output functions: first check if the output buffer is closed then abort */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 912 | if (res->flags & (BF_SHUTR_NOW|BF_SHUTR)) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 913 | si->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 914 | continue; |
| 915 | } |
| 916 | |
| 917 | switch (si->st0) { |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 918 | case STAT_CLI_PRINT: |
| 919 | if (buffer_feed(si->ib, s->data_ctx.cli.msg) < 0) |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 920 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 921 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 922 | case STAT_CLI_O_INFO: |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 923 | if (stats_dump_raw_to_buffer(s, res)) |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 924 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 925 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 926 | case STAT_CLI_O_SESS: |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 927 | if (stats_dump_sess_to_buffer(s, res)) |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 928 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 929 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 930 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 931 | if (stats_dump_errors_to_buffer(s, res)) |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 932 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 933 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 934 | default: /* abnormal state */ |
| 935 | si->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 936 | break; |
| 937 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 938 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 939 | /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */ |
| 940 | if (si->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 9bcc91e | 2009-10-10 18:01:44 +0200 | [diff] [blame] | 941 | if (buffer_feed(si->ib, si->st1 ? "\n> " : "\n") < 0) |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 942 | si->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 943 | } |
| 944 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 945 | /* If the output functions are still there, it means they require more room. */ |
Willy Tarreau | 96fd4b5 | 2009-10-04 17:18:35 +0200 | [diff] [blame] | 946 | if (si->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 947 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 948 | |
| 949 | /* Now we close the output if one of the writers did so, |
| 950 | * or if we're not in interactive mode and the request |
| 951 | * buffer is empty. This still allows pipelined requests |
| 952 | * to be sent in non-interactive mode. |
| 953 | */ |
| 954 | if ((res->flags & (BF_SHUTW|BF_SHUTW_NOW)) || (!si->st1 && !req->send_max)) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 955 | si->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 956 | continue; |
| 957 | } |
| 958 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 959 | /* switch state back to GETREQ to read next requests */ |
| 960 | si->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 961 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 962 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 963 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 964 | if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST) && (si->st0 != STAT_CLI_GETREQ)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 965 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 966 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 967 | /* Other size has closed, let's abort if we have no more processing to do |
| 968 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 969 | * we forward the close to the request side so that it flows upstream to |
| 970 | * the client. |
| 971 | */ |
| 972 | si->shutw(si); |
| 973 | } |
| 974 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 975 | if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && (si->st0 < STAT_CLI_OUTPUT)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 976 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 977 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 978 | /* We have no more processing to do, and nothing more to send, and |
| 979 | * the client side has closed. So we'll forward this state downstream |
| 980 | * on the response buffer. |
| 981 | */ |
| 982 | si->shutr(si); |
| 983 | res->flags |= BF_READ_NULL; |
| 984 | } |
| 985 | |
| 986 | /* update all other flags and resync with the other side */ |
| 987 | si->update(si); |
| 988 | |
| 989 | /* we don't want to expire timeouts while we're processing requests */ |
| 990 | si->ib->rex = TICK_ETERNITY; |
| 991 | si->ob->wex = TICK_ETERNITY; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 992 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 993 | out: |
| 994 | DPRINTF(stderr, "%s@%d: st=%d, rqf=%x, rpf=%x, rql=%d, rqs=%d, rl=%d, rs=%d\n", |
| 995 | __FUNCTION__, __LINE__, |
| 996 | si->state, req->flags, res->flags, req->l, req->send_max, res->l, res->send_max); |
| 997 | |
| 998 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 999 | /* check that we have released everything then unregister */ |
| 1000 | stream_int_unregister_handler(si); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1001 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1002 | } |
| 1003 | |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1004 | /* This function is called to send output to the response buffer. |
| 1005 | * It dumps statistics onto the output buffer <rep> owned by session <s>. |
| 1006 | * s->data_ctx must have been zeroed first, and the flags properly set. |
| 1007 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 1008 | * Some states are not used but it makes the code more similar to other |
| 1009 | * functions which handle stats too. |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1010 | */ |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1011 | int stats_dump_raw_to_buffer(struct session *s, struct buffer *rep) |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1012 | { |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1013 | struct proxy *px; |
| 1014 | struct chunk msg; |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1015 | unsigned int up; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1016 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1017 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1018 | |
| 1019 | switch (s->data_state) { |
| 1020 | case DATA_ST_INIT: |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1021 | /* the function had not been called yet */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1022 | s->data_state = DATA_ST_HEAD; |
| 1023 | /* fall through */ |
| 1024 | |
| 1025 | case DATA_ST_HEAD: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1026 | if (s->data_ctx.stats.flags & STAT_SHOW_STAT) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1027 | print_csv_header(&msg); |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1028 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1029 | return 0; |
| 1030 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1031 | |
| 1032 | s->data_state = DATA_ST_INFO; |
| 1033 | /* fall through */ |
| 1034 | |
| 1035 | case DATA_ST_INFO: |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1036 | up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1037 | if (s->data_ctx.stats.flags & STAT_SHOW_INFO) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1038 | chunk_printf(&msg, |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1039 | "Name: " PRODUCT_NAME "\n" |
| 1040 | "Version: " HAPROXY_VERSION "\n" |
| 1041 | "Release_date: " HAPROXY_DATE "\n" |
| 1042 | "Nbproc: %d\n" |
| 1043 | "Process_num: %d\n" |
| 1044 | "Pid: %d\n" |
| 1045 | "Uptime: %dd %dh%02dm%02ds\n" |
| 1046 | "Uptime_sec: %d\n" |
| 1047 | "Memmax_MB: %d\n" |
| 1048 | "Ulimit-n: %d\n" |
| 1049 | "Maxsock: %d\n" |
| 1050 | "Maxconn: %d\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 1051 | "Maxpipes: %d\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1052 | "CurrConns: %d\n" |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 1053 | "PipesUsed: %d\n" |
| 1054 | "PipesFree: %d\n" |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 1055 | "Tasks: %d\n" |
| 1056 | "Run_queue: %d\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1057 | "node: %s\n" |
| 1058 | "description: %s\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1059 | "", |
| 1060 | global.nbproc, |
| 1061 | relative_pid, |
| 1062 | pid, |
| 1063 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 1064 | up, |
| 1065 | global.rlimit_memmax, |
| 1066 | global.rlimit_nofile, |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 1067 | global.maxsock, global.maxconn, global.maxpipes, |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 1068 | actconn, pipes_used, pipes_free, |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1069 | nb_tasks_cur, run_queue_cur, |
| 1070 | global.node, global.desc?global.desc:"" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1071 | ); |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1072 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1073 | return 0; |
| 1074 | } |
| 1075 | |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1076 | s->data_ctx.stats.px = proxy; |
| 1077 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1078 | |
| 1079 | s->data_ctx.stats.sv = NULL; |
| 1080 | s->data_ctx.stats.sv_st = 0; |
| 1081 | |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1082 | s->data_state = DATA_ST_LIST; |
| 1083 | /* fall through */ |
| 1084 | |
| 1085 | case DATA_ST_LIST: |
| 1086 | /* dump proxies */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1087 | if (s->data_ctx.stats.flags & STAT_SHOW_STAT) { |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1088 | while (s->data_ctx.stats.px) { |
| 1089 | px = s->data_ctx.stats.px; |
| 1090 | /* skip the disabled proxies and non-networked ones */ |
| 1091 | if (px->state != PR_STSTOPPED && |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1092 | (px->cap & (PR_CAP_FE | PR_CAP_BE))) { |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1093 | if (stats_dump_proxy(s, px, NULL) == 0) |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1094 | return 0; |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1095 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1096 | |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1097 | s->data_ctx.stats.px = px->next; |
| 1098 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 1099 | } |
| 1100 | /* here, we just have reached the last proxy */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1101 | } |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1102 | |
| 1103 | s->data_state = DATA_ST_END; |
| 1104 | /* fall through */ |
| 1105 | |
| 1106 | case DATA_ST_END: |
| 1107 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 1108 | /* fall through */ |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1109 | |
| 1110 | case DATA_ST_FIN: |
| 1111 | return 1; |
| 1112 | |
| 1113 | default: |
| 1114 | /* unknown state ! */ |
Willy Tarreau | 24955a1 | 2009-10-04 11:54:04 +0200 | [diff] [blame] | 1115 | s->data_state = DATA_ST_FIN; |
| 1116 | return 1; |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1117 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1121 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 1122 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
| 1123 | * si->st0 becomes non-zero once the transfer is finished. The handler |
| 1124 | * automatically unregisters itself once transfer is complete. |
| 1125 | */ |
| 1126 | void http_stats_io_handler(struct stream_interface *si) |
| 1127 | { |
| 1128 | struct session *s = si->private; |
| 1129 | struct buffer *req = si->ob; |
| 1130 | struct buffer *res = si->ib; |
| 1131 | |
| 1132 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 1133 | goto out; |
| 1134 | |
| 1135 | /* check that the output is not closed */ |
| 1136 | if (res->flags & (BF_SHUTW|BF_SHUTW_NOW)) |
| 1137 | si->st0 = 1; |
| 1138 | |
| 1139 | if (!si->st0) { |
| 1140 | if (stats_dump_http(s, res, s->be->uri_auth)) { |
| 1141 | si->st0 = 1; |
| 1142 | si->shutw(si); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | if ((res->flags & BF_SHUTR) && (si->state == SI_ST_EST)) |
| 1147 | si->shutw(si); |
| 1148 | |
| 1149 | if ((req->flags & BF_SHUTW) && (si->state == SI_ST_EST) && si->st0) { |
| 1150 | si->shutr(si); |
| 1151 | res->flags |= BF_READ_NULL; |
| 1152 | } |
| 1153 | |
| 1154 | /* update all other flags and resync with the other side */ |
| 1155 | si->update(si); |
| 1156 | |
| 1157 | /* we don't want to expire timeouts while we're processing requests */ |
| 1158 | si->ib->rex = TICK_ETERNITY; |
| 1159 | si->ob->wex = TICK_ETERNITY; |
| 1160 | |
| 1161 | out: |
| 1162 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) { |
| 1163 | /* check that we have released everything then unregister */ |
| 1164 | stream_int_unregister_handler(si); |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | |
Willy Tarreau | 3e76e72 | 2007-10-17 18:57:38 +0200 | [diff] [blame] | 1169 | /* |
| 1170 | * Produces statistics data for the session <s>. Expects to be called with |
Willy Tarreau | 1ae3a05 | 2008-08-16 10:56:30 +0200 | [diff] [blame] | 1171 | * 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] | 1172 | * 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] | 1173 | * when there is free space in the buffer, of simply by letting an empty buffer |
| 1174 | * upon return.s->data_ctx must have been zeroed before the first call, and the |
| 1175 | * flags set. It returns 0 if it had to stop writing data and an I/O is needed, |
| 1176 | * 1 if the dump is finished and the session must be closed, or -1 in case of |
| 1177 | * any error. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1178 | */ |
Willy Tarreau | 0a46489 | 2008-12-07 18:30:00 +0100 | [diff] [blame] | 1179 | 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] | 1180 | { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1181 | struct proxy *px; |
| 1182 | struct chunk msg; |
| 1183 | unsigned int up; |
| 1184 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1185 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1186 | |
| 1187 | switch (s->data_state) { |
| 1188 | case DATA_ST_INIT: |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1189 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1190 | "HTTP/1.0 200 OK\r\n" |
| 1191 | "Cache-Control: no-cache\r\n" |
| 1192 | "Connection: close\r\n" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1193 | "Content-Type: %s\r\n", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1194 | (s->data_ctx.stats.flags & STAT_FMT_CSV) ? "text/plain" : "text/html"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1195 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1196 | if (uri->refresh > 0 && !(s->data_ctx.stats.flags & STAT_NO_REFRESH)) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1197 | chunk_printf(&msg, "Refresh: %d\r\n", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1198 | uri->refresh); |
| 1199 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1200 | chunk_printf(&msg, "\r\n"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1201 | |
| 1202 | s->txn.status = 200; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1203 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 56a560a | 2009-09-22 19:27:35 +0200 | [diff] [blame] | 1204 | return 0; |
| 1205 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1206 | if (!(s->flags & SN_ERR_MASK)) // this is not really an error but it is |
| 1207 | s->flags |= SN_ERR_PRXCOND; // to mark that it comes from the proxy |
| 1208 | if (!(s->flags & SN_FINST_MASK)) |
| 1209 | s->flags |= SN_FINST_R; |
| 1210 | |
| 1211 | if (s->txn.meth == HTTP_METH_HEAD) { |
| 1212 | /* that's all we return in case of HEAD request */ |
| 1213 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1214 | return 1; |
| 1215 | } |
| 1216 | |
| 1217 | s->data_state = DATA_ST_HEAD; /* let's start producing data */ |
| 1218 | /* fall through */ |
| 1219 | |
| 1220 | case DATA_ST_HEAD: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1221 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 1222 | /* WARNING! This must fit in the first buffer !!! */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1223 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1224 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 1225 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 1226 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1227 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 1228 | "<style type=\"text/css\"><!--\n" |
| 1229 | "body {" |
Willy Tarreau | a94f2d2 | 2009-05-10 20:08:10 +0200 | [diff] [blame] | 1230 | " font-family: arial, helvetica, sans-serif;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1231 | " font-size: 12px;" |
| 1232 | " font-weight: normal;" |
| 1233 | " color: black;" |
| 1234 | " background: white;" |
| 1235 | "}\n" |
| 1236 | "th,td {" |
Willy Tarreau | a94f2d2 | 2009-05-10 20:08:10 +0200 | [diff] [blame] | 1237 | " font-size: 10px;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1238 | "}\n" |
| 1239 | "h1 {" |
Willy Tarreau | da6721b | 2009-07-15 10:07:05 +0200 | [diff] [blame] | 1240 | " font-size: x-large;" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1241 | " margin-bottom: 0.5em;" |
| 1242 | "}\n" |
| 1243 | "h2 {" |
| 1244 | " font-family: helvetica, arial;" |
| 1245 | " font-size: x-large;" |
| 1246 | " font-weight: bold;" |
| 1247 | " font-style: italic;" |
| 1248 | " color: #6020a0;" |
| 1249 | " margin-top: 0em;" |
| 1250 | " margin-bottom: 0em;" |
| 1251 | "}\n" |
| 1252 | "h3 {" |
| 1253 | " font-family: helvetica, arial;" |
| 1254 | " font-size: 16px;" |
| 1255 | " font-weight: bold;" |
| 1256 | " color: #b00040;" |
| 1257 | " background: #e8e8d0;" |
| 1258 | " margin-top: 0em;" |
| 1259 | " margin-bottom: 0em;" |
| 1260 | "}\n" |
| 1261 | "li {" |
| 1262 | " margin-top: 0.25em;" |
| 1263 | " margin-right: 2em;" |
| 1264 | "}\n" |
| 1265 | ".hr {margin-top: 0.25em;" |
| 1266 | " border-color: black;" |
| 1267 | " border-bottom-style: solid;" |
| 1268 | "}\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1269 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1270 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 1271 | ".frontend {background: #e8e8d0;}\n" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1272 | ".socket {background: #d0d0d0;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1273 | ".backend {background: #e8e8d0;}\n" |
| 1274 | ".active0 {background: #ff9090;}\n" |
| 1275 | ".active1 {background: #ffd020;}\n" |
| 1276 | ".active2 {background: #ffffa0;}\n" |
| 1277 | ".active3 {background: #c0ffc0;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1278 | ".active4 {background: #ffffa0;}\n" /* NOLB state shows same as going down */ |
| 1279 | ".active5 {background: #a0e0a0;}\n" /* NOLB state shows darker than up */ |
| 1280 | ".active6 {background: #e0e0e0;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1281 | ".backup0 {background: #ff9090;}\n" |
| 1282 | ".backup1 {background: #ff80ff;}\n" |
| 1283 | ".backup2 {background: #c060ff;}\n" |
| 1284 | ".backup3 {background: #b0d0ff;}\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1285 | ".backup4 {background: #c060ff;}\n" /* NOLB state shows same as going down */ |
| 1286 | ".backup5 {background: #90b0e0;}\n" /* NOLB state shows same as going down */ |
| 1287 | ".backup6 {background: #e0e0e0;}\n" |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1288 | ".maintain {background: #c07820;}\n" |
Willy Tarreau | da6721b | 2009-07-15 10:07:05 +0200 | [diff] [blame] | 1289 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1290 | "\n" |
Krzysztof Piotr Oledzki | 1f67285 | 2009-10-24 14:24:30 +0200 | [diff] [blame] | 1291 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 1292 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 1293 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 1294 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 1295 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 1296 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 1297 | "\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1298 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1299 | "table.tbl td { text-align: right; border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray; white-space: nowrap;}\n" |
| 1300 | "table.tbl td.ac { text-align: center;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1301 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1302 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
Willy Tarreau | da6721b | 2009-07-15 10:07:05 +0200 | [diff] [blame] | 1303 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1304 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1305 | "\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1306 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 1307 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 1308 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1309 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1310 | "-->\n" |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 1311 | "</style></head>\n", |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1312 | (uri->flags&ST_SHNODE) ? " on " : "", |
| 1313 | (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
Willy Tarreau | 1d45b7c | 2009-08-16 10:29:18 +0200 | [diff] [blame] | 1314 | ); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1315 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1316 | print_csv_header(&msg); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1317 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1318 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1319 | return 0; |
| 1320 | |
| 1321 | s->data_state = DATA_ST_INFO; |
| 1322 | /* fall through */ |
| 1323 | |
| 1324 | case DATA_ST_INFO: |
| 1325 | up = (now.tv_sec - start_date.tv_sec); |
| 1326 | |
| 1327 | /* WARNING! this has to fit the first packet too. |
| 1328 | * We are around 3.5 kB, add adding entries will |
| 1329 | * become tricky if we want to support 4kB buffers ! |
| 1330 | */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1331 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1332 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1333 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 1334 | PRODUCT_NAME "%s</a></h1>\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1335 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1336 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 1337 | "<h3>> General process information</h3>\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1338 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 1339 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1340 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1341 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 1342 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 1343 | "current conns = %d; current pipes = %d/%d<br>\n" |
| 1344 | "Running tasks: %d/%d<br>\n" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1345 | "</td><td align=\"center\" nowrap>\n" |
| 1346 | "<table class=\"lgd\"><tr>\n" |
| 1347 | "<td class=\"active3\"> </td><td class=\"noborder\">active UP </td>" |
| 1348 | "<td class=\"backup3\"> </td><td class=\"noborder\">backup UP </td>" |
| 1349 | "</tr><tr>\n" |
| 1350 | "<td class=\"active2\"></td><td class=\"noborder\">active UP, going down </td>" |
| 1351 | "<td class=\"backup2\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 1352 | "</tr><tr>\n" |
| 1353 | "<td class=\"active1\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 1354 | "<td class=\"backup1\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 1355 | "</tr><tr>\n" |
| 1356 | "<td class=\"active0\"></td><td class=\"noborder\">active or backup DOWN </td>" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1357 | "<td class=\"active6\"></td><td class=\"noborder\">not checked </td>" |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1358 | "</tr><tr>\n" |
| 1359 | "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) </td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1360 | "</tr></table>\n" |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1361 | "Note: UP with load-balancing disabled is reported as \"NOLB\"." |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1362 | "</td>" |
| 1363 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 1364 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 1365 | "", |
| 1366 | (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING), |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1367 | pid, (uri->flags&ST_SHNODE) ? " on " : "", (uri->flags&ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 1368 | (uri->flags&ST_SHDESC)? ": " : "", (uri->flags&ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 1369 | pid, relative_pid, global.nbproc, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1370 | up / 86400, (up % 86400) / 3600, |
| 1371 | (up % 3600) / 60, (up % 60), |
| 1372 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 1373 | global.rlimit_memmax ? " MB" : "", |
| 1374 | global.rlimit_nofile, |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 1375 | global.maxsock, global.maxconn, global.maxpipes, |
Willy Tarreau | c7bdf09 | 2009-03-21 18:33:52 +0100 | [diff] [blame] | 1376 | actconn, pipes_used, pipes_used+pipes_free, |
| 1377 | run_queue_cur, nb_tasks_cur |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1378 | ); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1379 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1380 | if (s->data_ctx.stats.flags & STAT_HIDE_DOWN) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1381 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1382 | "<li><a href=\"%s%s%s\">Show all servers</a><br>\n", |
| 1383 | uri->uri_prefix, |
| 1384 | "", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1385 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1386 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1387 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1388 | "<li><a href=\"%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 1389 | uri->uri_prefix, |
| 1390 | ";up", |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1391 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1392 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1393 | if (uri->refresh > 0) { |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1394 | if (s->data_ctx.stats.flags & STAT_NO_REFRESH) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1395 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1396 | "<li><a href=\"%s%s%s\">Enable refresh</a><br>\n", |
| 1397 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1398 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1399 | ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1400 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1401 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1402 | "<li><a href=\"%s%s%s\">Disable refresh</a><br>\n", |
| 1403 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1404 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1405 | ";norefresh"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1406 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1407 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1408 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1409 | "<li><a href=\"%s%s%s\">Refresh now</a><br>\n", |
| 1410 | uri->uri_prefix, |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1411 | (s->data_ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 1412 | (s->data_ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : ""); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1413 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1414 | chunk_printf(&msg, |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 1415 | "<li><a href=\"%s;csv%s\">CSV export</a><br>\n", |
| 1416 | uri->uri_prefix, |
| 1417 | (uri->refresh > 0) ? ";norefresh" : ""); |
| 1418 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1419 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1420 | "</ul></td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1421 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 1422 | "<b>External ressources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 1423 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 1424 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 1425 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 1426 | "</ul>" |
| 1427 | "</td>" |
| 1428 | "</tr></table>\n" |
| 1429 | "" |
| 1430 | ); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 1431 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1432 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1433 | return 0; |
| 1434 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1435 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1436 | s->data_ctx.stats.px = proxy; |
| 1437 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 1438 | s->data_state = DATA_ST_LIST; |
| 1439 | /* fall through */ |
| 1440 | |
| 1441 | case DATA_ST_LIST: |
| 1442 | /* dump proxies */ |
| 1443 | while (s->data_ctx.stats.px) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1444 | if (buffer_almost_full(rep)) |
| 1445 | return 0; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1446 | px = s->data_ctx.stats.px; |
| 1447 | /* skip the disabled proxies and non-networked ones */ |
| 1448 | 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] | 1449 | if (stats_dump_proxy(s, px, uri) == 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1450 | return 0; |
| 1451 | |
| 1452 | s->data_ctx.stats.px = px->next; |
| 1453 | s->data_ctx.stats.px_st = DATA_ST_PX_INIT; |
| 1454 | } |
| 1455 | /* here, we just have reached the last proxy */ |
| 1456 | |
| 1457 | s->data_state = DATA_ST_END; |
| 1458 | /* fall through */ |
| 1459 | |
| 1460 | case DATA_ST_END: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1461 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1462 | chunk_printf(&msg, "</body></html>\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1463 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1464 | return 0; |
| 1465 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1466 | |
| 1467 | s->data_state = DATA_ST_FIN; |
| 1468 | /* fall through */ |
| 1469 | |
| 1470 | case DATA_ST_FIN: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1471 | return 1; |
| 1472 | |
| 1473 | default: |
| 1474 | /* unknown state ! */ |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1475 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1476 | return -1; |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | |
| 1481 | /* |
| 1482 | * Dumps statistics for a proxy. |
| 1483 | * Returns 0 if it had to stop dumping data because of lack of buffer space, |
| 1484 | * ot non-zero if everything completed. |
| 1485 | */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1486 | 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] | 1487 | { |
| 1488 | struct buffer *rep = s->rep; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1489 | struct server *sv, *svs; /* server and server-state, server-state=server or server->tracked */ |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1490 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1491 | struct chunk msg; |
| 1492 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1493 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1494 | |
| 1495 | switch (s->data_ctx.stats.px_st) { |
| 1496 | case DATA_ST_PX_INIT: |
| 1497 | /* we are on a new proxy */ |
| 1498 | |
| 1499 | if (uri && uri->scope) { |
| 1500 | /* we have a limited scope, we have to check the proxy name */ |
| 1501 | struct stat_scope *scope; |
| 1502 | int len; |
| 1503 | |
| 1504 | len = strlen(px->id); |
| 1505 | scope = uri->scope; |
| 1506 | |
| 1507 | while (scope) { |
| 1508 | /* match exact proxy name */ |
| 1509 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 1510 | break; |
| 1511 | |
| 1512 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 1513 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1514 | break; |
| 1515 | scope = scope->next; |
| 1516 | } |
| 1517 | |
| 1518 | /* proxy name not found : don't dump anything */ |
| 1519 | if (scope == NULL) |
| 1520 | return 1; |
| 1521 | } |
| 1522 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1523 | 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] | 1524 | (px->uuid != s->data_ctx.stats.iid)) |
| 1525 | return 1; |
| 1526 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1527 | s->data_ctx.stats.px_st = DATA_ST_PX_TH; |
| 1528 | /* fall through */ |
| 1529 | |
| 1530 | case DATA_ST_PX_TH: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1531 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1532 | /* print a new table */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1533 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1534 | "<table class=\"tbl\" width=\"100%%\">\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1535 | "<tr class=\"titre\">" |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 1536 | "<th class=\"pxname\" width=\"10%%\""); |
| 1537 | |
| 1538 | if (uri->flags&ST_SHLGNDS) { |
| 1539 | /* cap, mode, id */ |
| 1540 | chunk_printf(&msg, " title=\"cap: %s, mode: %s, id: %d", |
| 1541 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 1542 | px->uuid); |
| 1543 | |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 1544 | chunk_printf(&msg, "\""); |
| 1545 | } |
| 1546 | |
| 1547 | chunk_printf(&msg, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1548 | ">%s<a name=\"%s\"></a>" |
| 1549 | "<a class=px href=\"#%s\">%s</a>%s</th>" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1550 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1551 | "</tr>\n" |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1552 | "</table>\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1553 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 1554 | "<tr class=\"titre\">" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1555 | "<th rowspan=2></th>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1556 | "<th colspan=3>Queue</th>" |
| 1557 | "<th colspan=3>Session rate</th><th colspan=5>Sessions</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1558 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1559 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1560 | "<th colspan=9>Server</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1561 | "</tr>\n" |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1562 | "<tr class=\"titre\">" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1563 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1564 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1565 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>In</th><th>Out</th>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1566 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1567 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1568 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 1569 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 1570 | "<th>Thrtle</th>\n" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1571 | "</tr>", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1572 | (uri->flags & ST_SHLGNDS)?"<u>":"", |
Krzysztof Piotr Oledzki | 1f67285 | 2009-10-24 14:24:30 +0200 | [diff] [blame] | 1573 | px->id, px->id, px->id, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1574 | (uri->flags & ST_SHLGNDS)?"</u>":"", |
Krzysztof Piotr Oledzki | 48cb2ae | 2009-10-02 22:51:14 +0200 | [diff] [blame] | 1575 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1576 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1577 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1578 | return 0; |
| 1579 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1580 | |
| 1581 | s->data_ctx.stats.px_st = DATA_ST_PX_FE; |
| 1582 | /* fall through */ |
| 1583 | |
| 1584 | case DATA_ST_PX_FE: |
| 1585 | /* print the frontend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1586 | if ((px->cap & PR_CAP_FE) && |
| 1587 | (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_FE)))) { |
| 1588 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1589 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1590 | /* name, queue */ |
Krzysztof Piotr Oledzki | 516ed49 | 2009-10-22 22:48:09 +0200 | [diff] [blame] | 1591 | "<tr class=\"frontend\"><td class=ac>" |
Krzysztof Piotr Oledzki | 1f67285 | 2009-10-24 14:24:30 +0200 | [diff] [blame] | 1592 | "<a name=\"%s/Frontend\"></a>" |
| 1593 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td><td colspan=3></td>" |
Willy Tarreau | b44939a | 2010-02-26 11:35:39 +0100 | [diff] [blame] | 1594 | "", |
| 1595 | px->id, px->id); |
| 1596 | |
| 1597 | if (px->mode == PR_MODE_HTTP) { |
| 1598 | chunk_printf(&msg, |
| 1599 | /* sessions rate : current, max, limit */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1600 | "<td title=\"Cur: %u req/s\"><u>%s</u></td><td title=\"Max: %u req/s\"><u>%s</u></td><td>%s</td>" |
Willy Tarreau | b44939a | 2010-02-26 11:35:39 +0100 | [diff] [blame] | 1601 | "", |
| 1602 | read_freq_ctr(&px->fe_req_per_sec), |
| 1603 | U2H0(read_freq_ctr(&px->fe_sess_per_sec)), |
| 1604 | px->counters.fe_rps_max, |
| 1605 | U2H2(px->counters.fe_sps_max), |
| 1606 | LIM2A2(px->fe_sps_lim, "-")); |
| 1607 | } else { |
| 1608 | chunk_printf(&msg, |
| 1609 | /* sessions rate : current, max, limit */ |
| 1610 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 1611 | "", |
| 1612 | U2H0(read_freq_ctr(&px->fe_sess_per_sec)), |
| 1613 | U2H1(px->counters.fe_sps_max), LIM2A2(px->fe_sps_lim, "-")); |
| 1614 | } |
| 1615 | |
| 1616 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1617 | /* sessions: current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1618 | "<td>%s</td><td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1619 | "<td" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1620 | "", |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1621 | U2H3(px->feconn), U2H4(px->counters.feconn_max), U2H5(px->maxconn)); |
| 1622 | |
| 1623 | /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1624 | if (px->mode == PR_MODE_HTTP) { |
| 1625 | int i; |
| 1626 | |
Willy Tarreau | b44939a | 2010-02-26 11:35:39 +0100 | [diff] [blame] | 1627 | chunk_printf(&msg, " title=\"%lld requests:", px->counters.cum_fe_req); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1628 | |
| 1629 | for (i = 1; i < 6; i++) |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 1630 | chunk_printf(&msg, " %dxx=%lld,", i, px->counters.fe.http.rsp[i]); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1631 | |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 1632 | chunk_printf(&msg, " other=%lld\"", px->counters.fe.http.rsp[0]); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | chunk_printf(&msg, |
| 1636 | /* sessions: total, lbtot */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1637 | ">%s%s%s</td><td></td>" |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1638 | /* bytes : in, out */ |
| 1639 | "<td>%s</td><td>%s</td>" |
| 1640 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1641 | (px->mode == PR_MODE_HTTP)?"<u>":"", |
| 1642 | U2H6(px->counters.cum_feconn), |
| 1643 | (px->mode == PR_MODE_HTTP)?"</u>":"", |
| 1644 | U2H7(px->counters.bytes_in), U2H8(px->counters.bytes_out)); |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1645 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1646 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1647 | /* denied: req, resp */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1648 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1649 | /* errors : request, connect, response */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1650 | "<td>%s</td><td></td><td></td>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1651 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1652 | "<td></td><td></td>" |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1653 | /* server status : reflect frontend status */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1654 | "<td class=ac>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1655 | /* rest of server: nothing */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1656 | "<td class=ac colspan=8></td></tr>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1657 | "", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1658 | U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp), |
| 1659 | U2H2(px->counters.failed_req), |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1660 | px->state == PR_STRUN ? "OPEN" : |
| 1661 | px->state == PR_STIDLE ? "FULL" : "STOP"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1662 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1663 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1664 | /* pxid, name, queue cur, queue max, */ |
| 1665 | "%s,FRONTEND,,," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 1666 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1667 | "%d,%d,%d,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1668 | /* bytes : in, out */ |
| 1669 | "%lld,%lld," |
| 1670 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1671 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1672 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 1673 | "%lld,,," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 1674 | /* warnings: retries, redispatches */ |
| 1675 | ",," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1676 | /* server status : reflect frontend status */ |
| 1677 | "%s," |
| 1678 | /* rest of server: nothing */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1679 | ",,,,,,,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1680 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 1681 | "%d,%d,0,,,,%d," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1682 | /* rate, rate_lim, rate_max */ |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 1683 | "%u,%u,%u," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1684 | /* check_status, check_code, check_duration */ |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1685 | ",,,", |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1686 | px->id, |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1687 | px->feconn, px->counters.feconn_max, px->maxconn, px->counters.cum_feconn, |
| 1688 | px->counters.bytes_in, px->counters.bytes_out, |
| 1689 | px->counters.denied_req, px->counters.denied_resp, |
| 1690 | px->counters.failed_req, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1691 | px->state == PR_STRUN ? "OPEN" : |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 1692 | px->state == PR_STIDLE ? "FULL" : "STOP", |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 1693 | relative_pid, px->uuid, STATS_TYPE_FE, |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 1694 | read_freq_ctr(&px->fe_sess_per_sec), |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 1695 | px->fe_sps_lim, px->counters.fe_sps_max); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1696 | |
| 1697 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1698 | if (px->mode == PR_MODE_HTTP) { |
| 1699 | int i; |
| 1700 | |
| 1701 | for (i=1; i<6; i++) |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 1702 | chunk_printf(&msg, "%lld,", px->counters.fe.http.rsp[i]); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1703 | |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 1704 | chunk_printf(&msg, "%lld,", px->counters.fe.http.rsp[0]); |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1705 | } else { |
| 1706 | chunk_printf(&msg, ",,,,,,"); |
| 1707 | } |
| 1708 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 1709 | /* failed health analyses */ |
| 1710 | chunk_printf(&msg, ","); |
| 1711 | |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 1712 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 1713 | chunk_printf(&msg, "%u,%u,%lld,", |
| 1714 | read_freq_ctr(&px->fe_req_per_sec), |
| 1715 | px->counters.fe_rps_max, px->counters.cum_fe_req); |
| 1716 | |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1717 | /* errors: cli_aborts, srv_aborts */ |
| 1718 | chunk_printf(&msg, ",,"); |
| 1719 | |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1720 | /* finish with EOL */ |
| 1721 | chunk_printf(&msg, "\n"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 1722 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1723 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 1724 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1725 | return 0; |
| 1726 | } |
| 1727 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1728 | s->data_ctx.stats.l = px->listen; /* may be NULL */ |
| 1729 | s->data_ctx.stats.px_st = DATA_ST_PX_LI; |
| 1730 | /* fall through */ |
| 1731 | |
| 1732 | case DATA_ST_PX_LI: |
| 1733 | /* stats.l has been initialized above */ |
| 1734 | for (; s->data_ctx.stats.l != NULL; s->data_ctx.stats.l = l->next) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1735 | if (buffer_almost_full(rep)) |
| 1736 | return 0; |
| 1737 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1738 | l = s->data_ctx.stats.l; |
| 1739 | if (!l->counters) |
| 1740 | continue; |
| 1741 | |
| 1742 | if (s->data_ctx.stats.flags & STAT_BOUND) { |
| 1743 | if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SO))) |
| 1744 | break; |
| 1745 | |
| 1746 | if (s->data_ctx.stats.sid != -1 && l->luid != s->data_ctx.stats.sid) |
| 1747 | continue; |
| 1748 | } |
| 1749 | |
| 1750 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 1751 | chunk_printf(&msg, "<tr class=socket><td class=ac"); |
| 1752 | |
| 1753 | if (uri->flags&ST_SHLGNDS) { |
| 1754 | char str[INET6_ADDRSTRLEN], *fmt = NULL; |
| 1755 | int port; |
| 1756 | |
| 1757 | chunk_printf(&msg, " title=\"IP: "); |
| 1758 | |
| 1759 | port = (l->addr.ss_family == AF_INET6) |
| 1760 | ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port) |
| 1761 | : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port); |
| 1762 | |
| 1763 | if (l->addr.ss_family == AF_INET) { |
| 1764 | if (inet_ntop(AF_INET, |
| 1765 | (const void *)&((struct sockaddr_in *)&l->addr)->sin_addr, |
| 1766 | str, sizeof(str))) |
| 1767 | fmt = "%s:%d"; |
| 1768 | } else { |
| 1769 | if (inet_ntop(AF_INET6, |
| 1770 | (const void *)&((struct sockaddr_in6 *)(&l->addr))->sin6_addr, |
| 1771 | str, sizeof(str))) |
| 1772 | fmt = "[%s]:%d"; |
| 1773 | } |
| 1774 | |
| 1775 | if (fmt) |
| 1776 | chunk_printf(&msg, fmt, str, port); |
| 1777 | else |
| 1778 | chunk_printf(&msg, "(%s)", strerror(errno)); |
| 1779 | |
| 1780 | /* id */ |
| 1781 | chunk_printf(&msg, ", id: %d", l->luid); |
| 1782 | |
| 1783 | chunk_printf(&msg, "\""); |
| 1784 | } |
| 1785 | |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1786 | chunk_printf(&msg, |
| 1787 | /* name, queue */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1788 | ">%s<a name=\"%s/+%s\"></a>" |
| 1789 | "<a class=lfsb href=\"#%s/+%s\">%s</a></td><td colspan=3>%s</td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1790 | /* sessions rate: current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1791 | "<td colspan=3> </td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1792 | /* sessions: current, max, limit, total, lbtot */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1793 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 1794 | "<td>%s</td><td> </td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1795 | /* bytes: in, out */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1796 | "<td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1797 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1798 | (uri->flags & ST_SHLGNDS)?"<u>":"", |
Krzysztof Piotr Oledzki | 2ec025d | 2010-01-04 11:33:32 +0100 | [diff] [blame] | 1799 | px->id, l->name, px->id, l->name, l->name, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1800 | (uri->flags & ST_SHLGNDS)?"</u>":"", |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1801 | U2H3(l->nbconn), U2H4(l->counters->conn_max), U2H5(l->maxconn), |
| 1802 | U2H6(l->counters->cum_conn), U2H7(l->counters->bytes_in), U2H8(l->counters->bytes_out)); |
| 1803 | |
| 1804 | chunk_printf(&msg, |
| 1805 | /* denied: req, resp */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1806 | "<td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1807 | /* errors: request, connect, response */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1808 | "<td>%s</td><td></td><td></td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1809 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1810 | "<td></td><td></td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1811 | /* server status: reflect listener status */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1812 | "<td class=ac>%s</td>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1813 | /* rest of server: nothing */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1814 | "<td class=ac colspan=8></td></tr>" |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1815 | "", |
| 1816 | U2H0(l->counters->denied_req), U2H1(l->counters->denied_resp), |
| 1817 | U2H2(l->counters->failed_req), |
| 1818 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL"); |
| 1819 | } else { |
| 1820 | chunk_printf(&msg, |
| 1821 | /* pxid, name, queue cur, queue max, */ |
| 1822 | "%s,%s,,," |
| 1823 | /* sessions: current, max, limit, total */ |
| 1824 | "%d,%d,%d,%lld," |
| 1825 | /* bytes: in, out */ |
| 1826 | "%lld,%lld," |
| 1827 | /* denied: req, resp */ |
| 1828 | "%lld,%lld," |
| 1829 | /* errors: request, connect, response */ |
| 1830 | "%lld,,," |
| 1831 | /* warnings: retries, redispatches */ |
| 1832 | ",," |
| 1833 | /* server status: reflect listener status */ |
| 1834 | "%s," |
| 1835 | /* rest of server: nothing */ |
| 1836 | ",,,,,,,," |
| 1837 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 1838 | "%d,%d,%d,,,,%d," |
| 1839 | /* rate, rate_lim, rate_max */ |
| 1840 | ",,," |
| 1841 | /* check_status, check_code, check_duration */ |
| 1842 | ",,," |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 1843 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1844 | ",,,,,," |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 1845 | /* failed health analyses */ |
| 1846 | "," |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 1847 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 1848 | ",,," |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1849 | /* errors: cli_aborts, srv_aborts */ |
| 1850 | ",," |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1851 | "\n", |
| 1852 | px->id, l->name, |
| 1853 | l->nbconn, l->counters->conn_max, |
| 1854 | l->maxconn, l->counters->cum_conn, |
| 1855 | l->counters->bytes_in, l->counters->bytes_out, |
| 1856 | l->counters->denied_req, l->counters->denied_resp, |
| 1857 | l->counters->failed_req, |
| 1858 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 1859 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 1860 | } |
| 1861 | |
| 1862 | if (buffer_feed_chunk(rep, &msg) >= 0) |
| 1863 | return 0; |
| 1864 | } |
| 1865 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1866 | s->data_ctx.stats.sv = px->srv; /* may be NULL */ |
| 1867 | s->data_ctx.stats.px_st = DATA_ST_PX_SV; |
| 1868 | /* fall through */ |
| 1869 | |
| 1870 | case DATA_ST_PX_SV: |
| 1871 | /* stats.sv has been initialized above */ |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1872 | for (; s->data_ctx.stats.sv != NULL; s->data_ctx.stats.sv = sv->next) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1873 | 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] | 1874 | |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 1875 | if (buffer_almost_full(rep)) |
| 1876 | return 0; |
| 1877 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1878 | sv = s->data_ctx.stats.sv; |
| 1879 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1880 | if (s->data_ctx.stats.flags & STAT_BOUND) { |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 1881 | if (!(s->data_ctx.stats.type & (1 << STATS_TYPE_SV))) |
| 1882 | break; |
| 1883 | |
| 1884 | if (s->data_ctx.stats.sid != -1 && sv->puid != s->data_ctx.stats.sid) |
| 1885 | continue; |
| 1886 | } |
| 1887 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1888 | if (sv->tracked) |
| 1889 | svs = sv->tracked; |
| 1890 | else |
| 1891 | svs = sv; |
| 1892 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1893 | /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1894 | if (!(svs->state & SRV_CHECKED)) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1895 | sv_state = 6; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1896 | else if (svs->state & SRV_RUNNING) { |
| 1897 | if (svs->health == svs->rise + svs->fall - 1) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1898 | sv_state = 3; /* UP */ |
| 1899 | else |
| 1900 | sv_state = 2; /* going down */ |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1901 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1902 | if (svs->state & SRV_GOINGDOWN) |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1903 | sv_state += 2; |
| 1904 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1905 | else |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1906 | if (svs->health) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1907 | sv_state = 1; /* going up */ |
| 1908 | else |
| 1909 | sv_state = 0; /* DOWN */ |
| 1910 | |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 1911 | if (((sv_state == 0) || (sv->state & SRV_MAINTAIN)) && (s->data_ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1912 | /* do not report servers which are DOWN */ |
| 1913 | s->data_ctx.stats.sv = sv->next; |
| 1914 | continue; |
| 1915 | } |
| 1916 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 1917 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 1918 | static char *srv_hlt_st[7] = { "DOWN", "DN %d/%d ↑", |
| 1919 | "UP %d/%d ↓", "UP", |
| 1920 | "NOLB %d/%d ↓", "NOLB", |
| 1921 | "<i>no check</i>" }; |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 1922 | if ((sv->state & SRV_MAINTAIN) || (svs->state & SRV_MAINTAIN)) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1923 | chunk_printf(&msg, |
| 1924 | /* name */ |
| 1925 | "<tr class=\"maintain\"><td class=ac" |
| 1926 | ); |
| 1927 | } |
| 1928 | else { |
| 1929 | chunk_printf(&msg, |
| 1930 | /* name */ |
| 1931 | "<tr class=\"%s%d\"><td class=ac", |
| 1932 | (sv->state & SRV_BACKUP) ? "backup" : "active", sv_state); |
| 1933 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 1934 | |
| 1935 | if (uri->flags&ST_SHLGNDS) { |
| 1936 | char str[INET6_ADDRSTRLEN]; |
| 1937 | |
| 1938 | chunk_printf(&msg, " title=\"IP: "); |
| 1939 | |
| 1940 | /* IP */ |
| 1941 | if (inet_ntop(sv->addr.sin_family, &sv->addr.sin_addr, str, sizeof(str))) |
| 1942 | chunk_printf(&msg, "%s:%d", str, htons(sv->addr.sin_port)); |
| 1943 | else |
| 1944 | chunk_printf(&msg, "(%s)", strerror(errno)); |
| 1945 | |
| 1946 | /* id */ |
| 1947 | chunk_printf(&msg, ", id: %d", sv->puid); |
| 1948 | |
| 1949 | /* cookie */ |
| 1950 | if (sv->cookie) { |
| 1951 | struct chunk src; |
| 1952 | |
| 1953 | chunk_printf(&msg, ", cookie: '"); |
| 1954 | |
| 1955 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 1956 | chunk_htmlencode(&msg, &src); |
| 1957 | |
| 1958 | chunk_printf(&msg, "'"); |
| 1959 | } |
| 1960 | |
| 1961 | chunk_printf(&msg, "\""); |
| 1962 | } |
| 1963 | |
| 1964 | chunk_printf(&msg, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1965 | ">%s<a name=\"%s/%s\"></a>" |
| 1966 | "<a class=lfsb href=\"#%s/%s\">%s</a>%s</td>" |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 1967 | /* queue : current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1968 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 1969 | /* sessions rate : current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1970 | "<td>%s</td><td>%s</td><td></td>" |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 1971 | /* sessions: current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 1972 | "<td>%s</td><td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 1973 | "<td" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1974 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1975 | (uri->flags & ST_SHLGNDS)?"<u>":"", |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 1976 | px->id, sv->id, px->id, sv->id, sv->id, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1977 | (uri->flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 1978 | U2H0(sv->nbpend), U2H1(sv->counters.nbpend_max), LIM2A2(sv->maxqueue, "-"), |
| 1979 | U2H3(read_freq_ctr(&sv->sess_per_sec)), U2H4(sv->counters.sps_max), |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 1980 | U2H5(sv->cur_sess), U2H6(sv->counters.cur_sess_max), LIM2A7(sv->maxconn, "-")); |
| 1981 | |
| 1982 | /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1983 | if (px->mode == PR_MODE_HTTP) { |
| 1984 | int i; |
| 1985 | |
| 1986 | chunk_printf(&msg, " title=\"rsp codes:"); |
| 1987 | |
| 1988 | for (i = 1; i < 6; i++) |
| 1989 | chunk_printf(&msg, " %dxx=%lld,", i, sv->counters.p.http.rsp[i]); |
| 1990 | |
| 1991 | chunk_printf(&msg, " other=%lld\"", sv->counters.p.http.rsp[0]); |
| 1992 | } |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 1993 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 1994 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 1995 | /* sessions: total, lbtot */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 1996 | ">%s%s%s</td><td>%s</td>", |
| 1997 | (px->mode == PR_MODE_HTTP)?"<u>":"", |
| 1998 | U2H0(sv->counters.cum_sess), |
| 1999 | (px->mode == PR_MODE_HTTP)?"</u>":"", |
| 2000 | U2H1(sv->counters.cum_lbconn)); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2001 | |
| 2002 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2003 | /* bytes : in, out */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2004 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2005 | /* denied: req, resp */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2006 | "<td></td><td>%s</td>" |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2007 | /* errors : request, connect */ |
| 2008 | "<td></td><td>%s</td>" |
| 2009 | /* errors : response */ |
Willy Tarreau | 6a8573e | 2010-03-05 18:15:23 +0100 | [diff] [blame] | 2010 | "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 2011 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2012 | "<td>%lld</td><td>%lld</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2013 | "", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2014 | U2H0(sv->counters.bytes_in), U2H1(sv->counters.bytes_out), |
| 2015 | U2H2(sv->counters.failed_secu), |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2016 | U2H3(sv->counters.failed_conns), |
Willy Tarreau | 6a8573e | 2010-03-05 18:15:23 +0100 | [diff] [blame] | 2017 | sv->counters.cli_aborts, |
| 2018 | sv->counters.srv_aborts, |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2019 | U2H6(sv->counters.failed_resp), |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2020 | sv->counters.retries, sv->counters.redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2021 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2022 | /* status, lest check */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2023 | chunk_printf(&msg, "<td class=ac>"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2024 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2025 | if (sv->state & SRV_MAINTAIN) { |
| 2026 | chunk_printf(&msg, "%s ", |
| 2027 | human_time(now.tv_sec - sv->last_change, 1)); |
| 2028 | chunk_printf(&msg, "MAINT"); |
| 2029 | } |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2030 | else if (svs != sv && svs->state & SRV_MAINTAIN) { |
| 2031 | chunk_printf(&msg, "%s ", |
| 2032 | human_time(now.tv_sec - svs->last_change, 1)); |
| 2033 | chunk_printf(&msg, "MAINT(via)"); |
| 2034 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2035 | else if (svs->state & SRV_CHECKED) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2036 | chunk_printf(&msg, "%s ", |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2037 | human_time(now.tv_sec - svs->last_change, 1)); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2038 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2039 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2040 | srv_hlt_st[sv_state], |
| 2041 | (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), |
| 2042 | (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2043 | } |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 2044 | |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2045 | if (sv->state & SRV_CHECKED) { |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2046 | chunk_printf(&msg, "</td><td class=ac title=\"%s", |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 2047 | get_check_status_description(sv->check_status)); |
| 2048 | |
| 2049 | if (*sv->check_desc) { |
| 2050 | struct chunk src; |
| 2051 | |
| 2052 | chunk_printf(&msg, ": "); |
| 2053 | |
| 2054 | chunk_initlen(&src, sv->check_desc, 0, strlen(sv->check_desc)); |
| 2055 | chunk_htmlencode(&msg, &src); |
| 2056 | } |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2057 | |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2058 | chunk_printf(&msg, "\"><u> %s%s", |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2059 | tv_iszero(&sv->check_start)?"":"* ", |
| 2060 | get_check_status_info(sv->check_status)); |
| 2061 | |
| 2062 | if (sv->check_status >= HCHK_STATUS_L57DATA) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2063 | chunk_printf(&msg, "/%d", sv->check_code); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2064 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2065 | if (sv->check_status >= HCHK_STATUS_CHECKED && sv->check_duration >= 0) |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2066 | chunk_printf(&msg, " in %lums</u>", sv->check_duration); |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2067 | } else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2068 | chunk_printf(&msg, "</td><td>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2069 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2070 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2071 | /* weight */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2072 | "</td><td class=ac>%d</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2073 | /* act, bck */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2074 | "<td class=ac>%s</td><td class=ac>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2075 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 2076 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2077 | (sv->state & SRV_BACKUP) ? "-" : "Y", |
| 2078 | (sv->state & SRV_BACKUP) ? "Y" : "-"); |
| 2079 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2080 | /* check failures: unique, fatal, down time */ |
Krzysztof Piotr Oledzki | 748196e | 2010-01-04 00:48:43 +0100 | [diff] [blame] | 2081 | if (sv->state & SRV_CHECKED) { |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2082 | chunk_printf(&msg, "<td title=\"Failed Health Checks%s\"><u>%lld", |
Krzysztof Piotr Oledzki | 748196e | 2010-01-04 00:48:43 +0100 | [diff] [blame] | 2083 | svs->observe?"/Health Analyses":"", svs->counters.failed_checks); |
| 2084 | |
| 2085 | if (svs->observe) |
| 2086 | chunk_printf(&msg, "/%lld", svs->counters.failed_hana); |
| 2087 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2088 | chunk_printf(&msg, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2089 | "</u></td>" |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2090 | "<td>%lld</td><td>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2091 | "", |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2092 | svs->counters.down_trans, human_time(srv_downtime(sv), 1)); |
Krzysztof Piotr Oledzki | 748196e | 2010-01-04 00:48:43 +0100 | [diff] [blame] | 2093 | } else if (sv != svs) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2094 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | 88a14af | 2010-01-05 18:33:01 +0100 | [diff] [blame] | 2095 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s<a></td>", |
| 2096 | svs->proxy->id, svs->id, svs->proxy->id, svs->id); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2097 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2098 | chunk_printf(&msg, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2099 | "<td colspan=3></td>"); |
| 2100 | |
| 2101 | /* throttle */ |
| 2102 | if ((sv->state & SRV_WARMINGUP) && |
| 2103 | now.tv_sec < sv->last_change + sv->slowstart && |
| 2104 | now.tv_sec >= sv->last_change) { |
| 2105 | unsigned int ratio; |
| 2106 | ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2107 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2108 | "<td class=ac>%d %%</td></tr>\n", ratio); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2109 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2110 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2111 | "<td class=ac>-</td></tr>\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2112 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2113 | } else { |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2114 | static char *srv_hlt_st[7] = { "DOWN,", "DOWN %d/%d,", |
| 2115 | "UP %d/%d,", "UP,", |
| 2116 | "NOLB %d/%d,", "NOLB,", |
| 2117 | "no check," }; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2118 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2119 | /* pxid, name */ |
| 2120 | "%s,%s," |
| 2121 | /* queue : current, max */ |
| 2122 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 2123 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2124 | "%d,%d,%s,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2125 | /* bytes : in, out */ |
| 2126 | "%lld,%lld," |
| 2127 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2128 | ",%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2129 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2130 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 2131 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2132 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2133 | "", |
| 2134 | px->id, sv->id, |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 2135 | sv->nbpend, sv->counters.nbpend_max, |
| 2136 | sv->cur_sess, sv->counters.cur_sess_max, LIM2A0(sv->maxconn, ""), sv->counters.cum_sess, |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2137 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 2138 | sv->counters.failed_secu, |
| 2139 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 2140 | sv->counters.retries, sv->counters.redispatches); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2141 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2142 | /* status */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2143 | if (sv->state & SRV_MAINTAIN) { |
| 2144 | chunk_printf(&msg, "MAINT,"); |
Cyril Bonté | 0dae585 | 2010-02-03 00:26:28 +0100 | [diff] [blame] | 2145 | } |
| 2146 | else if (svs != sv && svs->state & SRV_MAINTAIN) { |
| 2147 | chunk_printf(&msg, "MAINT(via),"); |
| 2148 | } |
| 2149 | else { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2150 | chunk_printf(&msg, |
| 2151 | srv_hlt_st[sv_state], |
| 2152 | (svs->state & SRV_RUNNING) ? (svs->health - svs->rise + 1) : (svs->health), |
| 2153 | (svs->state & SRV_RUNNING) ? (svs->fall) : (svs->rise)); |
| 2154 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2155 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2156 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2157 | /* weight, active, backup */ |
| 2158 | "%d,%d,%d," |
| 2159 | "", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 2160 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2161 | (sv->state & SRV_BACKUP) ? 0 : 1, |
| 2162 | (sv->state & SRV_BACKUP) ? 1 : 0); |
| 2163 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2164 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2165 | if (sv->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2166 | chunk_printf(&msg, |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2167 | "%lld,%lld,%d,%d,", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2168 | sv->counters.failed_checks, sv->counters.down_trans, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 2169 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2170 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2171 | chunk_printf(&msg, |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 2172 | ",,,,"); |
| 2173 | |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2174 | /* queue limit, pid, iid, sid, */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2175 | chunk_printf(&msg, |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 2176 | "%s," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2177 | "%d,%d,%d,", |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 2178 | LIM2A0(sv->maxqueue, ""), |
| 2179 | relative_pid, px->uuid, sv->puid); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2180 | |
| 2181 | /* throttle */ |
| 2182 | if ((sv->state & SRV_WARMINGUP) && |
| 2183 | now.tv_sec < sv->last_change + sv->slowstart && |
| 2184 | now.tv_sec >= sv->last_change) { |
| 2185 | unsigned int ratio; |
| 2186 | ratio = MAX(1, 100 * (now.tv_sec - sv->last_change) / sv->slowstart); |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2187 | chunk_printf(&msg, "%d", ratio); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2188 | } |
| 2189 | |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 2190 | /* sessions: lbtot */ |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2191 | chunk_printf(&msg, ",%lld,", sv->counters.cum_lbconn); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2192 | |
| 2193 | /* tracked */ |
| 2194 | if (sv->tracked) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2195 | chunk_printf(&msg, "%s/%s,", |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2196 | sv->tracked->proxy->id, sv->tracked->id); |
| 2197 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2198 | chunk_printf(&msg, ","); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 2199 | |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 2200 | /* type */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2201 | chunk_printf(&msg, "%d,", STATS_TYPE_SV); |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 2202 | |
| 2203 | /* rate */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2204 | chunk_printf(&msg, "%u,,%u,", |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 2205 | read_freq_ctr(&sv->sess_per_sec), |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 2206 | sv->counters.sps_max); |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 2207 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2208 | if (sv->state & SRV_CHECKED) { |
| 2209 | /* check_status */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2210 | chunk_printf(&msg, "%s,", get_check_status_info(sv->check_status)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2211 | |
| 2212 | /* check_code */ |
| 2213 | if (sv->check_status >= HCHK_STATUS_L57DATA) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2214 | chunk_printf(&msg, "%u,", sv->check_code); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2215 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2216 | chunk_printf(&msg, ","); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2217 | |
| 2218 | /* check_duration */ |
Krzysztof Piotr Oledzki | 034550b | 2010-01-05 18:44:44 +0100 | [diff] [blame] | 2219 | if (sv->check_status >= HCHK_STATUS_CHECKED) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2220 | chunk_printf(&msg, "%lu,", sv->check_duration); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2221 | else |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2222 | chunk_printf(&msg, ","); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2223 | |
| 2224 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2225 | chunk_printf(&msg, ",,,"); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2226 | } |
| 2227 | |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2228 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2229 | if (px->mode == PR_MODE_HTTP) { |
| 2230 | int i; |
| 2231 | |
| 2232 | for (i=1; i<6; i++) |
| 2233 | chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[i]); |
| 2234 | |
| 2235 | chunk_printf(&msg, "%lld,", sv->counters.p.http.rsp[0]); |
| 2236 | } else { |
| 2237 | chunk_printf(&msg, ",,,,,,"); |
| 2238 | } |
| 2239 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2240 | /* failed health analyses */ |
| 2241 | chunk_printf(&msg, "%lld,", sv->counters.failed_hana); |
| 2242 | |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 2243 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2244 | chunk_printf(&msg, ",,,"); |
| 2245 | |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2246 | /* errors: cli_aborts, srv_aborts */ |
| 2247 | chunk_printf(&msg, "%lld,%lld,", |
| 2248 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 2249 | |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 2250 | /* finish with EOL */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2251 | chunk_printf(&msg, "\n"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2252 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2253 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2254 | return 0; |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2255 | } /* for sv */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2256 | |
| 2257 | s->data_ctx.stats.px_st = DATA_ST_PX_BE; |
| 2258 | /* fall through */ |
| 2259 | |
| 2260 | case DATA_ST_PX_BE: |
| 2261 | /* print the backend */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 2262 | if ((px->cap & PR_CAP_BE) && |
| 2263 | (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_BE)))) { |
| 2264 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2265 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2266 | /* name */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2267 | "<tr class=\"backend\"><td class=ac"); |
| 2268 | |
| 2269 | if (uri->flags&ST_SHLGNDS) { |
| 2270 | /* balancing */ |
Krzysztof Piotr Oledzki | c0f0c86 | 2010-01-06 15:03:18 +0100 | [diff] [blame] | 2271 | chunk_printf(&msg, " title=\"balancing: %s", |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2272 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
Krzysztof Piotr Oledzki | c0f0c86 | 2010-01-06 15:03:18 +0100 | [diff] [blame] | 2273 | |
| 2274 | /* cookie */ |
| 2275 | if (px->cookie_name) { |
| 2276 | struct chunk src; |
| 2277 | |
| 2278 | chunk_printf(&msg, ", cookie: '"); |
| 2279 | |
| 2280 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 2281 | chunk_htmlencode(&msg, &src); |
| 2282 | |
| 2283 | chunk_printf(&msg, "'"); |
| 2284 | } |
| 2285 | |
| 2286 | chunk_printf(&msg, "\""); |
| 2287 | |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | chunk_printf(&msg, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2291 | ">%s<a name=\"%s/Backend\"></a>" |
| 2292 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>%s</td>" |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2293 | /* queue : current, max */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2294 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 2295 | /* sessions rate : current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2296 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 2297 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2298 | (uri->flags & ST_SHLGNDS)?"<u>":"", |
Krzysztof Piotr Oledzki | 1f67285 | 2009-10-24 14:24:30 +0200 | [diff] [blame] | 2299 | px->id, px->id, |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2300 | (uri->flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 2301 | U2H0(px->nbpend) /* or px->totpend ? */, U2H1(px->counters.nbpend_max), |
| 2302 | U2H2(read_freq_ctr(&px->be_sess_per_sec)), U2H3(px->counters.be_sps_max)); |
Willy Tarreau | a3e4942 | 2009-05-10 19:19:41 +0200 | [diff] [blame] | 2303 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2304 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2305 | /* sessions: current, max, limit */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2306 | "<td>%s</td><td>%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2307 | "<td" |
| 2308 | "", |
| 2309 | U2H2(px->beconn), U2H3(px->counters.beconn_max), U2H4(px->fullconn)); |
| 2310 | |
| 2311 | /* http response (via td title): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2312 | if (px->mode == PR_MODE_HTTP) { |
| 2313 | int i; |
| 2314 | |
| 2315 | chunk_printf(&msg, " title=\"rsp codes:"); |
| 2316 | |
| 2317 | for (i = 1; i < 6; i++) |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 2318 | chunk_printf(&msg, " %dxx=%lld", i, px->counters.be.http.rsp[i]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2319 | |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 2320 | chunk_printf(&msg, " other=%lld\"", px->counters.be.http.rsp[0]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | chunk_printf(&msg, |
| 2324 | /* sessions: total, lbtot */ |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2325 | ">%s%s%s</td><td>%s</td>" |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2326 | /* bytes: in, out */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2327 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2328 | "", |
Willy Tarreau | e045409 | 2010-02-26 12:29:07 +0100 | [diff] [blame] | 2329 | (px->mode == PR_MODE_HTTP)?"<u>":"", |
| 2330 | U2H6(px->counters.cum_beconn), |
| 2331 | (px->mode == PR_MODE_HTTP)?"</u>":"", |
| 2332 | U2H7(px->counters.cum_lbconn), |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2333 | U2H8(px->counters.bytes_in), U2H9(px->counters.bytes_out)); |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2334 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2335 | chunk_printf(&msg, |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2336 | /* denied: req, resp */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2337 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2338 | /* errors : request, connect */ |
| 2339 | "<td></td><td>%s</td>" |
| 2340 | /* errors : response */ |
Willy Tarreau | 6a8573e | 2010-03-05 18:15:23 +0100 | [diff] [blame] | 2341 | "<td title=\"Connection resets during transfers: %lld client, %lld server\"><u>%s</u></td>" |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 2342 | /* warnings: retries, redispatches */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2343 | "<td>%lld</td><td>%lld</td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2344 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2345 | * 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] | 2346 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2347 | * active and backups. */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2348 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 2349 | "<td class=ac>%d</td><td class=ac>%d</td>" |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 2350 | "", |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2351 | U2H0(px->counters.denied_req), U2H1(px->counters.denied_resp), |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2352 | U2H2(px->counters.failed_conns), |
Willy Tarreau | 6a8573e | 2010-03-05 18:15:23 +0100 | [diff] [blame] | 2353 | px->counters.cli_aborts, |
| 2354 | px->counters.srv_aborts, |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2355 | U2H5(px->counters.failed_resp), |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2356 | px->counters.retries, px->counters.redispatches, |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2357 | human_time(now.tv_sec - px->last_change, 1), |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 2358 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 2359 | "<font color=\"red\"><b>DOWN</b></font>", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 2360 | (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] | 2361 | px->srv_act, px->srv_bck); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2362 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2363 | chunk_printf(&msg, |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2364 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
Krzysztof Piotr Oledzki | f2d2b1d | 2009-10-12 23:09:08 +0200 | [diff] [blame] | 2365 | "<td class=ac> </td><td>%d</td>" |
| 2366 | "<td>%s</td>" |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2367 | "<td></td>" |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2368 | "</tr>", |
| 2369 | px->down_trans, |
| 2370 | px->srv?human_time(be_downtime(px), 1):" "); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2371 | } else { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2372 | chunk_printf(&msg, |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2373 | /* pxid, name */ |
| 2374 | "%s,BACKEND," |
| 2375 | /* queue : current, max */ |
| 2376 | "%d,%d," |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 2377 | /* sessions : current, max, limit, total */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2378 | "%d,%d,%d,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2379 | /* bytes : in, out */ |
| 2380 | "%lld,%lld," |
| 2381 | /* denied: req, resp */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2382 | "%lld,%lld," |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2383 | /* errors : request, connect, response */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2384 | ",%lld,%lld," |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 2385 | /* warnings: retries, redispatches */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2386 | "%lld,%lld," |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 2387 | /* backend status: reflect backend status (up/down): we display UP |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2388 | * 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] | 2389 | * all (eg: for stats). Then we display the total weight, number of |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2390 | * active and backups. */ |
| 2391 | "%s," |
| 2392 | "%d,%d,%d," |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 2393 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 2394 | ",%d,%d,%d,," |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 2395 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
Willy Tarreau | 3b88d44 | 2009-04-11 20:44:08 +0200 | [diff] [blame] | 2396 | "%d,%d,0,,%lld,,%d," |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 2397 | /* rate, rate_lim, rate_max, */ |
| 2398 | "%u,,%u," |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 2399 | /* check_status, check_code, check_duration */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2400 | ",,,", |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2401 | px->id, |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 2402 | px->nbpend /* or px->totpend ? */, px->counters.nbpend_max, |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2403 | px->beconn, px->counters.beconn_max, px->fullconn, px->counters.cum_beconn, |
| 2404 | px->counters.bytes_in, px->counters.bytes_out, |
| 2405 | px->counters.denied_req, px->counters.denied_resp, |
| 2406 | px->counters.failed_conns, px->counters.failed_resp, |
| 2407 | px->counters.retries, px->counters.redispatches, |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 2408 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 2409 | (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] | 2410 | px->srv_act, px->srv_bck, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 2411 | px->down_trans, (int)(now.tv_sec - px->last_change), |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 2412 | px->srv?be_downtime(px):0, |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 2413 | relative_pid, px->uuid, |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 2414 | px->counters.cum_lbconn, STATS_TYPE_BE, |
Willy Tarreau | 8f208ec | 2009-05-10 19:01:49 +0200 | [diff] [blame] | 2415 | read_freq_ctr(&px->be_sess_per_sec), |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 2416 | px->counters.be_sps_max); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2417 | |
| 2418 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2419 | if (px->mode == PR_MODE_HTTP) { |
| 2420 | int i; |
| 2421 | |
| 2422 | for (i=1; i<6; i++) |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 2423 | chunk_printf(&msg, "%lld,", px->counters.be.http.rsp[i]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2424 | |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 2425 | chunk_printf(&msg, "%lld,", px->counters.be.http.rsp[0]); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2426 | } else { |
| 2427 | chunk_printf(&msg, ",,,,,,"); |
| 2428 | } |
| 2429 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 2430 | /* failed health analyses */ |
| 2431 | chunk_printf(&msg, ","); |
| 2432 | |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 2433 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 2434 | chunk_printf(&msg, ",,,"); |
| 2435 | |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 2436 | /* errors: cli_aborts, srv_aborts */ |
| 2437 | chunk_printf(&msg, "%lld,%lld,", |
| 2438 | px->counters.cli_aborts, px->counters.srv_aborts); |
| 2439 | |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 2440 | /* finish with EOL */ |
| 2441 | chunk_printf(&msg, "\n"); |
| 2442 | |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2443 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2444 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2445 | return 0; |
| 2446 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 2447 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2448 | s->data_ctx.stats.px_st = DATA_ST_PX_END; |
| 2449 | /* fall through */ |
| 2450 | |
| 2451 | case DATA_ST_PX_END: |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 2452 | if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) { |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2453 | chunk_printf(&msg, "</table><p>\n"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2454 | |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 2455 | if (buffer_feed_chunk(rep, &msg) >= 0) |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 2456 | return 0; |
| 2457 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 2458 | |
| 2459 | s->data_ctx.stats.px_st = DATA_ST_PX_FIN; |
| 2460 | /* fall through */ |
| 2461 | |
| 2462 | case DATA_ST_PX_FIN: |
| 2463 | return 1; |
| 2464 | |
| 2465 | default: |
| 2466 | /* unknown state, we should put an abort() here ! */ |
| 2467 | return 1; |
| 2468 | } |
| 2469 | } |
| 2470 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2471 | /* This function is called to send output to the response buffer. It dumps a |
| 2472 | * complete session state onto the output buffer <rep>. The session has to be |
| 2473 | * set in data_ctx.sess.target. It returns 0 if the output buffer is full and |
| 2474 | * it needs to be called again, otherwise non-zero. It is designed to be called |
| 2475 | * from stats_dump_sess_to_buffer() below. |
| 2476 | */ |
| 2477 | |
| 2478 | /* returns 1 if dump is not complete */ |
| 2479 | int stats_dump_full_sess_to_buffer(struct session *s, struct buffer *rep) |
| 2480 | { |
| 2481 | struct tm tm; |
| 2482 | struct chunk msg; |
| 2483 | struct session *sess; |
| 2484 | extern const char *monthname[12]; |
| 2485 | char pn[INET6_ADDRSTRLEN]; |
| 2486 | |
| 2487 | chunk_init(&msg, trash, sizeof(trash)); |
| 2488 | sess = s->data_ctx.sess.target; |
| 2489 | |
| 2490 | if (s->data_ctx.sess.section > 0 && s->data_ctx.sess.uid != sess->uniq_id) { |
| 2491 | /* session changed, no need to go any further */ |
| 2492 | chunk_printf(&msg, " *** session terminated while we were watching it ***\n"); |
| 2493 | if (buffer_feed_chunk(rep, &msg) >= 0) |
| 2494 | return 0; |
| 2495 | s->data_ctx.sess.target = NULL; |
| 2496 | s->data_ctx.sess.uid = 0; |
| 2497 | return 1; |
| 2498 | } |
| 2499 | |
| 2500 | switch (s->data_ctx.sess.section) { |
| 2501 | case 0: /* main status of the session */ |
| 2502 | s->data_ctx.sess.uid = sess->uniq_id; |
| 2503 | s->data_ctx.sess.section = 1; |
| 2504 | /* fall through */ |
| 2505 | |
| 2506 | case 1: |
| 2507 | chunk_printf(&msg, |
| 2508 | "%p: id=%u, proto=%s", |
| 2509 | sess, |
| 2510 | sess->uniq_id, |
| 2511 | sess->listener->proto->name); |
| 2512 | |
| 2513 | switch (sess->listener->proto->sock_family) { |
| 2514 | case AF_INET: |
| 2515 | inet_ntop(AF_INET, |
| 2516 | (const void *)&((struct sockaddr_in *)&sess->cli_addr)->sin_addr, |
| 2517 | pn, sizeof(pn)); |
| 2518 | |
| 2519 | chunk_printf(&msg, |
| 2520 | " source=%s:%d\n", |
| 2521 | pn, |
| 2522 | ntohs(((struct sockaddr_in *)&sess->cli_addr)->sin_port)); |
| 2523 | break; |
| 2524 | case AF_INET6: |
| 2525 | inet_ntop(AF_INET6, |
| 2526 | (const void *)&((struct sockaddr_in6 *)(&sess->cli_addr))->sin6_addr, |
| 2527 | pn, sizeof(pn)); |
| 2528 | |
| 2529 | chunk_printf(&msg, |
| 2530 | " source=%s:%d\n", |
| 2531 | pn, |
| 2532 | ntohs(((struct sockaddr_in6 *)&sess->cli_addr)->sin6_port)); |
| 2533 | break; |
| 2534 | case AF_UNIX: |
| 2535 | default: |
| 2536 | /* no more information to print right now */ |
| 2537 | chunk_printf(&msg, "\n"); |
| 2538 | break; |
| 2539 | } |
| 2540 | |
| 2541 | chunk_printf(&msg, |
| 2542 | " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n", |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame^] | 2543 | sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2544 | |
| 2545 | chunk_printf(&msg, |
| 2546 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)\n", |
| 2547 | sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp", |
| 2548 | sess->listener ? sess->listener->name ? sess->listener->name : "?" : "?", |
| 2549 | sess->listener ? sess->listener->luid : 0); |
| 2550 | |
| 2551 | chunk_printf(&msg, |
| 2552 | " backend=%s (id=%u mode=%s) server=%s (id=%u)\n", |
| 2553 | sess->be->id, sess->be->uuid, sess->be->mode ? "http" : "tcp", |
| 2554 | sess->srv ? sess->srv->id : "<none>", |
| 2555 | sess->srv ? sess->srv->puid : 0); |
| 2556 | |
| 2557 | chunk_printf(&msg, |
| 2558 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s)\n", |
| 2559 | sess->task, |
| 2560 | sess->task->state, |
| 2561 | sess->task->nice, sess->task->calls, |
| 2562 | sess->task->expire ? |
| 2563 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 2564 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 2565 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 2566 | task_in_rq(sess->task) ? ", running" : ""); |
| 2567 | |
| 2568 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
| 2569 | chunk_printf(&msg, |
| 2570 | " task created [%02d/%s/%04d:%02d:%02d:%02d.%06d] (age=%s)\n", |
| 2571 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 2572 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec), |
| 2573 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 2574 | |
| 2575 | chunk_printf(&msg, |
| 2576 | " si[0]=%p (state=%d flags=0x%02x fd=%d exp=%s, et=0x%03x)\n", |
| 2577 | &sess->si[0], |
| 2578 | sess->si[0].state, |
| 2579 | sess->si[0].flags, |
| 2580 | sess->si[0].fd, |
| 2581 | sess->si[0].exp ? |
| 2582 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 2583 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 2584 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 2585 | sess->si[0].err_type); |
| 2586 | |
| 2587 | chunk_printf(&msg, |
| 2588 | " si[1]=%p (state=%d flags=0x%02x fd=%d exp=%s, et=0x%03x)\n", |
| 2589 | &sess->si[1], |
| 2590 | sess->si[1].state, |
| 2591 | sess->si[1].flags, |
| 2592 | sess->si[1].fd, |
| 2593 | sess->si[1].exp ? |
| 2594 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 2595 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 2596 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 2597 | sess->si[1].err_type); |
| 2598 | |
| 2599 | chunk_printf(&msg, |
| 2600 | " txn=%p (flags=0x%x meth=%d status=%d req.st=%d rsp.st=%d)\n", |
| 2601 | &sess->txn, sess->txn.flags, sess->txn.meth, sess->txn.status, |
| 2602 | sess->txn.req.msg_state, sess->txn.rsp.msg_state); |
| 2603 | |
| 2604 | |
| 2605 | chunk_printf(&msg, |
| 2606 | " req=%p (f=0x%06x an=0x%x l=%d sndmx=%d pipe=%d fwd=%ld)\n" |
| 2607 | " an_exp=%s", |
| 2608 | sess->req, |
| 2609 | sess->req->flags, sess->req->analysers, |
| 2610 | sess->req->l, sess->req->send_max, |
| 2611 | sess->req->pipe ? sess->req->pipe->data : 0, |
| 2612 | sess->req->to_forward, |
| 2613 | sess->req->analyse_exp ? |
| 2614 | human_time(TICKS_TO_MS(sess->req->analyse_exp - now_ms), |
| 2615 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 2616 | |
| 2617 | chunk_printf(&msg, |
| 2618 | " rex=%s", |
| 2619 | sess->req->rex ? |
| 2620 | human_time(TICKS_TO_MS(sess->req->rex - now_ms), |
| 2621 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 2622 | |
| 2623 | chunk_printf(&msg, |
| 2624 | " wex=%s\n" |
| 2625 | " data=%p r=%d w=%d lr=%d total=%lld\n", |
| 2626 | sess->req->wex ? |
| 2627 | human_time(TICKS_TO_MS(sess->req->wex - now_ms), |
| 2628 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 2629 | sess->req->data, |
Willy Tarreau | 4e1554c | 2010-03-21 23:21:00 +0100 | [diff] [blame] | 2630 | (int)(sess->req->r - sess->req->data), |
| 2631 | (int)(sess->req->w - sess->req->data), |
| 2632 | (int)(sess->req->lr - sess->req->data), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2633 | sess->req->total); |
| 2634 | |
| 2635 | chunk_printf(&msg, |
| 2636 | " res=%p (f=0x%06x an=0x%x l=%d sndmx=%d pipe=%d fwd=%ld)\n" |
| 2637 | " an_exp=%s", |
| 2638 | sess->rep, |
| 2639 | sess->rep->flags, sess->rep->analysers, |
| 2640 | sess->rep->l, sess->rep->send_max, |
| 2641 | sess->rep->pipe ? sess->rep->pipe->data : 0, |
| 2642 | sess->rep->to_forward, |
| 2643 | sess->rep->analyse_exp ? |
| 2644 | human_time(TICKS_TO_MS(sess->rep->analyse_exp - now_ms), |
| 2645 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 2646 | |
| 2647 | chunk_printf(&msg, |
| 2648 | " rex=%s", |
| 2649 | sess->rep->rex ? |
| 2650 | human_time(TICKS_TO_MS(sess->rep->rex - now_ms), |
| 2651 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 2652 | |
| 2653 | chunk_printf(&msg, |
| 2654 | " wex=%s\n" |
| 2655 | " data=%p r=%d w=%d lr=%d total=%lld\n", |
| 2656 | sess->rep->wex ? |
| 2657 | human_time(TICKS_TO_MS(sess->rep->wex - now_ms), |
| 2658 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 2659 | sess->rep->data, |
Willy Tarreau | 4e1554c | 2010-03-21 23:21:00 +0100 | [diff] [blame] | 2660 | (int)(sess->rep->r - sess->rep->data), |
| 2661 | (int)(sess->rep->w - sess->rep->data), |
| 2662 | (int)(sess->rep->lr - sess->rep->data), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2663 | sess->rep->total); |
| 2664 | |
| 2665 | if (buffer_feed_chunk(rep, &msg) >= 0) |
| 2666 | return 0; |
| 2667 | |
| 2668 | /* use other states to dump the contents */ |
| 2669 | } |
| 2670 | /* end of dump */ |
| 2671 | s->data_ctx.sess.uid = 0; |
| 2672 | return 1; |
| 2673 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2674 | |
| 2675 | /* This function is called to send output to the response buffer. |
| 2676 | * It dumps the sessions states onto the output buffer <rep>. |
| 2677 | * Expects to be called with client socket shut down on input. |
| 2678 | * s->data_ctx must have been zeroed first, and the flags properly set. |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 2679 | * It returns 0 as long as it does not complete, non-zero upon completion. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2680 | */ |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 2681 | int stats_dump_sess_to_buffer(struct session *s, struct buffer *rep) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2682 | { |
| 2683 | struct chunk msg; |
| 2684 | |
| 2685 | if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) { |
| 2686 | /* If we're forced to shut down, we might have to remove our |
| 2687 | * reference to the last session being dumped. |
| 2688 | */ |
| 2689 | if (s->data_state == DATA_ST_LIST) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 2690 | if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2691 | LIST_DEL(&s->data_ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 2692 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 2693 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2694 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 2695 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2696 | } |
| 2697 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2698 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2699 | |
| 2700 | switch (s->data_state) { |
| 2701 | case DATA_ST_INIT: |
| 2702 | /* the function had not been called yet, let's prepare the |
| 2703 | * buffer for a response. We initialize the current session |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 2704 | * pointer to the first in the global list. When a target |
| 2705 | * session is being destroyed, it is responsible for updating |
| 2706 | * this pointer. We know we have reached the end when this |
| 2707 | * pointer points back to the head of the sessions list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2708 | */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2709 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 2710 | s->data_ctx.sess.bref.ref = sessions.n; |
| 2711 | s->data_state = DATA_ST_LIST; |
| 2712 | /* fall through */ |
| 2713 | |
| 2714 | case DATA_ST_LIST: |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 2715 | /* first, let's detach the back-ref from a possible previous session */ |
| 2716 | if (!LIST_ISEMPTY(&s->data_ctx.sess.bref.users)) { |
| 2717 | LIST_DEL(&s->data_ctx.sess.bref.users); |
| 2718 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 2719 | } |
| 2720 | |
| 2721 | /* and start from where we stopped */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2722 | while (s->data_ctx.sess.bref.ref != &sessions) { |
| 2723 | char pn[INET6_ADDRSTRLEN + strlen(":65535")]; |
| 2724 | struct session *curr_sess; |
| 2725 | |
| 2726 | curr_sess = LIST_ELEM(s->data_ctx.sess.bref.ref, struct session *, list); |
| 2727 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2728 | if (s->data_ctx.sess.target) { |
| 2729 | if (s->data_ctx.sess.target != curr_sess) |
| 2730 | goto next_sess; |
| 2731 | |
| 2732 | LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users); |
| 2733 | /* call the proper dump() function and return if we're missing space */ |
| 2734 | if (!stats_dump_full_sess_to_buffer(s, rep)) |
| 2735 | return 0; |
| 2736 | |
| 2737 | /* session dump complete */ |
| 2738 | LIST_DEL(&s->data_ctx.sess.bref.users); |
| 2739 | LIST_INIT(&s->data_ctx.sess.bref.users); |
| 2740 | s->data_ctx.sess.target = NULL; |
| 2741 | break; |
| 2742 | } |
| 2743 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2744 | chunk_printf(&msg, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2745 | "%p: proto=%s", |
| 2746 | curr_sess, |
| 2747 | curr_sess->listener->proto->name); |
| 2748 | |
| 2749 | switch (curr_sess->listener->proto->sock_family) { |
| 2750 | case AF_INET: |
| 2751 | inet_ntop(AF_INET, |
| 2752 | (const void *)&((struct sockaddr_in *)&curr_sess->cli_addr)->sin_addr, |
| 2753 | pn, sizeof(pn)); |
| 2754 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2755 | chunk_printf(&msg, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2756 | " src=%s:%d fe=%s be=%s srv=%s", |
| 2757 | pn, |
| 2758 | ntohs(((struct sockaddr_in *)&curr_sess->cli_addr)->sin_port), |
| 2759 | curr_sess->fe->id, |
| 2760 | curr_sess->be->id, |
| 2761 | curr_sess->srv ? curr_sess->srv->id : "<none>" |
| 2762 | ); |
| 2763 | break; |
| 2764 | case AF_INET6: |
| 2765 | inet_ntop(AF_INET6, |
| 2766 | (const void *)&((struct sockaddr_in6 *)(&curr_sess->cli_addr))->sin6_addr, |
| 2767 | pn, sizeof(pn)); |
| 2768 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2769 | chunk_printf(&msg, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2770 | " src=%s:%d fe=%s be=%s srv=%s", |
| 2771 | pn, |
| 2772 | ntohs(((struct sockaddr_in6 *)&curr_sess->cli_addr)->sin6_port), |
| 2773 | curr_sess->fe->id, |
| 2774 | curr_sess->be->id, |
| 2775 | curr_sess->srv ? curr_sess->srv->id : "<none>" |
| 2776 | ); |
| 2777 | |
| 2778 | break; |
| 2779 | case AF_UNIX: |
| 2780 | /* no more information to print right now */ |
| 2781 | break; |
| 2782 | } |
| 2783 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2784 | chunk_printf(&msg, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 2785 | " ts=%02x age=%s calls=%d", |
| 2786 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 2787 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 2788 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2789 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2790 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 2791 | " rq[f=%06xh,l=%d,an=%02xh,rx=%s", |
| 2792 | curr_sess->req->flags, |
| 2793 | curr_sess->req->l, |
| 2794 | curr_sess->req->analysers, |
| 2795 | curr_sess->req->rex ? |
| 2796 | human_time(TICKS_TO_MS(curr_sess->req->rex - now_ms), |
| 2797 | TICKS_TO_MS(1000)) : ""); |
| 2798 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2799 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 2800 | ",wx=%s", |
| 2801 | curr_sess->req->wex ? |
| 2802 | human_time(TICKS_TO_MS(curr_sess->req->wex - now_ms), |
| 2803 | TICKS_TO_MS(1000)) : ""); |
| 2804 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2805 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 2806 | ",ax=%s]", |
| 2807 | curr_sess->req->analyse_exp ? |
| 2808 | human_time(TICKS_TO_MS(curr_sess->req->analyse_exp - now_ms), |
| 2809 | TICKS_TO_MS(1000)) : ""); |
| 2810 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2811 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 2812 | " rp[f=%06xh,l=%d,an=%02xh,rx=%s", |
| 2813 | curr_sess->rep->flags, |
| 2814 | curr_sess->rep->l, |
| 2815 | curr_sess->rep->analysers, |
| 2816 | curr_sess->rep->rex ? |
| 2817 | human_time(TICKS_TO_MS(curr_sess->rep->rex - now_ms), |
| 2818 | TICKS_TO_MS(1000)) : ""); |
| 2819 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2820 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 2821 | ",wx=%s", |
| 2822 | curr_sess->rep->wex ? |
| 2823 | human_time(TICKS_TO_MS(curr_sess->rep->wex - now_ms), |
| 2824 | TICKS_TO_MS(1000)) : ""); |
| 2825 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2826 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 2827 | ",ax=%s]", |
| 2828 | curr_sess->rep->analyse_exp ? |
| 2829 | human_time(TICKS_TO_MS(curr_sess->rep->analyse_exp - now_ms), |
| 2830 | TICKS_TO_MS(1000)) : ""); |
| 2831 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2832 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 2833 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 2834 | curr_sess->si[0].state, |
| 2835 | curr_sess->si[0].flags, |
| 2836 | curr_sess->si[0].fd, |
| 2837 | curr_sess->si[0].exp ? |
| 2838 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 2839 | TICKS_TO_MS(1000)) : ""); |
| 2840 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2841 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 2842 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 2843 | curr_sess->si[1].state, |
| 2844 | curr_sess->si[1].flags, |
| 2845 | curr_sess->si[1].fd, |
| 2846 | curr_sess->si[1].exp ? |
| 2847 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 2848 | TICKS_TO_MS(1000)) : ""); |
| 2849 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2850 | chunk_printf(&msg, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 2851 | " exp=%s", |
| 2852 | curr_sess->task->expire ? |
| 2853 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 2854 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 2855 | if (task_in_rq(curr_sess->task)) |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2856 | chunk_printf(&msg, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 2857 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2858 | chunk_printf(&msg, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2859 | |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 2860 | if (buffer_feed_chunk(rep, &msg) >= 0) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 2861 | /* let's try again later from this session. We add ourselves into |
| 2862 | * this session's users so that it can remove us upon termination. |
| 2863 | */ |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2864 | LIST_ADDQ(&curr_sess->back_refs, &s->data_ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 2865 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2866 | } |
| 2867 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2868 | next_sess: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2869 | s->data_ctx.sess.bref.ref = curr_sess->list.n; |
| 2870 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 2871 | |
| 2872 | if (s->data_ctx.sess.target) { |
| 2873 | /* specified session not found */ |
| 2874 | if (s->data_ctx.sess.section > 0) |
| 2875 | chunk_printf(&msg, " *** session terminated while we were watching it ***\n"); |
| 2876 | else |
| 2877 | chunk_printf(&msg, "Session not found.\n"); |
| 2878 | |
| 2879 | if (buffer_feed_chunk(rep, &msg) >= 0) |
| 2880 | return 0; |
| 2881 | |
| 2882 | s->data_ctx.sess.target = NULL; |
| 2883 | s->data_ctx.sess.uid = 0; |
| 2884 | return 1; |
| 2885 | } |
| 2886 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2887 | s->data_state = DATA_ST_FIN; |
| 2888 | /* fall through */ |
| 2889 | |
| 2890 | default: |
| 2891 | s->data_state = DATA_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 2892 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 2893 | } |
| 2894 | } |
| 2895 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 2896 | /* print a line of text buffer (limited to 70 bytes) to <out>. The format is : |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2897 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 2898 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 2899 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 2900 | * lines are respected within the limit of 70 output chars. Lines that are |
| 2901 | * continuation of a previous truncated line begin with "+" instead of " " |
| 2902 | * after the offset. The new pointer is returned. |
| 2903 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 2904 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 2905 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2906 | { |
| 2907 | int end; |
| 2908 | unsigned char c; |
| 2909 | |
| 2910 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2911 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2912 | return ptr; |
| 2913 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2914 | chunk_printf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2915 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 2916 | while (ptr < len && ptr < bsize) { |
| 2917 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 2918 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2919 | if (out->len > end - 2) |
| 2920 | break; |
| 2921 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 2922 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2923 | if (out->len > end - 3) |
| 2924 | break; |
| 2925 | out->str[out->len++] = '\\'; |
| 2926 | switch (c) { |
| 2927 | case '\t': c = 't'; break; |
| 2928 | case '\n': c = 'n'; break; |
| 2929 | case '\r': c = 'r'; break; |
| 2930 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 2931 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2932 | } |
| 2933 | out->str[out->len++] = c; |
| 2934 | } else { |
| 2935 | if (out->len > end - 5) |
| 2936 | break; |
| 2937 | out->str[out->len++] = '\\'; |
| 2938 | out->str[out->len++] = 'x'; |
| 2939 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 2940 | out->str[out->len++] = hextab[c & 0xF]; |
| 2941 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 2942 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2943 | /* we had a line break, let's return now */ |
| 2944 | out->str[out->len++] = '\n'; |
| 2945 | *line = ptr; |
| 2946 | return ptr; |
| 2947 | } |
| 2948 | } |
| 2949 | /* we have an incomplete line, we return it as-is */ |
| 2950 | out->str[out->len++] = '\n'; |
| 2951 | return ptr; |
| 2952 | } |
| 2953 | |
| 2954 | /* This function is called to send output to the response buffer. |
| 2955 | * It dumps the errors logged in proxies onto the output buffer <rep>. |
| 2956 | * Expects to be called with client socket shut down on input. |
| 2957 | * s->data_ctx must have been zeroed first, and the flags properly set. |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 2958 | * It returns 0 as long as it does not complete, non-zero upon completion. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2959 | */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 2960 | int stats_dump_errors_to_buffer(struct session *s, struct buffer *rep) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2961 | { |
| 2962 | extern const char *monthname[12]; |
| 2963 | struct chunk msg; |
| 2964 | |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 2965 | if (unlikely(rep->flags & (BF_WRITE_ERROR|BF_SHUTW))) |
| 2966 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2967 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 2968 | chunk_init(&msg, trash, sizeof(trash)); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2969 | |
| 2970 | if (!s->data_ctx.errors.px) { |
| 2971 | /* the function had not been called yet, let's prepare the |
| 2972 | * buffer for a response. |
| 2973 | */ |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 2974 | s->data_ctx.errors.px = proxy; |
| 2975 | s->data_ctx.errors.buf = 0; |
| 2976 | s->data_ctx.errors.bol = 0; |
| 2977 | s->data_ctx.errors.ptr = -1; |
| 2978 | } |
| 2979 | |
| 2980 | /* we have two inner loops here, one for the proxy, the other one for |
| 2981 | * the buffer. |
| 2982 | */ |
| 2983 | while (s->data_ctx.errors.px) { |
| 2984 | struct error_snapshot *es; |
| 2985 | |
| 2986 | if (s->data_ctx.errors.buf == 0) |
| 2987 | es = &s->data_ctx.errors.px->invalid_req; |
| 2988 | else |
| 2989 | es = &s->data_ctx.errors.px->invalid_rep; |
| 2990 | |
| 2991 | if (!es->when.tv_sec) |
| 2992 | goto next; |
| 2993 | |
| 2994 | if (s->data_ctx.errors.iid >= 0 && |
| 2995 | s->data_ctx.errors.px->uuid != s->data_ctx.errors.iid && |
| 2996 | es->oe->uuid != s->data_ctx.errors.iid) |
| 2997 | goto next; |
| 2998 | |
| 2999 | if (s->data_ctx.errors.ptr < 0) { |
| 3000 | /* just print headers now */ |
| 3001 | |
| 3002 | char pn[INET6_ADDRSTRLEN]; |
| 3003 | struct tm tm; |
| 3004 | |
| 3005 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 8811f8e | 2010-03-05 17:42:58 +0100 | [diff] [blame] | 3006 | chunk_printf(&msg, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3007 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 3008 | 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] | 3009 | |
| 3010 | |
| 3011 | if (es->src.ss_family == AF_INET) |
| 3012 | inet_ntop(AF_INET, |
| 3013 | (const void *)&((struct sockaddr_in *)&es->src)->sin_addr, |
| 3014 | pn, sizeof(pn)); |
| 3015 | else |
| 3016 | inet_ntop(AF_INET6, |
| 3017 | (const void *)&((struct sockaddr_in6 *)(&es->src))->sin6_addr, |
| 3018 | pn, sizeof(pn)); |
| 3019 | |
| 3020 | switch (s->data_ctx.errors.buf) { |
| 3021 | case 0: |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3022 | chunk_printf(&msg, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3023 | " frontend %s (#%d): invalid request\n" |
| 3024 | " src %s, session #%d, backend %s (#%d), server %s (#%d)\n" |
Willy Tarreau | 8811f8e | 2010-03-05 17:42:58 +0100 | [diff] [blame] | 3025 | " request length %d bytes, error at position %d:\n \n", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3026 | s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid, |
Willy Tarreau | 3fd6cec | 2010-03-25 06:45:07 +0100 | [diff] [blame] | 3027 | pn, es->sid, (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 3028 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3029 | es->srv ? es->srv->id : "<NONE>", |
| 3030 | es->srv ? es->srv->puid : -1, |
| 3031 | es->len, es->pos); |
| 3032 | break; |
| 3033 | case 1: |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3034 | chunk_printf(&msg, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3035 | " backend %s (#%d) : invalid response\n" |
| 3036 | " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n" |
Willy Tarreau | 8811f8e | 2010-03-05 17:42:58 +0100 | [diff] [blame] | 3037 | " response length %d bytes, error at position %d:\n \n", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3038 | s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid, |
| 3039 | pn, es->sid, es->oe->id, es->oe->uuid, |
| 3040 | es->srv ? es->srv->id : "<NONE>", |
| 3041 | es->srv ? es->srv->puid : -1, |
| 3042 | es->len, es->pos); |
| 3043 | break; |
| 3044 | } |
| 3045 | |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3046 | if (buffer_feed_chunk(rep, &msg) >= 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3047 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3048 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3049 | } |
| 3050 | s->data_ctx.errors.ptr = 0; |
| 3051 | s->data_ctx.errors.sid = es->sid; |
| 3052 | } |
| 3053 | |
| 3054 | if (s->data_ctx.errors.sid != es->sid) { |
| 3055 | /* the snapshot changed while we were dumping it */ |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 3056 | chunk_printf(&msg, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3057 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3058 | if (buffer_feed_chunk(rep, &msg) >= 0) |
| 3059 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3060 | goto next; |
| 3061 | } |
| 3062 | |
| 3063 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3064 | while (s->data_ctx.errors.ptr < es->len && s->data_ctx.errors.ptr < sizeof(es->buf)) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3065 | int newptr; |
| 3066 | int newline; |
| 3067 | |
| 3068 | newline = s->data_ctx.errors.bol; |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 3069 | newptr = dump_text_line(&msg, es->buf, sizeof(es->buf), es->len, &newline, s->data_ctx.errors.ptr); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3070 | if (newptr == s->data_ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3071 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3072 | |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3073 | if (buffer_feed_chunk(rep, &msg) >= 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3074 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3075 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3076 | } |
| 3077 | s->data_ctx.errors.ptr = newptr; |
| 3078 | s->data_ctx.errors.bol = newline; |
| 3079 | }; |
| 3080 | next: |
| 3081 | s->data_ctx.errors.bol = 0; |
| 3082 | s->data_ctx.errors.ptr = -1; |
| 3083 | s->data_ctx.errors.buf++; |
| 3084 | if (s->data_ctx.errors.buf > 1) { |
| 3085 | s->data_ctx.errors.buf = 0; |
| 3086 | s->data_ctx.errors.px = s->data_ctx.errors.px->next; |
| 3087 | } |
| 3088 | } |
| 3089 | |
| 3090 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 3091 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 3092 | } |
| 3093 | |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 3094 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 3095 | static struct cfg_kw_list cfg_kws = {{ },{ |
| 3096 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 3097 | { 0, NULL, NULL }, |
| 3098 | }}; |
| 3099 | |
| 3100 | __attribute__((constructor)) |
| 3101 | static void __dumpstats_module_init(void) |
| 3102 | { |
| 3103 | cfg_register_keywords(&cfg_kws); |
| 3104 | } |
| 3105 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3106 | /* |
| 3107 | * Local variables: |
| 3108 | * c-indent-level: 8 |
| 3109 | * c-basic-offset: 8 |
| 3110 | * End: |
| 3111 | */ |