line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Parser::Vmstat; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Test::Parser::Vmstat - Perl module to parse output from vmstat. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Test::Parser::Vmstat; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $parser = new Test::Parser::Vmstat; |
12
|
|
|
|
|
|
|
$parser->parse($text); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This module transforms vmstat output into a hash that can be used to generate |
17
|
|
|
|
|
|
|
XML. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 FUNCTIONS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Also see L for functions available from the base class. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
24399
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
26
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
27
|
1
|
|
|
1
|
|
610
|
use Test::Parser; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
29
|
|
28
|
1
|
|
|
1
|
|
1727
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
@Test::Parser::Vmstat::ISA = qw(Test::Parser); |
31
|
|
|
|
|
|
|
use base 'Test::Parser'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use fields qw( |
34
|
|
|
|
|
|
|
data |
35
|
|
|
|
|
|
|
time_units |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use vars qw( %FIELDS $AUTOLOAD $VERSION ); |
39
|
|
|
|
|
|
|
our $VERSION = '1.7'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 new() |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Creates a new Test::Parser::Vmstat instance. |
44
|
|
|
|
|
|
|
Also calls the Test::Parser base class' new() routine. |
45
|
|
|
|
|
|
|
Takes no arguments. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
50
|
|
|
|
|
|
|
my $class = shift; |
51
|
|
|
|
|
|
|
my Test::Parser::Vmstat $self = fields::new($class); |
52
|
|
|
|
|
|
|
$self->SUPER::new(); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$self->name('vmstat'); |
55
|
|
|
|
|
|
|
$self->type('standards'); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# |
58
|
|
|
|
|
|
|
# Vmstat data in an array. |
59
|
|
|
|
|
|
|
# |
60
|
|
|
|
|
|
|
$self->{data} = []; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
# Used for plotting. |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
$self->{format} = 'png'; |
66
|
|
|
|
|
|
|
$self->{outdir} = '.'; |
67
|
|
|
|
|
|
|
$self->{time_units} = 'Minutes'; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head3 data() |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Returns a hash representation of the vmstat data. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
sub data { |
78
|
|
|
|
|
|
|
my $self = shift; |
79
|
|
|
|
|
|
|
if (@_) { |
80
|
|
|
|
|
|
|
$self->{data} = @_; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
return {vmstat => {data => $self->{data}}}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head3 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Override of Test::Parser's default parse_line() routine to make it able |
88
|
|
|
|
|
|
|
to parse vmstat output. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
sub parse_line { |
92
|
|
|
|
|
|
|
my $self = shift; |
93
|
|
|
|
|
|
|
my $line = shift; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
# Trim any leading and trailing whitespaces. |
97
|
|
|
|
|
|
|
# |
98
|
|
|
|
|
|
|
$line =~ s/^\s+//; |
99
|
|
|
|
|
|
|
chomp($line); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my @i = split / +/, $line; |
102
|
|
|
|
|
|
|
# |
103
|
|
|
|
|
|
|
# These should ignore any header lines. |
104
|
|
|
|
|
|
|
# |
105
|
|
|
|
|
|
|
return 1 if (scalar @i != 16); |
106
|
|
|
|
|
|
|
return 1 if ($i[0] eq 'r'); |
107
|
|
|
|
|
|
|
# |
108
|
|
|
|
|
|
|
# Since the first row of data is garbage, set everything to 0. |
109
|
|
|
|
|
|
|
# |
110
|
|
|
|
|
|
|
my $count = scalar @{$self->{data}}; |
111
|
|
|
|
|
|
|
@i = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) |
112
|
|
|
|
|
|
|
if ($count == 0); |
113
|
|
|
|
|
|
|
push @{$self->{data}}, {r => $i[0], b => $i[1], swpd => $i[2], |
114
|
|
|
|
|
|
|
free => $i[3], buff => $i[4], cache => $i[5], si => $i[6], |
115
|
|
|
|
|
|
|
so => $i[7], bi => $i[8], bo => $i[9], in => $i[10], cs => $i[11], |
116
|
|
|
|
|
|
|
us => $i[12], sy => $i[13], idle => $i[14], wa => $i[15], |
117
|
|
|
|
|
|
|
elapsed_time => $count}; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return 1; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head3 to_xml() |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Returns vmstat data transformed into XML. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
sub to_xml { |
128
|
|
|
|
|
|
|
my $self = shift; |
129
|
|
|
|
|
|
|
my $outfile = shift; |
130
|
|
|
|
|
|
|
return XMLout({data => $self->{data}}, RootName => 'vmstat'); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
__END__ |