Created
April 10, 2012 15:40
-
-
Save tedsparc/2352255 to your computer and use it in GitHub Desktop.
tailrate -- read STDIN, showing how many lines per X seconds; good for tailing an Apache access log, etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
# tailrate -- read STDIN, showing how many lines per X seconds | |
# Example invocation to tail a log file and print lines per second every 5 seconds: | |
# tail -f /var/log/httpd/access_log | perl tailrate.pl 5 | |
my $interval = shift || 1; | |
my $count = 0; | |
my $previous_count = 0; | |
alarm $interval; | |
$SIG{ALRM} = sub { | |
alarm $interval; | |
my $lines_per_sec = ($count - $previous_count) / $interval; | |
print "$lines_per_sec lines per sec\n"; | |
$previous_count = $count; | |
}; | |
while (<>) { | |
$count++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment