Skip to main content
added 37 characters in body
Source Link
Alan Haggai Alavi
  • 74.6k
  • 19
  • 105
  • 129
  1. With the class "Win32_PerfFormattedData_PerfOS_Processor"Win32_PerfFormattedData_PerfOS_Processor, I'm always getting the same values they don't change...
  2. With the WMI class "Win32_PerfRawData_PerfOS_Processor"Win32_PerfRawData_PerfOS_Processor, the value of "PercentProcessorTime"PercentProcessorTime is equal to "PercentProcessorTime"PercentProcessorTime, something is wrong...

#!/usr/bin/perl -w use strict; use warnings;

 
#!/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;
  1. With the class "Win32_PerfFormattedData_PerfOS_Processor", I'm always getting the same values they don't change...
  2. With the WMI class "Win32_PerfRawData_PerfOS_Processor", the value of "PercentProcessorTime" is equal to "PercentProcessorTime", 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;
  1. With the class Win32_PerfFormattedData_PerfOS_Processor, I'm always getting the same values they don't change...
  2. With the WMI class Win32_PerfRawData_PerfOS_Processor, the value of PercentProcessorTime is equal to PercentProcessorTime, 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;
Source Link
gulden PT
  • 411
  • 5
  • 13

Get WMI CPU Values using Perl

I'm Trying go GET CPU values using WMI classes but with no lucky.

  1. With the class "Win32_PerfFormattedData_PerfOS_Processor", I'm always getting the same values they don't change...
  2. With the WMI class "Win32_PerfRawData_PerfOS_Processor", the value of "PercentProcessorTime" is equal to "PercentProcessorTime", 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'
                      }
        };