forked from pcpiela/collectl-lustre
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LustreCommon.pm
80 lines (67 loc) · 1.67 KB
/
LustreCommon.pm
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
use strict;
package LustreCommon;
use constant NO_SAMPLE => -12341234;
sub lustreGetRpcStats {
my $proc = shift;
my $tag = shift;
if (!open PROC, "<$proc") {
return(0);
}
while (my $line = <PROC>) {
if (($line =~ /req_waittime /) ||
($line =~ /req_qdepth /) ||
($line =~ /req_active /) ||
($line =~ /req_timeout /) ||
($line =~ /reqbuf_avail /)) {
main::record(2, "$tag $line" );
}
}
close PROC;
return(1);
}
sub transLustreUUID {
my $name = shift;
my $Host = shift;
my $hostRoot;
# This handles names like OST_Lustre9_2_UUID or OST_Lustre9_UUID
# changing them to just 0,9 or ost123.
chomp $name;
$hostRoot = $Host;
$hostRoot =~ s/\d+$//;
$name =~ s/OST_$hostRoot\d+//;
$name =~ s/_UUID//;
$name =~ s/_//;
$name = 0 if $name eq '';
return($name);
}
sub sumMetricValStr {
my $val = shift;
my $width = shift;
return ($val == NO_SAMPLE) ?
sprintf("%".$width."s", " ") :
sprintf("%".$width."d", $val);
}
sub updateSumMetric {
my $metric = shift;
my $cumulCount = shift;
my $sum = shift;
if (defined $metric->{lastCumulCount} && defined $metric->{lastSum}) {
if ($cumulCount == $metric->{lastCumulCount}) {
$metric->{value} = LustreCommon::NO_SAMPLE;
} elsif ($cumulCount > $metric->{lastCumulCount} &&
$sum >= $metric->{lastSum}) {
$metric->{value} = ($sum - $metric->{lastSum}) /
($cumulCount - $metric->{lastCumulCount});
}
} else {
$metric->{value} = 0;
}
$metric->{lastCumulCount} = $cumulCount;
$metric->{lastSum} = $sum;
}
sub delta {
my $current = shift;
my $last = shift;
return (defined $last && ($current > $last)) ? $current - $last : 0;
}
1;