-
Notifications
You must be signed in to change notification settings - Fork 9
/
asm-metrics-fix.pl
executable file
·108 lines (79 loc) · 2.58 KB
/
asm-metrics-fix.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env perl
=head1 asm-metrics-fix.pl
This script will correct snaptime values if present
Negative elapsed times will also be fixed
These occurred due to the bug where 'HH' was used in a timestamp conversion.
The correct value in the timestamp format is 'HH24' and this has been corrected
in asm-metrics-collector.pl
=cut
use strict;
use warnings;
use IO::File;
my $debug=0;
my $dateLen=19; # YYYY-MM-DD HH24:MI:SS results in a 19 character date
# locations of column names in the row
# if snaptime is not in the data file,
# then remove or comment out the line
my %locations = (
DISPLAYTIME => 0,
SNAPTIME => 1,
ELAPSEDTIME => 2
);
my $useSnaptime = exists ($locations{SNAPTIME}) ? 1 : 0;
warn "useSnaptime: $useSnaptime\n" if $debug;
my $delimiter=',';
my $inputFile='abc123';
my $fh;
my $break='#' x 80;
while (<>) {
my $line=$_;
my $newInputFile=$ARGV;
if ($inputFile ne $newInputFile) {
print "Headers: $line" if $debug;
$inputFile=$newInputFile;
# assuming here that filename has a '.csv' suffix
my $flen = length($inputFile);
my $outputFile=substr($inputFile,0,$flen-4) . '-corrected.csv';
#if (defined($fh)) {
#print $fh "\n";
#}
$fh = IO::File->new();
#open CSVOUT, '>', $outputFile or die "cannot create $outputFile - $!\n";
$fh->open($outputFile,'>') or die "cannot create $outputFile - $!\n";
print $fh $line;
next;
}
my @row=split(/$delimiter/,$line);
my ($displayTime, $snapTime, $elapsedTime);
$displayTime=$row[$locations{DISPLAYTIME}];
$elapsedTime=$row[$locations{ELAPSEDTIME}];
if ($useSnaptime) {
$snapTime=$row[$locations{SNAPTIME}];
# detect incorrect snaptime by comparing just the first part of snaptime to display time
# display time was always correct
if ( substr($snapTime,0,$dateLen) ne $displayTime ) {
warn qq[
$break
Orig Disptime: $displayTime
Orig Snaptime: $snapTime
] if $debug;
# 2015-06-23 01
my $errHour=substr($snapTime,11,2);
warn "Err Hour: $errHour\n" if $debug;
my $newHour = $errHour + 12;
warn "New Hour: $newHour\n" if $debug;
substr($snapTime,11,2)=$newHour;
warn "New Snaptime: $snapTime\n" if $debug;
$row[$locations{SNAPTIME}] = $snapTime;
}
}
# the negative elapsed times occurred only the time went from 12:59.x to 13:00.x
# subtracting the absolute value of elapsed time from 60 will correct the negative values
if ($elapsedTime < 0 ) {
warn "Old elapsedTime: $elapsedTime\n" if $debug;
$elapsedTime = (60 - abs($elapsedTime));
warn "New elapsedTime: $elapsedTime\n" if $debug;
$row[$locations{ELAPSEDTIME}] = $elapsedTime;
}
print $fh join($delimiter,@row);
}