hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
package HotSaNICmod::OSdep;
sub version {
($VERSION = '$Revision: 1.14 $') =~ s/.*(\d+\.\d+).*/$1/;
return "$^O.pm $VERSION";
}
sub sample {
my %args=@_;
my %DEVS;
foreach (@{$args{DEV}}) {
my ($device,$name)=split /,/;
$name =~ s/\//_/g;
$name =~ s/^_//g;
$DEVS{$device}=$name;
}
######################################################################
#
# KERNEL 2.2 CODE
#
if ($args{KERNEL} eq "2.2") {
# disk 1494755 377215 221577 144318
# disk_rio 564538 286941 151189 77490
# disk_wio 930217 90274 70388 66828
# disk_rblk 1129538 573882 302378 154980
# disk_wblk 1860536 180548 140776 133656
open FILE,"/proc/stat";
while (<FILE>) {
(undef,@readacc)=split if /disk_rio/;
(undef,@writeacc)=split if /disk_wio/;
(undef,@readblk)=split if /disk_rblk/;
(undef,@writeblk)=split if /disk_wblk/;
}
close FILE;
$device=0;
while (@readacc) {
$racc=shift @readacc;
$wacc=shift @writeacc;
$rblk=shift @readblk;
$wblk=shift @writeblk;
$blocksize=512;
HotSaNICmod::do_rrd($device,"U",time,$racc,$blocksize*$rblk,$wacc,$blocksize*$wblk);
$device++;
}
}
######################################################################
#
# KERNEL 2.4 CODE
#
elsif ($args{KERNEL} eq "2.4") {
if ( ($args{"SOURCE"} eq "partitions") or ($args{"SOURCE"} eq "diskstats") ) {
# major minor #blocks name rio rmerge rsect ruse wio wmerge wsect wuse running use aveq
# 8 16 8958120 sdb 285 6274 52274 17480 9 3 96 0 0 2750 17480
# 34 0 80043264 ide/host2/bus1/target0/lun0/disc 2368478 1209106 28620666 20372050 2689313 9234680 95391960 22393060 0 26560040 42765110
open FILE,"/proc/".$args{SOURCE};
$_=<FILE>; # strip header
while (<FILE>) {
chomp;
if ($_ ne "") {
($major,$minor,undef,undef,$rio,undef,$rsect,undef,$wio,undef,$wsect,undef) = split;
$device=$major."_".$minor;
if (defined $DEVS{$device}) {
my $sectsize=512;
HotSaNICmod::do_rrd($device,"U",time,$rio,$sectsize*$rsect,$wio,$sectsize*$wsect);
}
}
}
close FILE;
}
else {
# disk_io: (8,0):(985065,41330,436455,943735,13075448) (8,1):(12563,6363,333604,6200,167608) (8,2):(11194,11012,90140,182,3160)
open FILE,"/proc/stat";
while (<FILE>) { (undef,@stats)=split if /disk_io/; }
close FILE;
foreach my $entry (@stats) {
$entry=~ s/[()]//g;
$entry=~ s/:/,/g;
my ($num1,$num2,undef,$racc,$rblk,$wacc,$wblk)=split /,/,$entry;
$device=$num1."_".$num2;
if (defined $DEVS{$device}) {
$blocksize=512;
HotSaNICmod::do_rrd($device,"U",time,$racc,$blocksize*$rblk,$wacc,$blocksize*$wblk);
}
}
}
}
######################################################################
#
# KERNEL 2.6 CODE
#
elsif ($args{KERNEL} eq "2.6") {
# diskstats: major minor name rio rmerge rsect ruse wio wmerge wsect wuse running use aveq
# 3 64 hdb 524233 57272 91269016 6239457 233008 24726677 199678904 73630251 0 6331127 79891245
# 3 64 hdb 524298 57274 91284864 6239742 233012 24726679 199678952 73630252 0 6331403 79891531
open FILE,"/proc/diskstats";
while ($entry = <FILE>) {
$entry =~ s/^\s*//; # strip leading whitespaces
my ($major,$minor,undef,$racc,undef,$rsect,undef,$wacc,undef,$wsect)=split(/\s+/,$entry);
$device=$major."_".$minor;
if (defined $DEVS{$device}) {
my $sectsize=512;
HotSaNICmod::do_rrd($device,"U",time,$racc,$rsect*$sectsize,$wacc,$wsect*$sectsize);
}
}
close FILE;
}
}
1;