Works for me...

use strict; use warnings; use Win32::PerfLib (); my $server = ""; { my %counters; my $process_group_id; my $handle_count_counter_id; my %perf_data; my $perflib; my $process_instances; my $total_instance; my $total_counters; my $total_handle_count_counter; my $total_handle_count; Win32::PerfLib::GetCounterNames($server, \%counters); foreach (keys(%counters)) { if ($counters{$_} eq 'Process') { $process_group_id = $_; } if ($counters{$_} eq 'Handle Count') { $handle_count_counter_id = $_; } } $perflib = new Win32::PerfLib($server); $perflib->GetObjectList($process_group_id, \%perf_data); $perflib->Close(); $process_instances = $perf_data{'Objects'}->{$process_group_id}->{' +Instances'}; foreach (keys(%$process_instances)) { if ($process_instances->{$_}->{'Name'} eq '_Total') { $total_instance = $process_instances->{$_}; last; } } $total_counters = $total_instance->{'Counters'}; foreach (keys(%$total_counters)) { if ($total_counters->{$_}->{'CounterNameTitleIndex'} == $handle_ +count_counter_id) { $total_handle_count_counter = $total_counters->{$_}; last; } } $total_handle_count = $total_handle_count_counter->{'Counter'}; print($total_handle_count, $/); }

OT rant:

ug! It would be nice if we could say
$perfdata{'Objects'}{'Process'}{'Instances'}{'_Total'}[0]{'Counters'}{'Handle Count'}{'Counter'}
instead of
$perfdata->{'Objects'}{some random number}{'Instances'}{some random number}{'Counters'}{some random number}{'Counter'}
Each "some random number" requires an annoying and unneccesary loop.


In reply to Re^3: Getting Total Object Handles in Windows by ikegami
in thread Getting Total Object Handles in Windows by slloyd

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.