From 10479e4bac8349ed45eb27953ff4085d9df5c5c7 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 12 Dec 2010 14:00:34 +0100 Subject: [PATCH] [MINOR] stats: add global event ID and count This counter will help quickly spot whether there are new errors or not. It is also assigned to each capture so that a script can keep trace of which capture was taken when. --- include/types/proxy.h | 2 ++ src/dumpstats.c | 21 +++++++++++++++++---- src/proto_http.c | 1 + src/proxy.c | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/types/proxy.h b/include/types/proxy.h index 89cb09b778..8da98a6c21 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -161,6 +161,7 @@ struct error_snapshot { unsigned int len; /* original length of the last invalid request/response */ unsigned int pos; /* position of the first invalid character */ unsigned int sid; /* ID of the faulty session */ + unsigned int ev_id; /* event number (counter incremented for each capture) */ unsigned int state; /* message state before the error (when saved) */ unsigned int flags; /* buffer flags */ struct server *srv; /* server associated with the error (or NULL) */ @@ -363,6 +364,7 @@ struct redirect_rule { extern struct proxy *proxy; extern struct eb_root used_proxy_id; /* list of proxy IDs in use */ +extern unsigned int error_snapshot_id; /* global ID assigned to each error then incremented */ #endif /* _TYPES_PROXY_H */ diff --git a/src/dumpstats.c b/src/dumpstats.c index da29809702..a45d40a811 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -3426,6 +3426,19 @@ int stats_dump_errors_to_buffer(struct session *s, struct buffer *rep) /* the function had not been called yet, let's prepare the * buffer for a response. */ + struct tm tm; + + get_localtime(date.tv_sec, &tm); + chunk_printf(&msg, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n", + tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, + tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), + error_snapshot_id); + + if (buffer_feed_chunk(rep, &msg) >= 0) { + /* Socket buffer full. Let's try again later from the same point */ + return 0; + } + s->data_ctx.errors.px = proxy; s->data_ctx.errors.buf = 0; s->data_ctx.errors.bol = 0; @@ -3477,27 +3490,27 @@ int stats_dump_errors_to_buffer(struct session *s, struct buffer *rep) chunk_printf(&msg, " frontend %s (#%d): invalid request\n" " src %s, session #%d, backend %s (#%d), server %s (#%d)\n" - " HTTP internal state %d, buffer flags 0x%08x\n" + " HTTP internal state %d, buffer flags 0x%08x, event #%u\n" " request length %d bytes, error at position %d:\n \n", s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid, pn, es->sid, (es->oe->cap & PR_CAP_BE) ? es->oe->id : "", (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1, es->srv ? es->srv->id : "", es->srv ? es->srv->puid : -1, - es->state, es->flags, + es->state, es->flags, es->ev_id, es->len, es->pos); break; case 1: chunk_printf(&msg, " backend %s (#%d) : invalid response\n" " src %s, session #%d, frontend %s (#%d), server %s (#%d)\n" - " HTTP internal state %d, buffer flags 0x%08x\n" + " HTTP internal state %d, buffer flags 0x%08x, event #%u\n" " response length %d bytes, error at position %d:\n \n", s->data_ctx.errors.px->id, s->data_ctx.errors.px->uuid, pn, es->sid, es->oe->id, es->oe->uuid, es->srv ? es->srv->id : "", es->srv ? es->srv->puid : -1, - es->state, es->flags, + es->state, es->flags, es->ev_id, es->len, es->pos); break; } diff --git a/src/proto_http.c b/src/proto_http.c index 8ca39c124d..25421bcf87 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -7278,6 +7278,7 @@ void http_capture_bad_message(struct error_snapshot *es, struct session *s, es->src = s->cli_addr; es->state = state; es->flags = buf->flags; + es->ev_id = error_snapshot_id++; } /* return the IP address pointed to by occurrence of header in diff --git a/src/proxy.c b/src/proxy.c index 2082d0998a..0c6640e9ba 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -43,6 +43,7 @@ int listeners; /* # of proxy listeners, set by cfgparse, unset by maintain_proxies */ struct proxy *proxy = NULL; /* list of all existing proxies */ struct eb_root used_proxy_id = EB_ROOT; /* list of proxy IDs in use */ +unsigned int error_snapshot_id = 0; /* global ID assigned to each error then incremented */ /* * This function returns a string containing a name describing capabilities to -- 2.47.3