AnsweredAssumed Answered

Need help on Diskstats and device stats perl script.

Question asked by Nkota on Jun 26, 2012
Latest reply on Jun 26, 2012 by Nkota
Hello All,

Can you please help me on the below issue.

We are trying to generate the metrics according the below script, When i executed " iostat -d | grep tps | wc –l “ result is 1.
Depending on this we need to get diff set of iostat metrics., but I guess the perl script is not considering the condition here(even for both null value and 1 it’s producing the metrics which are
Defined for Null value.)

Script:

!/bin/perl
#############################################################
# Linux Disk Stats
# =========================
# Copyright (C) 2011
# =========================
# Description:
# The program will create two nodes: DEVICE, which
# provides metrics by device name; Disk, which provides metrics by mount point.
# =========================
# Usage: perl linDiskStats.pl [filesystem1 /filesystem2 ...]
#
# Adding a filesystem to the commandline will cause the program to only report
# metrics for the specified device and/or disk.
#############################################################
use FindBin;
use lib ("$FindBin::Bin", "$FindBin::Bin/lib/perl", "$FindBin::Bin/../lib/perl");
use Wily::PrintMetric;

use strict;


# get the mounted disks specified on the command line
my $mountedDisksRegEx = '.'; # default is match all
if (scalar(@ARGV) > 0) {
$mountedDisksRegEx = join('|', @ARGV);
}

# iostat command for Linux disks
my $iostatCommand = 'iostat -d';
# Get the device stats
my @iostatResults = `$iostatCommand`;
# Get rid of the header lines for each command
@iostatResults = @iostatResults[4..$#iostatResults];
# Output on RHEL:
#Linux 2.6.18-128.el5 (xxxxx) 03/22/2011
## relevant data using metrics

my $tps_value = 'iostat -d | grep tps |wc -l';
print $main::tps_value, "\n";

if ( $tps_value == '') {
foreach my $isline (@iostatResults) {
chomp $isline; # remove trailing new line
my @deviceStats = split /\s+/, $isline;
my $device = $deviceStats[0];

# now, check to see if the user specified this device on the command
# line.
next if $device !~ /$mountedDisksRegEx/i;

# report iostats
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => '%util',
value => int ($deviceStats[11]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'svctm',
value => int ($deviceStats[10]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'await',
value => int ($deviceStats[9]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'avgqu-sz',
value => int ($deviceStats[8]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',value => int ($deviceStats[6]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'rsec/s',
value => int ($deviceStats[5]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'w/s',
value => int ($deviceStats[4]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'r/s',
value => int ($deviceStats[3]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'wrqm/s',
value => int ($deviceStats[2]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'rrqm/s',
value => int ($deviceStats[1]),
);
}

}

if ( $tps_value == 1 ) {
foreach my $isline (@iostatResults) {
chomp $isline; # remove trailing new line
my @deviceStats = split /\s+/, $isline;
my $device = $deviceStats[0];

# now, check to see if the user specified this device on the command );
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'Blk_read',
value => int ($deviceStats[4]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'Blk_wrtn/s',
value => int ($deviceStats[3]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'Blk_read/s',
value => int ($deviceStats[2]),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Device',
subresource => $device,
name => 'tps',
value => int ($deviceStats[1]),
);
}

}

# df command for RHEL
my $dfCommand = 'df -k';
# Get the disk stats
my @dfResults = `$dfCommand`;
# Get rid of the header lines for each command
@dfResults = @dfResults[1..$#dfResults];
# Output on RHEL:
#Filesystem 1K-blocks Used Available Use% Mounted on
#/dev/mapper/VolGroup00-LogVol00
# 5078656 455620 4360892 10% /
#/dev/mapper/VolGroup00-lv_var
# 2031440 251980 1674604 14% /var
#/dev/mapper/VolGroup00-lv_opt
# 2031440 852272 1074312 45% /opt
#/dev/mapper/VolGroup00-lv_home
# 2031440 97196 1829388 6% /home
#/dev/mapper/VolGroup00-lv_tmp
1236864 469836 703136 41% /tmp
#/dev/mapper/VolGroup00-lv_usr
# 4411048 3083976 1100996 74% /usr
#/dev/mapper/VolGroup00-lv_audit
# 63461 5403 54782 9% /audit
#/dev/sda1 101086 15564 80303 17% /boot
#tmpfs 2987952 0 2987952 0% /dev/shm
#/dev/mapper/app_vg_uat-lv_http

my $i = 0;
my $h = 0;
my @holdVal;
foreach my $dfLine (@dfResults) {
chomp $dfLine; # remove trailing new line
my @dfStats = split /\s+/, $dfLine;
my $fsName = $dfStats[0];
my $diskName = $dfStats[5];

# check if line is just the filesystem; if so, hold temporarily until next loop
if (length($diskName) == 0 ) {
$holdVal[$i] = $dfStats[0];
$h++;
$i++;
next;
}

# now, check to see if the user specified this disk on the command
# line.
next if $diskName !~ /$mountedDisksRegEx/i;

# report the df stats
# Just print the Used Disk Space as a Percent and in Megabytes
# chop gets rid of '%' in the capacity
chop $dfStats[4];
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Filesystem',
subresource => $diskName,
name => 'Used Disk Space (%)',
value => $dfStats[4],
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Filesystem',
subresource => $diskName,
name => 'Free Disk Space (MB)',
value => int ($dfStats[3] / 1024),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Filesystem',
subresource => $diskName,
name => 'Used Disk Space (MB)',
value => int ($dfStats[2] / 1024),
);
Wily::PrintMetric::printMetric( type => 'IntCounter',
resource => 'STORAGE|Filesystem',
subresource => $diskName,
name => 'Total Disk Space (MB)',
value => int ($dfStats[1] / 1024),
);
if ($h == 1) {
Wily::PrintMetric::printMetric( type => 'StringEvent',
resource => 'STORAGE|Filesystem',
subresource => $diskName,
name => 'Filesystem',
value => $holdVal[$i - 1],
);
} else {
Wily::PrintMetric::printMetric( type => 'StringEvent',
resource => 'STORAGE|Filesystem',
subresource => $diskName,
name => 'Filesystem',
value => $dfStats[0],
);
}
$h=0;
$i++;
}


Can you please help me on this issue?

Thanks,
N

Outcomes