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 $obdstats = "stats";
12 print STDERR "Usage: $pname <ost_name> [<interval> [<count>}]\n";
13 print STDERR "where ost_name : ost name under obdfilter\n";
14 print STDERR " interval : sample interval in seconds\n";
15 print STDERR "example: $pname lustre-OST0000 2\n";
16 print STDERR "Use CTRL + C to stop statistics printing\n";
20 my $statspath = "None";
24 if (($#ARGV < 0) || ($#ARGV > 2)) {
27 if ( $ARGV[0] =~ /help$/ ) {
31 $statspath = $ARGV[0];
32 } elsif ( -f "$ARGV[0]/$obdstats" ) {
33 $statspath = "$ARGV[0]/$obdstats";
35 my $st = glob ("/{proc,sys}/fs/lustre/obdfilter/$ARGV[0]");
39 my $st = glob("/{proc,sys}/fs/lustre/obdfilter/$ARGV[0]/$obdstats");
45 if ( $statspath =~ /^None$/ ) {
46 die "Cannot locate stat file for: $ARGV[0]\n";
56 print "$pname on $ARGV[0]\n";
62 # Removed some statstics like open, close that obdfilter doesn't contain.
63 # To add statistics parameters one needs to specify parameter names in the
64 # below declarations in the same sequence.
65 my ($read_bytes, $write_bytes, $create, $destroy, $statfs, $punch,
66 $snapshot_time) = ("read_bytes", "write_bytes", "create", "destroy",
67 "statfs", "punch", "snapshot_time");
69 my @extinfo = ($create, $destroy, $statfs, $punch);
70 my %shortname = ($create => "cx", $destroy => "dx", $statfs => "st", $punch => "pu");
75 my $itc_freq; # On Itanium systems use this
76 if (open(CPUINFO, "/proc/cpuinfo")==0) {
80 if (/^cpu MHz\s+:\s*([\d\.]+)/) { $cpu_freq=$1; }
81 elsif (/^itc MHz\s+:\s*([\d\.]+)/) { $itc_freq=$1; }
83 if (defined($itc_freq)) {
85 } elsif (defined($cpu_freq)) {
94 print "Processor counters run at $mhz MHz\n";
96 # read statistics from obdfilter stats file.
97 # This subroutine gets called after every interval specified by user.
106 # ($name, $cumulcount, $samples, $unit, $min, $max, $sum, $sumsquare)
107 @iodata = split(/\s+/, $_);
108 my $name = $iodata[0];
110 $prevcount = $cur{$name};
111 if (defined($prevcount)) {
112 $last{$name} = $prevcount;
114 if ($name =~ /^read_bytes$/ || $name =~ /^write_bytes$/) {
115 $cur{$name} = $iodata[6];
117 elsif ($name =~ /^snapshot_time$/) {
118 # $cumulcount =~ /(\d+)/;
119 $cur{$name} = $iodata[1];
121 $cur{$name} = $iodata[1];
126 # process stats information read from obdfilter stats file.
127 # This subroutine gets called after every interval specified by user.
132 my $last_time = $last{$snapshot_time};
133 if (!defined($last_time)) {
134 printf "Read: %-g, Write: %-g, create/destroy: %-g/%-g, stat: %-g, punch: %-g\n",
135 $cur{$read_bytes}, $cur{$write_bytes},
136 $cur{$create}, $cur{$destroy},
137 $cur{$statfs}, $cur{$punch};
139 print "[NOTE: cx: create, dx: destroy, st: statfs, pu: punch ]\n\n";
140 print "Timestamp Read-delta ReadRate Write-delta WriteRate\n";
141 print "--------------------------------------------------------\n";
144 my $timespan = $cur{$snapshot_time} - $last{$snapshot_time};
145 my $rdelta = $cur{$read_bytes} - $last{$read_bytes};
146 my $rrate = ($rdelta) / ($timespan * ( 1 << 20 ));
147 my $wdelta = $cur{$write_bytes} - $last{$write_bytes};
148 my $wrate = ($wdelta) / ($timespan * ( 1 << 20 ));
149 $rdelta = ($rdelta) / (1024 * 1024);
150 $wdelta = ($wdelta) / (1024 * 1024);
151 # This print repeats after every interval.
152 printf "%10lu %6.2fMB %6.2fMB/s %6.2fMB %6.2fMB/s",
153 $cur{$snapshot_time}, $rdelta, $rrate, $wdelta, $wrate;
155 $delta = $cur{$getattr} - $last{$getattr};
157 $rdelta = int ($delta/$timespan);
158 print " ga:$delta,$rdelta/s";
161 for $data ( @extinfo ) {
162 $delta = $cur{$data} - $last{$data};
164 print " $shortname{$data}:$delta";
172 #Open the obdfilter stat file with STATS
173 open(STATS, $statspath) || die "Cannot open $statspath: $!\n";
175 # read the statistics from stat file.
182 # Repeat the statistics printing after every "interval" specified in
183 # command line, up to counter times, if specified
184 } while ($interval && (defined($counter) ? $counter-- > 0 : 1));
186 # llobdfilter.pl ends here.