I am looking for a tool which does something similar to
tail -f /var/log/some.log | grep EVENT1 |rate
which keeps displaying the rate of the event.
tail -f /var/log/some.log | grep --line-buffered EVENT1 | pv -l > /dev/null
pv
is a pipe monitor, which outputs statistics on stderr
; the -l
will measure lines instead of bytes.
You'll need to use --line-buffered
on your grep
call, so that it doesn't buffer larger blocks, or for a general case you can use stdbuf
to adjust your buffering.
Assuming you mean events/second:
while read line; do echo -n "$(grep -c EVENT1 <<<"$line")"; done | pv >/dev/null
This uses pv
, an extremely simple utility. sudo apt-get install pv
on most distrubutions (or yum -i
etc.)
Output, when the input is e.g. (while true; do echo yes; sleep .1; done)
:
218B 0:00:22 [9,88B/s] [ <=> ]
The technique used is to replace each matching line with a single byte in the output (namely '1'
) and just measure output bandwith in bytes-per-second :)