Created
December 10, 2009 21:29
-
-
Save toddlipcon/253696 to your computer and use it in GitHub Desktop.
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; | |
use Data::Dumper; | |
my $GMETRIC = '/usr/bin/gmetric'; | |
my %DISKS = ( | |
'dm-0' => 'root', | |
'dm-1' => 'tmp', | |
'dm-2' => 'var', | |
'dm-3' => 'srv', | |
'dm-4' => 'swap', | |
'dm-5' => 'home', | |
'dm-6' => 'drbd-lv' | |
); | |
my @iostat_blocks = split /\n\n/, `iostat -dx 45 2`; | |
my $important_block = $iostat_blocks[2]; | |
my @iostat = split /\n/, $important_block; | |
my $header_line = shift @iostat; | |
my @header_fields = map { | |
s#/#_per_#g; | |
s#-#_#g; | |
s#%#pct#; | |
$_; | |
} split(/\s+/, $header_line); | |
shift(@header_fields); # Get rid of "Device" header | |
my %stats; | |
foreach (@iostat) { | |
my ($dev, @row_fields) = split /\s+/; | |
@row_fields = map { s/-/_/; $_; } @row_fields; | |
next unless $DISKS{$dev}; | |
my $diskname = $DISKS{$dev}; | |
my %row_data; | |
foreach my $field (@header_fields) { | |
$row_data{$field} = shift @row_fields | |
} | |
$stats{$diskname} = \%row_data; | |
} | |
my %all_stats; | |
foreach my $dev (keys %stats) { | |
foreach my $stat (keys %{$stats{$dev}}) { | |
$all_stats{$dev . "_" . $stat} = $stats{$dev}->{$stat}; | |
} | |
} | |
# print Data::Dumper::Dumper(\%all_stats); | |
## | |
# Output gmetric commands | |
## | |
foreach my $stat (keys %all_stats) { | |
my $val = $all_stats{$stat}; | |
print "$GMETRIC -n iostat_$stat -v $val -t float\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment