-
Notifications
You must be signed in to change notification settings - Fork 9
/
disk-pivot.pl
executable file
·67 lines (42 loc) · 1.11 KB
/
disk-pivot.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
#!/usr/bin/perl
=head1 disk-pivot.pl
=head2 pivot avg writetimes per disk
Transform this layout
timestamp diskname metric1 metric2 metric3
To this layout
timestamp disk1 disk2 disk3 ...
metric
In this case the metric is avg_wrt_time, but it can be any metric
=cut
use warnings;
use strict;
use Data::Dumper;
my @timestamps=();
my %diskData=();
my $hdr = <STDIN>;
chomp $hdr;
my @hdr = split(/,/,$hdr);
while(<STDIN>) {
chomp;
my ($timestamp, $avgReadTime, $avgWriteTime, $diskName) = split(/,/);
push @timestamps, $timestamp unless grep(/$timestamp/,@timestamps);
#push @{$diskData{$timestamp}->{$diskName}}, $avgWriteTime;
$diskData{$timestamp}->{$diskName} = $avgWriteTime;
}
#print Dumper(\%diskData);
my @diskNames;
foreach my $timestamp ( @timestamps ) {
my %times = %{$diskData{$timestamp}};
#print Dumper(\%times);
#die;
if (! defined $diskNames[0] ) {
@diskNames = map{ $_ } sort keys %times;
print 'timestamp,' . join(',',@diskNames) . "\n";
}
print "$timestamp";
foreach my $diskName ( @diskNames ) {
print ",$times{$diskName}";
}
print "\n";
}
#print Dumper(\@diskNames);