package Lustrestats; #perl module containing lustre stat formatting routines use strict; use Switch; use warnings; use Exporter; use vars qw(@ISA @EXPORT @EXPORT_OK); @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(parse_jobstats parse_stats parse_single parse_exportstats); sub parse_jobstats { # input - an array of jobstat output from mdt.*.job_stats or odbfilter.*OST*.job_stats # output - array with each line in format: # target jobid metic_name value timestamp # scratch-0ST0000 5688 read_bytes 1710444 130004401010 my ($jobstat_array)=@_; my $target; #ost or mdt target, like "scratch-OST0000" my $timestamp; my $jobid; my $value; my @stats_out; foreach my $line (@$jobstat_array) { my @linearray = split(' ', $line); #do a case statement for linearray length # 1 = "obdfilter.scratch-0000.job_stats=" or "job_stats" # 2 = timestamp # 3 = jobid # else = get values my $line_len = scalar @linearray; switch ($line_len) { case 1 { if ($linearray[0] =~ /^mdt\./) { $target = $linearray[0]; $target =~ s/\.job_stats=//g; $target =~ s/mdt\.//g; } elsif ($linearray[0] =~ /^obdfilter/) { $target = $linearray[0]; $target =~ s/\.job_stats=//g; $target =~ s/obdfilter\.//g; } } #endcase 1 case 2 { if ($linearray[0] eq 'snapshot_time:' ) { $timestamp = $linearray[1]; } } #endcase 2 case 3 { if ($linearray[1] eq 'job_id:') { $jobid = $linearray[2]; $jobid =~ s/\./\#/g; #replace any "." in procname.uid, for graphite schema } } #endcase 3 else { if ($linearray[0] =~ /read|write/) { $value = $linearray[11]; } else { $value = $linearray[3]; } $value =~ s/\,//g; my $metric_name = $linearray[0]; $metric_name =~ s/\://g; #push data on array my @outrecord = ($target, $jobid, $metric_name, $value, $timestamp); push @stats_out, join(' ',@outrecord); } #endcase else } #endswitch }#end foreach jobstat_array line #return the data return (\@stats_out); }#end sub parse_jobstats sub parse_stats { # input - an array of stat output from for exmple 'lctl get_param obdfilter.*.stats' or mdt.*MDT*.md_stats # output - array with each line in format: # target metric_name value timestamp # scratch-0ST0000 read_bytes 1710444 130004401010 my ($stat_array)=@_; my $target; #ost or mdt target, like "scratch-OST0000" my $timestamp; my $value; my @stats_out; foreach my $line (@$stat_array) { my @linearray = split(' ', $line); #do a case statement for linearray length # 1 = "obdfilter.scratch-0000.stats=" or "job_stats" # 3 = timestamp # else = get values my $line_len = scalar @linearray; switch ($line_len) { case 1 { if ($linearray[0] =~ /^mdt\./) { $target = $linearray[0]; $target =~ s/\.md_stats=//g; $target =~ s/mdt\.//g; } elsif ($linearray[0] =~ /^obdfilter/) { $target = $linearray[0]; $target =~ s/\.stats=//g; $target =~ s/obdfilter\.//g; } } #endcase 1 case 3 { if ($linearray[0] eq 'snapshot_time' ) { $timestamp = $linearray[1]; $timestamp = int($timestamp + 0.5); #round to integer } } #endcase 3 else { if ($linearray[0] =~ /read_bytes|write_bytes/) { $value = $linearray[6]; } else { $value = $linearray[1]; } my $metric_name = $linearray[0]; #push data on array my @outrecord = ($target, $metric_name, $value, $timestamp); push @stats_out, join(' ',@outrecord); } #endcase else } #endswitch }#end foreach stat_array line #return the data return (\@stats_out); }#end sub parse_stats sub parse_single { #input array, with one or more lines like this: # osd-ldiskfs.scratch-OST0000.kbytesavail=10563714384 #output - array with each line like this: # target metric_name value # scratch-OST-0000 kbytesvail 1056443234 #notice - timestamps aren't provided, so we don't output. It's easy enough to generate # your own if needed. #this script might not be worth the trouble, but included for completeness.. my ($stat_array)=@_; my $value; my $target; my @stats_out; foreach my $line (@$stat_array) { chomp $line; $line =~ s/\./\=/g; my @linearray = split('=', $line); push @stats_out, join(' ', $linearray[1], $linearray[2], $linearray[3]); } return (\@stats_out); }#end sub parse_single sub parse_exportstats { # input - an array of export stat output from for exmple 'lctl get_param mdt.*MDT*.exports.*o2ib.stats # output - array with each line in format: # target export metric_name value timestamp # scratch-0ST0000 172.17.1.6@o2ib read_bytes 1710444 130004401010 my ($stat_array)=@_; my $target; #ost or mdt target, like "scratch-OST0000" my $export; #name of export like 172.17.1.6@o2ib my $timestamp; my $value; my @stats_out; foreach my $line (@$stat_array) { my @linearray = split(' ', $line); #do a case statement for linearray length # 1 = "mdt.scratch-MDT0000.exports.172.17.1@o2ib.stats=" # 3 = timestamp - note standalone timestamps ignored, look like: # mdt.scratch-MDT0000.exports.172.17.1.2@o2ib.stats=snapshot_time 1410535014.186685 secs.usecs # else = get values my $line_len = scalar @linearray; switch ($line_len) { case 1 { if ($linearray[0] =~ /^mdt\./) { #split this thing at "exports" for easier parsing my @statinfo = split ('.exports.', $linearray[0]); $target = $statinfo[0]; $target =~ s/mdt\.//g; $export = $statinfo[1]; $export =~ s/\.stats=//g; } elsif ($linearray[0] =~ /^obdfilter/) { my @statinfo = split ('.exports.', $linearray[0]); $target = $statinfo[0]; $target =~ s/obdfilter\.//g; $export = $statinfo[1]; $export =~ s/\.stats=//g; } } #endcase 1 case 3 { if ($linearray[0] eq 'snapshot_time' ) { $timestamp = $linearray[1]; $timestamp = int($timestamp + 0.5); #round to integer } } #endcase 3 else { if ($linearray[0] =~ /read_bytes|write_bytes/) { $value = $linearray[6]; } else { $value = $linearray[1]; } my $metric_name = $linearray[0]; #push data on array my @outrecord = ($target, $export, $metric_name, $value, $timestamp); push @stats_out, join(' ',@outrecord); } #endcase else } #endswitch }#end foreach stat_array line #return the data return (\@stats_out); }#end sub parse_stats 1;