use strict; use warnings; use Test::Parser::Vmstat; use Tie::File; my @vmstat_data; tie @vmstat_data, 'Tie::File', $ARGV[0] or die $!; `sed '/[procs|swpd]/d' $ARGV[0] > /tmp/vmstat_intermidiate`; open (my $in, '<', "/tmp/vmstat_intermidiate") or die "Can't read old file: $!"; open (my $out, '>', "/tmp/vmstat_log") or die "Can't write new file: $!"; print $out "$vmstat_data[0]\n"; print $out "$vmstat_data[1]\n"; while( <$in> ) { print $out $_; } close $out; close $in; `rm -rf /tmp/vmstat_intermidiate`; my $parser = new Test::Parser::Vmstat or die "Couldn't create Test::Parser::Vmstat object\n"; my $logfile = '/tmp/vmstat_log'; $parser->parse($logfile) or die "Could not parse Vmstat log.\n"; print $parser->to_xml(); OUTPUT procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 50122424 234628 9616504 0 0 0 20 2 4 0 0 99 0 0 0 0 0 50121664 234628 9616864 0 0 0 0 7813 5956 1 1 98 0 0 1 0 0 50122252 234628 9616864 0 0 0 190 10727 6872 2 1 97 0 0 0 0 0 50122092 234628 9616864 0 0 0 164 8645 6966 1 1 98 0 0 PERL SCRIPT OUTPUT [root@r01mgt ~]# perl parse_vmstat.pl /tmp/vmstat