Home > Archive > PERL Miscellaneous > October 2004 > Get Win32 Total Physical Memory & Available Physical Memory stats
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Get Win32 Total Physical Memory & Available Physical Memory stats
|
|
| Karim Wall 2004-10-27, 3:56 am |
| Hello. I've checked CPAN and have searched the net as well and have not been
able to find a Perl script or module that will get me the Total Physical
Memory and Available Physical Memory stats for a remote system, much less an
NT utility. The one utility I found, SYSTEMINFO.EXE can't be used to get
info on an NT4 system and I have plenty of them. I've found some scripts
that provide task mgr types of info but that's too much.
Any ideas?
Thanks,
Karim
| |
| A. Sinan Unur 2004-10-27, 3:56 am |
| "Karim Wall" <mirak63@carolina.rr.com> wrote in
news:UNqdncAz8fvrY-PcRVn-sA@giganews.com:
> Hello. I've checked CPAN and have searched the net as well and have
> not been able to find a Perl script or module that will get me the
> Total Physical Memory and Available Physical Memory stats for a remote
> system, much less an NT utility.
Don't know about pulling information from remote machines but does:
http://tinyurl.com/5rl7e
help?
Sinan.
| |
| Thomas Kratz 2004-10-27, 8:56 am |
| Karim Wall wrote:
> Hello. I've checked CPAN and have searched the net as well and have not been
> able to find a Perl script or module that will get me the Total Physical
> Memory and Available Physical Memory stats for a remote system, much less an
> NT utility. The one utility I found, SYSTEMINFO.EXE can't be used to get
> info on an NT4 system and I have plenty of them. I've found some scripts
> that provide task mgr types of info but that's too much.
>
> Any ideas?
>
> Thanks,
> Karim
>
>
An example how to get at WMI information with Win32::OLE can be found here:
http://tinyurl.com/5f2tn
You have to use Win32::OLE as
use Win32::OLE qw/in/;
and change the object creation to
my $wmi = Win32::OLE->GetObject(
" winmgmts:{impersonationLevel=impersonate
,(security)}\\\\<machine>"
);
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
| |
|
| Karim Wall wrote:
> Hello. I've checked CPAN and have searched the net as well and have not been
> able to find a Perl script or module that will get me the Total Physical
> Memory and Available Physical Memory stats for a remote system, much less an
> NT utility. The one utility I found, SYSTEMINFO.EXE can't be used to get
> info on an NT4 system and I have plenty of them. I've found some scripts
> that provide task mgr types of info but that's too much.
>
> Any ideas?
>
> Thanks,
> Karim
>
>
Try Perl's Win32::OLE and MS's WMI:
use strict;
use warnings;
use Win32::OLE qw[in];
my $host = $ARGV[0] || '.';
my $wmi = Win32::OLE->GetObject( "winmgmts://$host/root/cimv2" )
or die Win32::FormatMessage( Win32::OLE::LastError() );
my %instances = (
Win32_PhysicalMemory => \&get_pmem,
Win32_PerfRawData_PerfOS_Memory => \&get_amem,
);
my $out;
foreach ( keys %instances ) {
my $class = $wmi->InstancesOf( $_ );
$out .= $instances{ $_ }->( $class );
}
print $out;
sub get_pmem {
my $class = shift;
my $total;
$total += $_->{Capacity} foreach in($class);
return "Physical Memory: $total\n";
}
sub get_amem {
my $class = shift;
my $amem;
$amem .= join ' ', $_->{AvailableBytes} foreach in($class);
return "Available Memory: $amem\n";
}
Good resources:
Basics of using Win32:OLE & WMI:
http://www.ntmag.com/WindowsScripti...9828/19828.html
WMI Win32 clases:
http://msdn.microsoft.com/library/d...n32_classes.asp
HTH - keith
| |
|
|
"ko" <kuujinbo@hotmail.com> wrote in message
news:2u9g2sF27lsdpU1@uni-berlin.de...
> Karim Wall wrote:
>
> Try Perl's Win32::OLE and MS's WMI:
>
> use strict;
> use warnings;
> use Win32::OLE qw[in];
>
> my $host = $ARGV[0] || '.';
> my $wmi = Win32::OLE->GetObject( "winmgmts://$host/root/cimv2" )
> or die Win32::FormatMessage( Win32::OLE::LastError() );
>
> my %instances = (
> Win32_PhysicalMemory => \&get_pmem,
> Win32_PerfRawData_PerfOS_Memory => \&get_amem,
> );
>
> my $out;
> foreach ( keys %instances ) {
> my $class = $wmi->InstancesOf( $_ );
> $out .= $instances{ $_ }->( $class );
> }
> print $out;
>
> sub get_pmem {
> my $class = shift;
> my $total;
> $total += $_->{Capacity} foreach in($class);
> return "Physical Memory: $total\n";
> }
>
> sub get_amem {
> my $class = shift;
> my $amem;
> $amem .= join ' ', $_->{AvailableBytes} foreach in($class);
> return "Available Memory: $amem\n";
> }
>
>
> Good resources:
>
> Basics of using Win32:OLE & WMI:
> http://www.ntmag.com/WindowsScripti...9828/19828.html
>
> WMI Win32 clases:
> http://msdn.microsoft.com/library/d...n32_classes.asp
>
> HTH - keith
I noticed "my $host = $ARGV[0]". I assumed that this was a target remote
server. However, I get "Too many parameters" error when I run SCRIPT.PL
SERVERNAME. Is this what you intended?
Thanks,
Karim
| |
|
| KWall wrote:
> "ko" <kuujinbo@hotmail.com> wrote in message
[snip code]
> I noticed "my $host = $ARGV[0]". I assumed that this was a target remote
> server. However, I get "Too many parameters" error when I run SCRIPT.PL
> SERVERNAME. Is this what you intended?
> Thanks,
> Karim
>
Yes, that's how it works. Don't know why you're having problems, check
perldiag against the exact error you're getting. Tested with ActiveState
Perl 5.8.4, Win32::OLE 0.1701 and Cygwin Perl 5.8.2, Win32::OLE 0.1502.
Try hard-coding the hostname/IP and see if that works. You said that you
have plenty of hosts to query, so I assume that you're either going to
get a list of hosts from a text file or database lookup anyway.
HTH - keith
|
|
|
|
|