Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Win32::Perfmon

Status
Not open for further replies.

cody14

MIS
Joined
Aug 11, 2003
Messages
4
Location
US
Hello,

I'm trying to use the Win32::Perfmon module to gather some performance metrics off a windows host. For some reason, i cannot get anything out of the "PhysicalDisk" counter.

When I do a PerfObj->ListCounters("PhysicalDisk"), it always errors out with a "A required argument is invalid or a reserved argument is not NULL".

And I get nothing out of the counter value.

Can anybody please help me figure this out. Here is my code -


**********************************
use Win32::PerfMon;
use strict;

my $ret = undef;
my $err = undef;

my $xxx = Win32::PerfMon->new("\\\\MyServer");

if($xxx != undef)
{
print "\n***List of Performance Counters***\n";
my $Data= $xxx->ListCounters("PhysicalDisk");
foreach my $cntr (@$Data) { print "$cntr\n"; }
# Here is where I get the error

$ret = $xxx->AddCounter("PhysicalDisk", "Avg. Disk Bytes/Read", -1);

if($ret != 0)
{
$ret = $xxx->CollectData();

if($ret != 0)
{
my $secs = $xxx->GetCounterValue("PhysicalDisk", "Avg. Disk Bytes/Read", -1);

if($secs > -1)
{
print "Avg Disk Bytes Read = [$secs]\n";
}
else
{
$err = $xxx->GetErrorText();

print "Failed to get the counter data ", $err, "\n";
}
}
else
{
$err = $xxx->GetErrorText();

print "Failed to collect the perf data ", $err, "\n";
}
}
else
{
$err = $xxx->GetErrorText();

print "Failed to add the counter ", $err, "\n";
}
}
else
{
print "Failed to create the perf object\n";
}

******************************************
 
foreach my $cntr (@$Data)

should this not be

foreach my $cntr (@Data)
?
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
No, it should be (@$Data) because "List Counters" returns a reference to an array. So, $Data is a reference to the array containing the counters for a particular object.
 
In case of PhysicalDisk, you need to provide an instance to obtain data.

So your code must be like
$ret = $xxx->AddCounter("PhysicalDisk", "Avg. Disk Bytes/Read", instance);

Philippe
 
Thanks. I corrected that problem. I'm using "_Total" for instance now.

But I still can't query the counters associated with PhysicalDisk (or) LogicalDisk. Keep getting an error that the specified object is not found on this system.

Any clues on how to resolve this??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top