This is the full script using also other WMI Class.
#!/usr/bin/env perl use strict; use warnings; use Win32::OLE; use Data::Dumper; my $class = "Win32_PerfFormattedData_PerfOS_Processor"; my $key = 'Name'; my @properties = qw(PercentIdleTime PercentProcessorTime PercentPr +ivilegedTime PercentUserTime 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' } };
With the WMI class "Win32_PerfRawData_PerfOS_Processor", the value of "PercentProcessorTime" is equal to "PercentProcessorTime", i'm doing something wrong...

In reply to Re: How to GET CPU values from WMI by gulden
in thread How to GET CPU values from WMI by gulden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.