The Test::Parser::Iostat has a data method which provides a hash, no need to parse the XML. This example plots a histogram of util against elapsed time for sda2 from a file created with iostat sda2 -x 1 10 > iostat.txt.
#!/usr/bin/perl
use strict;
use Test::Parser::Iostat;
use GD::Graph::bars;
my $parser = new Test::Parser::Iostat();
open IN,'iostat.txt' or die "$!";
$parser->parse(\*IN) or die $parser->error(), "\n";
my $hash = $parser->data();
# create plot data
my @plot=([],[]);
for my $ar (@{$hash->{'iostat'}{'data'}}){
if ($ar->{'device'} eq 'sda2'){
push @plot[0],$ar->{'elapsed_time'};
push @plot[1],$ar->{'util'};
}
}
# create graph
my $graph = GD::Graph::bars->new(400, 300);
$graph->set(
x_label => 'Elapsed time',
y_label => 'Util',
title => 'sda2 util',
y_max_value => 100,
) or die $graph->error;
my $gd = $graph->plot(\@plot) or die $graph->error;
open(IMG, '>iostat.gif') or die $!;
binmode IMG;
print IMG $gd->gif;
poj
|