package Requester::vmstat;

@Requester::vmstat::ISA = qw( Requester::CommandWatchRequester );

use Requester::CommandWatchRequester;

my $requester = new Requester::vmstat();

sub new {
    my ($this, $args ) = @_;
    my  $class = ref($this) || $this;
    my  $self = {};

    bless($self, $class);
    $self->set_command( "vmstat %d 2" );
    $self->register( "vmstat" );
    return $self;
}


sub parse {
    my( $self, $lines, $duration ) = @_;

    return undef unless( $lines && ($#$lines >= 3) );
    my @heads = split( /[\s\t]+/, $lines->[1] );
    my @values = split( /[\s\t]+/, $lines->[3] );
    return undef unless( $#heads == $#values );
    my $info0 = {};
    my $info = { "0" => $info0 };
    for( my $i=0; $i<=$#heads; $i++ ) {
        my $head = $heads[$i];
	my $value = $values[$i];
	$info0->{"$head"} = $value;
    }
    $duration = ($duration>0)?$duration:1;
    foreach my $head qw( si so bi bo in cs ) {
        $info0->{"$head"} /= $duration;
    }
    return $info;
}


sub available {
    my( $self ) = @_;

    return( $self->command_available( "vmstat" ) ); 
}

1;

