]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] stats: add global event ID and count
authorWilly Tarreau <w@1wt.eu>
Sun, 12 Dec 2010 13:00:34 +0000 (14:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 12 Dec 2010 13:00:34 +0000 (14:00 +0100)
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
src/dumpstats.c
src/proto_http.c
src/proxy.c

index 89cb09b77805da20a5a63868975c79630ef6d12f..8da98a6c21b8a3d47990d7deb05b90931733e06c 100644 (file)
@@ -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 */
 
index da29809702907a267361c40dac1c614a7faae6b3..a45d40a8117f5465383c3fb436513498efc6719f 100644 (file)
@@ -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 : "<NONE>",
                                             (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1,
                                             es->srv ? es->srv->id : "<NONE>",
                                             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 : "<NONE>",
                                             es->srv ? es->srv->puid : -1,
-                                            es->state, es->flags,
+                                            es->state, es->flags, es->ev_id,
                                             es->len, es->pos);
                                break;
                        }
index 8ca39c124d34702c4003027a6dc4305e28b79426..25421bcf87dfbccbabd66e4f0b2e328ff7da793d 100644 (file)
@@ -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 <occ> of header <hname> in
index 2082d0998a5a7fb2485add1bc35054f7ff7bac87..0c6640e9ba8eacb3d251e93525338f5893483cb5 100644 (file)
@@ -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