From: Willy Tarreau Date: Thu, 28 Oct 2010 18:33:46 +0000 (+0200) Subject: [CONTRIB] halog: report per-url counts, errors and times X-Git-Tag: v1.5-dev8~423 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=abe45b6bb33606c5fde7b671a371d6b253d9900d;p=thirdparty%2Fhaproxy.git [CONTRIB] halog: report per-url counts, errors and times Using -u{,c,e,t,a,to,ao} it is possible to get per-URL statistics, sorted by URL, request count, error count, total time, avg time, total time on OK requests, avg time on OK requests. Since it has to parse URLs and store a number of fields, it's quite slower than other methods, but still correct for production usage (typically 800000 lines or 270 MB per second on a 2 GHz system). Results are sorted in reverse order so that it's easy to catch them by piping the output to the "head" command. (cherry picked from commit 15ce7f56d15f839ce824279b84ffe14c58e41fda) --- diff --git a/contrib/halog/Makefile b/contrib/halog/Makefile index 9a1b79ac29..fa3e6bb610 100644 --- a/contrib/halog/Makefile +++ b/contrib/halog/Makefile @@ -5,10 +5,10 @@ OPTIMIZE = -O3 OBJS = halog halog64 halog: halog.c fgets2.c - $(CC) $(OPTIMIZE) -o $@ $(INCLUDE) $(EBTREE_DIR)/ebtree.c $(EBTREE_DIR)/eb32tree.c $(EBTREE_DIR)/ebmbtree.c $(EBTREE_DIR)/ebsttree.c $^ + $(CC) $(OPTIMIZE) -o $@ $(INCLUDE) $(EBTREE_DIR)/ebtree.c $(EBTREE_DIR)/eb32tree.c $(EBTREE_DIR)/eb64tree.c $(EBTREE_DIR)/ebmbtree.c $(EBTREE_DIR)/ebsttree.c $(EBTREE_DIR)/ebistree.c $(EBTREE_DIR)/ebimtree.c $^ halog64: halog.c fgets2-64.c - $(CC) $(OPTIMIZE) -o $@ $(INCLUDE) $(EBTREE_DIR)/ebtree.c $(EBTREE_DIR)/eb32tree.c $(EBTREE_DIR)/ebmbtree.c $(EBTREE_DIR)/ebsttree.c $^ + $(CC) $(OPTIMIZE) -o $@ $(INCLUDE) $(EBTREE_DIR)/ebtree.c $(EBTREE_DIR)/eb32tree.c $(EBTREE_DIR)/eb64tree.c $(EBTREE_DIR)/ebmbtree.c $(EBTREE_DIR)/ebsttree.c $(EBTREE_DIR)/ebistree.c $(EBTREE_DIR)/ebimtree.c $^ clean: rm -vf $(OBJS) diff --git a/contrib/halog/halog.c b/contrib/halog/halog.c index 016227987c..fa31b2893e 100644 --- a/contrib/halog/halog.c +++ b/contrib/halog/halog.c @@ -20,6 +20,8 @@ #include #include +#include +#include #include #define SOURCE_FIELD 5 @@ -29,6 +31,8 @@ #define STATUS_FIELD 10 #define TERM_CODES_FIELD 14 #define CONN_FIELD 15 +#define METH_FIELD 17 +#define URL_FIELD 18 #define MAXLINE 16384 #define QBITS 4 @@ -53,6 +57,17 @@ struct srv_st { /* don't put anything else here, the server name will be there */ }; +struct url_stat { + union { + struct ebpt_node url; + struct eb64_node val; + } node; + char *url; + unsigned long long total_time; /* sum(all reqs' times) */ + unsigned long long total_time_ok; /* sum(all OK reqs' times) */ + unsigned int nb_err, nb_req; +}; + #define FILT_COUNT_ONLY 0x01 #define FILT_INVERT 0x02 #define FILT_QUIET 0x04 @@ -70,6 +85,16 @@ struct srv_st { #define FILT_COUNT_SRV_STATUS 0x1000 #define FILT_COUNT_TERM_CODES 0x2000 +#define FILT_COUNT_URL_ONLY 0x004000 +#define FILT_COUNT_URL_COUNT 0x008000 +#define FILT_COUNT_URL_ERR 0x010000 +#define FILT_COUNT_URL_TTOT 0x020000 +#define FILT_COUNT_URL_TAVG 0x040000 +#define FILT_COUNT_URL_TTOTO 0x080000 +#define FILT_COUNT_URL_TAVGO 0x100000 +#define FILT_COUNT_URL_ANY (FILT_COUNT_URL_ONLY|FILT_COUNT_URL_COUNT|FILT_COUNT_URL_ERR| \ + FILT_COUNT_URL_TTOT|FILT_COUNT_URL_TAVG|FILT_COUNT_URL_TTOTO|FILT_COUNT_URL_TAVGO) + unsigned int filter = 0; unsigned int filter_invert = 0; const char *line; @@ -80,7 +105,8 @@ void die(const char *msg) { fprintf(stderr, "%s" - "Usage: halog [-q] [-c] [-v] {-gt|-pct|-st|-tc|-srv} [-s ] [-e|-E] [-rt|-RT