Realtime lines per second in a log file

tail -f /var/log/logfile|perl -e 'while (<>) {$l++;if (time > $e) {$e=time;print "$l\n";$l=0}}'
Using tail to follow and standard perl to count and print the lps when lines are written to the logfile.

5
By: madsen
2011-06-21 10:28:26

7 Alternatives + Submit Alt

What Others Think

This works great! And Iike that it prints out the speed in real time, and keeps the history around. But this gets very inaccurate for low frequency events since it only checks if a second has passed each time it receives a line. It could account for the time difference between when a line was received and when the last second actually elapsed...but that'd probably be more than 255 chars. You can see this easily with a loop that output a line every 2 seconds: while sleep 2; do echo test; done |perl -e 'while (<>) {$l++;if (time > $e) {$e=time;print "$l\n";$l=0}}' 1 1 1 1 1
varenc · 66 weeks and 4 days ago
by replacing the '\r' chars in `pv`'s output, you can get the rate history info this perl one-liner provides, but with accurate rates for low volume events. That alternative is here: https://www.commandlinefu.com/commands/view/24920/realtime-lines-per-second-in-a-log-file-with-history
varenc · 66 weeks and 3 days ago
You shared a useful post and thanks for sharing this to us. WalmartOne is an application designed to be used in mobiles for associates of Walmart. By using this application. Associates and employees can access all information from walmartone login page. https://walmartone.fun
jackdann · 60 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: