| 1 | ################################################################################ | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use POSIX qw(mktime); | ||
| 5 | use StatsView::Graph; | ||
| 6 | package StatsView::Graph::Vxstat; | ||
| 7 | @StatsView::Graph::Vxstat::ISA = qw(StatsView::Graph); | ||
| 8 | |||
| 9 | %StatsView::Graph::Vxstat::m2n = | ||
| 10 | ( Jan => 0, Feb => 1, Mar => 2, Apr => 3, May => 4, Jun => 5, | ||
| 11 | Jul => 6, Aug => 7, Sep => 8, Oct => 9, Nov => 10, Dec => 11 ); | ||
| 12 | |||
| 13 | ################################################################################ | ||
| 14 | |||
| 15 | sub new($$$) | ||
| 16 | { | ||
| 17 | my ($class, $file, $fh) = @_; | ||
| 18 | $class = ref($class) || $class; | ||
| 19 | |||
| 20 | # Look for the header lines | ||
| 21 | my $line; | ||
| 22 | while (defined($line = $fh->getline()) && $line =~ /^\s*$/) { } | ||
| 23 | $line =~ /OPERATIONS\s+BLOCKS\s+AVG TIME\(ms\)/ || return(undef); | ||
| 24 | $line = $fh->getline(); | ||
| 25 | $line =~ /TYP NAME\s+READ\s+WRITE\s+READ\s+WRITE\s+READ\s+WRITE/ | ||
| 26 | || return(undef); | ||
| 27 | |||
| 28 | # Find the first timestamp & figure out the format | ||
| 29 | my $self = $class->SUPER::init($file); | ||
| 30 | while (defined($line = $fh->getline()) && $line !~ /\d\d:\d\d:\d\d/) { } | ||
| 31 | my @l = split(/\s+|:/, $line); | ||
| 32 | if (@l == 7) | ||
| 33 | { | ||
| 34 | $self->{parsedate} = sub | ||
| 35 | { | ||
| 36 | my @d = split(/\s+|:/, $_[0]); | ||
| 37 | $d[1] = $StatsView::Graph::Vxstat::m2n{substr($d[1], 0, 3)}; | ||
| 38 | $d[6] -= 1900; | ||
| 39 | return(POSIX::mktime(@d[5,4,3,2,1,6], 0, 0, -1)); | ||
| 40 | }; | ||
| 41 | } | ||
| 42 | elsif (@l == 9) | ||
| 43 | { | ||
| 44 | $self->{parsedate} = sub | ||
| 45 | { | ||
| 46 | my @d = split(/\s+|:/, $_[0]); | ||
| 47 | $d[2] = $StatsView::Graph::Vxstat::m2n{substr($d[2], 0, 3)}; | ||
| 48 | $d[3] -= 1900; | ||
| 49 | if ($d[4] == 12) { $d[4] -= 12 if ($d[7] =~ /AM/i); } | ||
| 50 | else { $d[4] += 12 if ($d[7] =~ /PM/i); } | ||
| 51 | return(POSIX::mktime(@d[6,5,4,1,2,3], 0, 0, -1)); | ||
| 52 | }; | ||
| 53 | } | ||
| 54 | else | ||
| 55 | { return(undef); } | ||
| 56 | |||
| 57 | return($self); | ||
| 58 | } | ||
| 59 | |||
| 60 | ################################################################################ | ||
| 61 | |||
| 62 | sub read($) | ||
| 63 | { | ||
| 64 | my ($self) = @_; | ||
| 65 | $self->SUPER::read(); | ||
| 66 | |||
| 67 | # Open the file | ||
| 68 | my $vxstat = IO::File->new($self->{file}, "r") | ||
| 69 | || die("Can't open $self->{file}: $!\n"); | ||
| 70 | $self->{title} = "Veritas Statistics"; | ||
| 71 | |||
| 72 | # Look for the header lines | ||
| 73 | my $line; | ||
| 74 | while (defined($line = $vxstat->getline()) && $line =~ /^\s*$/) { } | ||
| 75 | $line =~ /OPERATIONS\s+BLOCKS\s+AVG TIME\(ms\)/ | ||
| 76 | || die("$self->{file} is not a vxstat file (1)\n"); | ||
| 77 | $line = $vxstat->getline(); | ||
| 78 | $line =~ /TYP NAME\s+READ\s+WRITE\s+READ\s+WRITE\s+READ\s+WRITE/ | ||
| 79 | || die("$self->{file} is not a vxstat file (2)\n"); | ||
| 80 | |||
| 81 | # Define the column types - N = numeric, % = percentage | ||
| 82 | $self->define_cols(['Read op/sec', 'Write op/sec', | ||
| 83 | 'Read blk/sec', 'Write blk/sec', | ||
| 84 | 'Avg read (ms)', 'Avg write (ms)' ], | ||
| 85 | [ qw(N N N N N N) ]); | ||
| 86 | |||
| 87 | # Skip to the start of the second timestamp - | ||
| 88 | # the data after the first is info from the last reboot to the present | ||
| 89 | my $parsedate = $self->{parsedate}; | ||
| 90 | while (defined ($line = $vxstat->getline()) && $line !~ /\d\d:\d\d:\d\d/) { } | ||
| 91 | die("$self->{file} is not a vxstat file (3)\n") if (! $line); | ||
| 92 | my $first_ts = &$parsedate($line); | ||
| 93 | |||
| 94 | while (defined ($line = $vxstat->getline()) && $line !~ /^\s*$/) { } | ||
| 95 | die("$self->{file} is not a vxstat file (4)\n") if (! $line); | ||
| 96 | |||
| 97 | my $interval; | ||
| 98 | my $tstamp; | ||
| 99 | my $first = 1; | ||
| 100 | while (defined($line = $vxstat->getline())) | ||
| 101 | { | ||
| 102 | # Parse the timestamp | ||
| 103 | $tstamp = &$parsedate($line); | ||
| 104 | |||
| 105 | # If this is the first sample, store the start time | ||
| 106 | if ($first) | ||
| 107 | { | ||
| 108 | $self->{start} = $tstamp; | ||
| 109 | $interval = $self->{interval} = $tstamp - $first_ts; | ||
| 110 | $first = 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | # Read the data | ||
| 114 | while (defined($line = $vxstat->getline()) && $line !~ /^\s*$/) | ||
| 115 | { | ||
| 116 | my (@value) = split(' ', $line); | ||
| 117 | my $inst = shift(@value) . " " . shift(@value); | ||
| 118 | |||
| 119 | # Scale values to be in units of a second | ||
| 120 | @value[0..3] = map({ $_ / $interval } @value[0..3]); | ||
| 121 | |||
| 122 | # Save the data | ||
| 123 | push(@{$self->{data}{$inst}}, { tstamp => $tstamp, value => [ @value ] }); | ||
| 124 | $self->{instance}{$inst} = $self->{index_3d}++ | ||
| 125 | if (! exists($self->{instance}->{$inst})); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | $self->{finish} = $tstamp; | ||
| 129 | $vxstat->close(); | ||
| 130 | } | ||
| 131 | |||
| 132 | ################################################################################ | ||
| 133 | |||
| 134 | sub get_data_type($;$) | ||
| 135 | { | ||
| 136 | return("3d"); | ||
| 137 | } | ||
| 138 | |||
| 139 | ################################################################################ | ||
| 140 | 1; |