From: Olivier Burgard Date: Thu, 22 May 2014 14:44:59 +0000 (+0200) Subject: CONTRIB: halog: Filter input lines by date and time through timestamp X-Git-Tag: v1.5-dev26~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e97b9048016977feceb2b21f14a6e5cfea34d295;p=thirdparty%2Fhaproxy.git CONTRIB: halog: Filter input lines by date and time through timestamp I wanted to make a graph with average answer time in nagios that takes only the last 5 mn of the log. Filtering the log before using halog was too slow, so I added that filter to halog. The patch attached to this mail is a proposal to add a new option : -time [min][:max] The values are min timestamp and/or max timestamp of the lines to be used for stats. The date and time of the log lines between '[' and ']' are converted to timestamp and compared to these values. Here is an exemple of usage : cat /var/log/haproxy.log | ./halog -srv -H -q -time $(date --date '-5 min' +%s) --- diff --git a/contrib/halog/halog.c b/contrib/halog/halog.c index 95529983a8..364bf90aed 100644 --- a/contrib/halog/halog.c +++ b/contrib/halog/halog.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -116,7 +117,10 @@ struct url_stat { #define FILT_COUNT_COOK_CODES 0x40000000 #define FILT_COUNT_IP_COUNT 0x80000000 +#define FILT2_TIMESTAMP 0x01 + unsigned int filter = 0; +unsigned int filter2 = 0; unsigned int filter_invert = 0; const char *line; int linenum = 0; @@ -144,7 +148,7 @@ void usage(FILE *output, const char *msg) " halog [-q] [-c] [-m ]\n" " {-cc|-gt|-pct|-st|-tc|-srv|-u|-uc|-ue|-ua|-ut|-uao|-uto|-uba|-ubt|-ic}\n" " [-s ] [-e|-E] [-H] [-rt|-RT