2 # llobdstat is a utility that parses obdfilter statistics files
3 # found at proc/fs/lustre/<ostname>/stats.
4 # It is mainly useful to watch the statistics change over time.
8 my $defaultpath = "/proc/fs/lustre";
9 my $obdstats = "stats";
13 print STDERR "Usage: $pname <ost_name> [<interval>]\n";
14 print STDERR "where ost_name : ost name under $defaultpath/obdfilter\n";
15 print STDERR " interval : sample interaval in seconds\n";
16 print STDERR "example: $pname lustre-OST0000 2\n";
17 print STDERR "Use CTRL + C to stop statistics printing\n";
21 my $statspath = "None";
24 if (($#ARGV < 0) || ($#ARGV > 1)) {
27 if ( $ARGV[0] =~ /help$/ ) {
31 $statspath = $ARGV[0];
32 } elsif ( -f "$ARGV[0]/$obdstats" ) {
33 $statspath = "$ARGV[0]/$obdstats";
35 my $st = `ls $defaultpath/*/$ARGV[0]/$obdstats 2> /dev/null`;
41 if ( $statspath =~ /^None$/ ) {
42 die "Cannot locate stat file for: $ARGV[0]\n";
49 print "$pname on $statspath\n";
55 #Removed some statstics like open, close that obdfilter don't contains.
56 #To add statistics parameters one need to specify parameter names in below declarations in same sequence.
57 my ($read_bytes, $write_bytes, $create, $destroy, $statfs, $punch, $snapshot_time) =
58 ("read_bytes", "write_bytes", "create", "destroy", "statfs", "punch", "snapshot_time");
60 my @extinfo = ($create, $destroy, $statfs, $punch);
61 my %shortname = ($create => "cx", $destroy => "dx", $statfs => "st", $punch => "pu");
66 my $itc_freq; # On Itanium systems use this
67 if (open(CPUINFO, "/proc/cpuinfo")==0) {
71 if (/^cpu MHz\s+:\s*([\d\.]+)/) { $cpu_freq=$1; }
72 elsif (/^itc MHz\s+:\s*([\d\.]+)/) { $itc_freq=$1; }
74 if (defined($itc_freq)) { $mhz = $itc_freq; }
75 elsif (defined($cpu_freq)) { $mhz = $cpu_freq; }
81 print "Processor counters run at $mhz MHz\n";
83 # readstats subroutine reads statistics from obdfilter stats file.
84 # This subroutine gets called after every interval specified by user.
93 # ($name, $cumulcount, $samples, $unit, $min, $max, $sum, $sumsquare)
94 @iodata = split(/\s+/, $_);
95 my $name = $iodata[0];
97 $prevcount = $cur{$name};
98 if (defined($prevcount)) {
99 $last{$name} = $prevcount;
101 if ($name =~ /^read_bytes$/ || $name =~ /^write_bytes$/) {
102 $cur{$name} = $iodata[6];
104 elsif ($name =~ /^snapshot_time$/) {
105 # $cumulcount =~ /(\d+)/;
106 $cur{$name} = $iodata[1];
109 $cur{$name} = $iodata[1];
113 # process_stats subroutine processes stats information read from obdfilter stats file.
114 # This subroutine gets called after every interval specified by user.
119 my $last_time = $last{$snapshot_time};
120 if (!defined($last_time)) {
121 printf "Read: %-g, Write: %-g, create/destroy: %-g/%-g, stat: %-g, punch: %-g\n",
122 $cur{$read_bytes}, $cur{$write_bytes},
123 $cur{$create}, $cur{$destroy},
124 $cur{$statfs}, $cur{$punch};
126 print "[NOTE: cx: create, dx: destroy, st: statfs, pu: punch ]\n\n";
127 print "Timestamp Read-delta ReadRate Write-delta WriteRate\n";
128 print "--------------------------------------------------------\n";
132 my $timespan = $cur{$snapshot_time} - $last{$snapshot_time};
133 my $rdelta = $cur{$read_bytes} - $last{$read_bytes};
134 my $rrate = ($rdelta) / ($timespan * ( 1 << 20 ));
135 my $wdelta = $cur{$write_bytes} - $last{$write_bytes};
136 my $wrate = ($wdelta) / ($timespan * ( 1 << 20 ));
137 $rdelta = ($rdelta) / (1024 * 1024);
138 $wdelta = ($wdelta) / (1024 * 1024);
139 # This print repeats after every interval.
140 printf "%10lu %6.2fMB %6.2fMB/s %6.2fMB %6.2fMB/s",
141 $cur{$snapshot_time}, $rdelta, $rrate, $wdelta, $wrate;
143 $delta = $cur{$getattr} - $last{$getattr};
145 $rdelta = int ($delta/$timespan);
146 print " ga:$delta,$rdelta/s";
149 for $data ( @extinfo ) {
150 $delta = $cur{$data} - $last{$data};
152 print " $shortname{$data}:$delta";
159 #Open the obdfilter stat file with STATS
160 open(STATS, $statspath) || die "Cannot open $statspath: $!\n";
162 readstat(); # read the statistics from stat file.
168 } while ($interval); # Repeat the statistics printing after every "interval" specified in command line.
170 # llobdfilter.pl ends here.