Skip to content

Instantly share code, notes, and snippets.

@afeinberg
Created May 20, 2011 00:29
Show Gist options
  • Save afeinberg/982098 to your computer and use it in GitHub Desktop.
Save afeinberg/982098 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
use strict;
use warnings;
use POSIX;
sub main {
if(@ARGV < 3) {
die "Usage: $0 pattern seconds output";
}
my $ph;
open $ph, "iostat -d -x 2 |";
my $filename = $ARGV[2];
my $fh;
open $fh, ">$filename" or die "open(): $!";
my $pattern = quotemeta $ARGV[0];
my $seconds = $ARGV[1];
my $start_time = time();
while(my $line = <$ph>) {
my $current_time = time();
if($line =~ /$pattern/) {
print {$fh} strftime("%d-%m %k:%M:%S", localtime($current_time)) . " $line";
}
if(($current_time - $start_time) > $seconds) {
clean_up($fh, $ph);
exit 0;
}
}
clean_up();
}
sub clean_up {
my @handles = @_;
foreach my $handle(@handles) {
eval {
close $handle;
};
if($@) {
print "close(): $@";
}
}
}
&main;
#!/usr/bin/gnuplot
set terminal png
set output "disk.png"
set title "Disk Activity"
set xdata time
set xlabel "time"
set ylabel "IOPS"
set timefmt "%d-%m %H:%M:%S"
set format x "%H:%M"
plot "iostat.out" using 1:4 title "reads" with lines, \
"iostat.out" using 1:5 title "writes" with lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment