Hello Olivier,

On Thu, May 22, 2014 at 04:44:59PM +0200, Olivier Burgard wrote:
> Hello,
> 
> 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)

Wow that's excellent! I've long wanted to do it but felt lazy. So of course
I've applied it! After looking at it a bit, I found that you called time(),
localtime() and mktime() for each line, which is a real waste. So I performed
a small change by having a cache of last converted date and by only initializing
the timeinfo struct once. Result: 8 times faster here on my machine :-)

Thus I merged this change as well.

Thanks!
Willy


Reply via email to