您好,登錄后才能下訂單哦!
#!/usr/bin/perl -w use strict; use Regexp::Common; use Getopt::Long; my %values; my $result; my ($iostat,$data,$perfdata); my ($warning,$critical,$disk); $result = GetOptions("disk=s" => \$disk, "d=s" => \$disk, "warning=i" => \$warning, "w=i" => \$warning, "critical=i" => \$critical, "c=i" => \$critical, "help" => \&help, ); $warning ||= 75; $critical ||= 80; $disk ||= undef; &main(); sub main(){ &set_iostat(); &get_data(); if ( $values{'%util'} < $warning ) { print "TEST_IO OK - " . "$data| $perfdata\n"; } elsif ( $values{'%util'} >= $warning ) { print "TEST_IO WARNING - " . "$data| $perfdata\n"; } elsif ( $values{'%util'} >= $critical ) { print "TEST_IO CRITICAL - " . "$data| $perfdata\n"; } else #No clue what value is there! { print "UNKNOWN - Error in command output\n"; } } sub set_iostat(){ if (defined $disk){ $iostat = "iostat " . "$disk"; }else{ $iostat = "iostat"; } } sub get_data(){ &set_iostat(); my $output = `$iostat -d -x 1 3 |tail -n 3`; unless($output) { print "Error executing iostat command\n"; } $output =~ /Device.*?/gs; foreach my $key (qw(rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util)){ if($output =~ /\G.*?($RE{num}{real})/gs){ $data .= sprintf("%s %s ", $key, $1); } } %values = split ' ', $data; $data = ''; foreach my $key(qw(r/s w/s avgqu-sz await svctm %util)){ $data .= sprintf("%s %s ",$key,$values{$key}); #排除(await、svctm、%util)的perfdata輸出 # if( $key eq 'r/s'|| $key eq 'w/s'|| $key eq 'avgqu-sz'){ $perfdata .= $key . "=" . $values{$key} . " "; # } } } sub help{ print "Usage: -d|--disk=</path/to/iostat> -w|--warning=<warn> -c|--critical=<crit>\n"; }
#perl check_diskio.pl -d /dev/sda -w 75 -c 80
TEST_IO OK - r/s 0.00 w/s 3.00 avgqu-sz 0.01 await 3.00 svctm 1.00 %util 0.30 | r/s=0.00 w/s=3.00 avgqu-sz=0.01 await=3.00 svctm=1.00 %util=0.30
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。