Skip to content

Instantly share code, notes, and snippets.

@tedsparc
Created April 10, 2012 15:40
Show Gist options
  • Save tedsparc/2352255 to your computer and use it in GitHub Desktop.
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.
#!/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