rahulruns has asked for the wisdom of the Perl Monks concerning the following question:
I have the iostat -x data which I have parsed and converted into XML using Test::Parser::Iostat. I need the parsed output to create a graph using GD else GD::Graph. I have created a hash with the keys and all the values associated with. But to use a GD::Graph I need to convert this hash to array of arrays to generate a graph. How do I do this else is it possible to utilize this hash to generate a Graph?
The code is #!/usr/bin/perl use strict; use warnings; use File::Slurp; use Data::Dumper; my %graph_point_hash; my @report_graph_point = `sed -e 's/data//g' -e 's/[\<\/\>]//g' -e 's/ +^ *//' -e 's/* \$//' -e '/^\$/d' -e '1d;\$d' $ARGV[0]`; my @split_graph_points; foreach (@report_graph_point) { @split_graph_points = split (' ', $_); foreach my $graph_point (@split_graph_points) { $graph_point =~ s/"//g; my ($key, $val) = split ("=", $graph_point); push (@{$graph_point_hash{$key}}, "$val"); } #foreach loop ends here } #foreach loop ends here print Dumper \%graph_point_hash; XML file is <iostat> <data avgqu="0" avgrq="0" await="0" device="sdb" elapsed_time="0" r= +"0" rmb="0" rrqm="0" svctm="0" util="0" w="0" wmb="0" wrqm="0" /> <data avgqu="0" avgrq="0" await="0" device="sda" elapsed_time="0" r= +"0" rmb="0" rrqm="0" svctm="0" util="0" w="0" wmb="0" wrqm="0" /> <data avgqu="0.00" avgrq="0.00" await="0.00" device="sdb" elapsed_ti +me="1" r="0.00" rmb="0.00" rrqm="0.00" svctm="0.00" util="0.00" w="0. +00" wmb="0.00" wrqm="0.00" /> <data avgqu="0.00" avgrq="58.91" await="0.09" device="sda" elapsed_t +ime="1" r="0.00" rmb="0.00" rrqm="0.00" svctm="0.09" util="0.05" w="5 +.50" wmb="324.00" wrqm="35.00" /> <data avgqu="0.00" avgrq="0.00" await="0.00" device="sdb" elapsed_ti +me="2" r="0.00" rmb="0.00" rrqm="0.00" svctm="0.00" util="0.00" w="0. +00" wmb="0.00" wrqm="0.00" /> THE OUTPUT IS $VAR1 = { 'w' => [ '0', '0', '0.00', '5.50', '0.00', '2.50', '0.00', '489.50', '0.00', '0.00', '0.00', '0.00', '0.00', '242.00', '0.00', '0.00', '0.00', '5.50', '0.00', '4.00',
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I need to create a graph from a hash using GD else GD::Graph
by Laurent_R (Canon) on Sep 10, 2013 at 10:40 UTC | |
by rahulruns (Scribe) on Sep 11, 2013 at 05:13 UTC | |
by poj (Abbot) on Sep 11, 2013 at 09:20 UTC | |
by Laurent_R (Canon) on Sep 11, 2013 at 06:36 UTC |