#!perl
use Win32::OLE qw(in with);
$true = 1;
$false = 0;
$jid = $ARGV[0];
if (!$ARGV[0])
{
print "Job ID>";
chomp($jid = ());
}
# Search Resources for Nodes Associated with this Job ID
$found = $false;
open(NODES, "ccusage |");
while()
{
chop;
($host, $jobid) = (split())[0,3];
if ($jobid == $jid) { push(@Nodes,$host); $found = $true; }
}
close(NODES);
if (!$found) { print "ERROR: $jid is not currently running\n"; exit; }
$WMI = Win32::OLE->new('WbemScripting.SWbemLocator') ||
die "Cannot access WMI on local machine: ", Win32::OLE->LastError;
for(;;)
{
foreach $host (@Nodes)
{
print "\n$host\n";
$Services = $WMI->ConnectServer($host) ||
die "Cannot access WMI on remote machine: ", Win32::OLE->LastError;
# Gather Memory Information
$os_set = $Services->InstancesOf("Win32_OperatingSystem");
foreach $os (in($os_set))
{
$os_totalmem = $os->{'TotalVisibleMemorySize'};
$os_freemem = $os->{'FreePhysicalMemory'};
$os_totalvirtmem = $os->{'TotalVirtualMemorySize'};
$os_freevirtmem = $os->{'FreeVirtualMemory'};
}
print "Total Memory: $os_totalmem\n";
print "Free Memory: $os_freemem\n";
print "Memory Utilization: ",
int(100 * (($os_totalmem - $os_freemem)/$os_totalmem)),"\%\n";
print "Total Virtual Memory: $os_totalvirtmem\n";
print "Free Virtual Memory: $os_freevirtmem\n";
print "Virtual Memory Utilization: ",
int(100 * (($os_totalvirtmem - $os_freevirtmem)/$os_totalvirtmem)),"\%\n";
sleep 1;
} # for each node to monitor
} # for ever
And the output from this one:
C:\WIP\WMIExamples\Example 3 - Text Memory Monitor>memory_watch.pl
Job ID>77772
ctc017.tc.cornell.edu
Total Memory: 4062760
Free Memory: 3790724
Memory Utilization: 6%
Total Virtual Memory: 12156700
Free Virtual Memory: 11791320
Virtual Memory Utilization: 3%
ctc018.tc.cornell.edu
Total Memory: 4062760
Free Memory: 3789912
Memory Utilization: 6%
Total Virtual Memory: 12156696
Free Virtual Memory: 11791872
Virtual Memory Utilization: 3%
ctc019.tc.cornell.edu
Total Memory: 4062760
Free Memory: 3793416
Memory Utilization: 6%
Total Virtual Memory: 12156692
Free Virtual Memory: 11795704
Virtual Memory Utilization: 2%
ctc022.tc.cornell.edu
Total Memory: 4062760
Free Memory: 3798028
Memory Utilization: 6%
Total Virtual Memory: 12156700
Free Virtual Memory: 11800696
Virtual Memory Utilization: 2%
ctc026.tc.cornell.edu
Total Memory: 4062760
Free Memory: 3818760
Memory Utilization: 6%
Total Virtual Memory: 12156704
Free Virtual Memory: 11825868
Virtual Memory Utilization: 2%
ctc017.tc.cornell.edu
Total Memory: 4062760
Free Memory: 3790776
Memory Utilization: 6%
Total Virtual Memory: 12156700
Free Virtual Memory: 11791316
Virtual Memory Utilization: 3%
ctc018.tc.cornell.edu
Total Memory: 4062760
Free Memory: 3789924
Memory Utilization: 6%
Total Virtual Memory: 12156696
Free Virtual Memory: 11791876
Virtual Memory Utilization: 3%
ctc019.tc.cornell.edu
Total Memory: 4062760
Free Memory: 3793880
Memory Utilization: 6%
Total Virtual Memory: 12156692
Free Virtual Memory: 11796144
Virtual Memory Utilization: 2%
ctc022.tc.cornell.edu
Total Memory: 4062760
Free Memory: 3798052
Memory Utilization: 6%
Total Virtual Memory: 12156700
Free Virtual Memory: 11800692
Virtual Memory Utilization: 2%
ctc026.tc.cornell.edu
Total Memory: 4062760
Free Memory: 3818768
Memory Utilization: 6%
Total Virtual Memory: 12156704
Free Virtual Memory: 11825852
Virtual Memory Utilization: 2%