#!/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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。