| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Parser::Iostat; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Test::Parser::Iostat - Perl module to parse output from iostat (iostat -x). |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Test::Parser::Iostat; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $parser = new Test::Parser::Iostat; |
|
12
|
|
|
|
|
|
|
$parser->parse($text); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This module transforms iostat 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
|
|
24409
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
46
|
|
|
26
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
27
|
1
|
|
|
1
|
|
697
|
use Test::Parser; |
|
|
1
|
|
|
|
|
14
|
|
|
|
1
|
|
|
|
|
31
|
|
|
28
|
1
|
|
|
1
|
|
1728
|
use XML::Simple; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
@Test::Parser::Iostat::ISA = qw(Test::Parser); |
|
31
|
|
|
|
|
|
|
use base 'Test::Parser'; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use fields qw( |
|
34
|
|
|
|
|
|
|
device |
|
35
|
|
|
|
|
|
|
data |
|
36
|
|
|
|
|
|
|
elapsed_time |
|
37
|
|
|
|
|
|
|
info |
|
38
|
|
|
|
|
|
|
time_units |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
use vars qw( %FIELDS $AUTOLOAD $VERSION ); |
|
42
|
|
|
|
|
|
|
our $VERSION = '1.7'; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 new() |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Creates a new Test::Parser::Iostat instance. |
|
47
|
|
|
|
|
|
|
Also calls the Test::Parser base class' new() routine. |
|
48
|
|
|
|
|
|
|
Takes no arguments. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub new { |
|
53
|
|
|
|
|
|
|
my $class = shift; |
|
54
|
|
|
|
|
|
|
my Test::Parser::Iostat $self = fields::new($class); |
|
55
|
|
|
|
|
|
|
$self->SUPER::new(); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self->name('iostat'); |
|
58
|
|
|
|
|
|
|
$self->type('standards'); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# |
|
61
|
|
|
|
|
|
|
# Iostat data in an array and other supporting information. |
|
62
|
|
|
|
|
|
|
# |
|
63
|
|
|
|
|
|
|
$self->{data} = []; |
|
64
|
|
|
|
|
|
|
$self->{info} = ''; |
|
65
|
|
|
|
|
|
|
# |
|
66
|
|
|
|
|
|
|
# Start at -1 because the first increment to the value will set it to 0 |
|
67
|
|
|
|
|
|
|
# for the first set of data. |
|
68
|
|
|
|
|
|
|
# |
|
69
|
|
|
|
|
|
|
$self->{elapsed_time} = -1; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# |
|
72
|
|
|
|
|
|
|
# Used for plotting. |
|
73
|
|
|
|
|
|
|
# |
|
74
|
|
|
|
|
|
|
$self->{format} = 'png'; |
|
75
|
|
|
|
|
|
|
$self->{outdir} = '.'; |
|
76
|
|
|
|
|
|
|
$self->{time_units} = 'Minutes'; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return $self; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head3 data() |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Returns a hash representation of the iostat data. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
sub data { |
|
87
|
|
|
|
|
|
|
my $self = shift; |
|
88
|
|
|
|
|
|
|
if (@_) { |
|
89
|
|
|
|
|
|
|
$self->{data} = @_; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
return {iostat => {data => $self->{data}}}; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head3 |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Override of Test::Parser's default parse_line() routine to make it able |
|
97
|
|
|
|
|
|
|
to parse iostat output. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
|
100
|
|
|
|
|
|
|
sub parse_line { |
|
101
|
|
|
|
|
|
|
my $self = shift; |
|
102
|
|
|
|
|
|
|
my $line = shift; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# |
|
105
|
|
|
|
|
|
|
# Trim any leading and trailing whitespaces. |
|
106
|
|
|
|
|
|
|
# |
|
107
|
|
|
|
|
|
|
chomp($line); |
|
108
|
|
|
|
|
|
|
$line =~ s/^\s+//; |
|
109
|
|
|
|
|
|
|
$line =~ s/\s+$//; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my @i = split / +/, $line; |
|
112
|
|
|
|
|
|
|
my $count = scalar @i; |
|
113
|
|
|
|
|
|
|
if ($count == 12) { |
|
114
|
|
|
|
|
|
|
# |
|
115
|
|
|
|
|
|
|
# This is either the iostat headers or the data. If it's a header |
|
116
|
|
|
|
|
|
|
# skip to the next line and increment the counter. |
|
117
|
|
|
|
|
|
|
# |
|
118
|
|
|
|
|
|
|
if ($i[0] eq "Device:") { |
|
119
|
|
|
|
|
|
|
# |
|
120
|
|
|
|
|
|
|
# We've gone through 1 iteration of data, increment the counter. |
|
121
|
|
|
|
|
|
|
# |
|
122
|
|
|
|
|
|
|
++$self->{elapsed_time}; |
|
123
|
|
|
|
|
|
|
return 1; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
} elsif ($count == 1) { |
|
126
|
|
|
|
|
|
|
# |
|
127
|
|
|
|
|
|
|
# This just read the device name. The data will be on the next line. |
|
128
|
|
|
|
|
|
|
# |
|
129
|
|
|
|
|
|
|
$self->{device} = $line; |
|
130
|
|
|
|
|
|
|
return 1; |
|
131
|
|
|
|
|
|
|
} elsif ($count == 11) { |
|
132
|
|
|
|
|
|
|
# |
|
133
|
|
|
|
|
|
|
# Put $self->{device} in front of @i |
|
134
|
|
|
|
|
|
|
# |
|
135
|
|
|
|
|
|
|
unshift @i, $self->{device}; |
|
136
|
|
|
|
|
|
|
} elsif ($count == 4) { |
|
137
|
|
|
|
|
|
|
# |
|
138
|
|
|
|
|
|
|
# This should be information about the OS and the date. |
|
139
|
|
|
|
|
|
|
# |
|
140
|
|
|
|
|
|
|
$self->{info} = $line; |
|
141
|
|
|
|
|
|
|
return 1; |
|
142
|
|
|
|
|
|
|
} else { |
|
143
|
|
|
|
|
|
|
# |
|
144
|
|
|
|
|
|
|
# Skip empty lines. |
|
145
|
|
|
|
|
|
|
# |
|
146
|
|
|
|
|
|
|
return 1; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
# |
|
149
|
|
|
|
|
|
|
# If $self->{elapsed_time} == 0 then zero the data out since it's bogus. |
|
150
|
|
|
|
|
|
|
# |
|
151
|
|
|
|
|
|
|
@i = ($i[0], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) |
|
152
|
|
|
|
|
|
|
if ($self->{elapsed_time} == 0); |
|
153
|
|
|
|
|
|
|
push @{$self->{data}}, {device => $i[0], rrqm => $i[1], wrqm => $i[2], |
|
154
|
|
|
|
|
|
|
r => $i[3], w => $i[4], rmb => $i[5], wmb => $i[6], avgrq => $i[7], |
|
155
|
|
|
|
|
|
|
avgqu => $i[8], await => $i[9], svctm => $i[10], util => $i[11], |
|
156
|
|
|
|
|
|
|
elapsed_time => $self->{elapsed_time}}; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
return 1; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head3 to_xml() |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Returns iostat data transformed into XML. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
|
166
|
|
|
|
|
|
|
sub to_xml { |
|
167
|
|
|
|
|
|
|
my $self = shift; |
|
168
|
|
|
|
|
|
|
my $outfile = shift; |
|
169
|
|
|
|
|
|
|
return XMLout({data => $self->{data}}, RootName => 'iostat'); |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |
|
173
|
|
|
|
|
|
|
__END__ |