I'm Trying go GET CPU values using WMI classes but with no lucky.
- With the class
Win32_PerfFormattedData_PerfOS_Processor, I'm always getting the same values they don't change... - With the WMI class
Win32_PerfRawData_PerfOS_Processor, the value ofPercentProcessorTimeis equal toPercentProcessorTime, something is wrong.
#!/usr/bin/perl -w
use strict;
use warnings;
use Win32::OLE;
use Data::Dumper;
my $class = "Win32_PerfFormattedData_PerfOS_Processor";
my $key = 'Name';
my @properties = qw(PercentIdleTime PercentProcessorTime PercentPrivilegedTimePercentUserTime PercentInterruptTime);
my $wmi = Win32::OLE->GetObject("winmgmts://./root/cimv2")
or die "Failed getobject\n";
my $list, my $v;
$list = $wmi->InstancesOf("$class")
or die "Failed getobject\n";
my $hash;
foreach $v (in $list) {
$hash->{$v->{$key}}->{$_} = $v->{$_} for @properties;
}
print Dumper $hash;
#-------------------
# Using Otehr class
$class = 'Win32_PerfRawData_PerfOS_Processor';
$wmi = Win32::OLE->GetObject("winmgmts://./root/cimv2")
or die "Failed getobject\n";
$list = $wmi->InstancesOf("$class")
or die "Failed getobject\n";
foreach $v (in $list) {
$hash->{$v->{$key}}->{$_} = $v->{$_} for @properties;
}
print Dumper $hash;
OUTPUT:
$VAR1 = {
'0' => {
'PercentPrivilegedTime' => '0',
'PercentIdleTime' => '0',
'PercentInterruptTime' => '0',
'PercentUserTime' => '0',
'PercentProcessorTime' => '100'
},
'_Total' => {
'PercentPrivilegedTime' => '0',
'PercentIdleTime' => '0',
'PercentInterruptTime' => '0',
'PercentUserTime' => '0',
'PercentProcessorTime' => '100'
}
};
$VAR1 = {
'0' => {
'PercentPrivilegedTime' => '15442905808',
'PercentIdleTime' => '2505024948976',
'PercentInterruptTime' => '1866684160',
'PercentUserTime' => '682681648',
'PercentProcessorTime' => '2505024948976'
},
'_Total' => {
'PercentPrivilegedTime' => '15442905808',
'PercentIdleTime' => '2505024948976',
'PercentInterruptTime' => '1866684160',
'PercentUserTime' => '682681648',
'PercentProcessorTime' => '2505024948976'
}
};
-wanduse warningsare redundant in this case.-wis global whereasuse warningspragma can be enabled and disabled within blocks, or byno warnings.