A combination really. I am trying to ascertain two pieces of information: 1.
How much RAM is on a machine (total RAM). 2. How much of it is currently in
use. SWAP/TMP areas are not of interest. With regards to portability, it is
OK if I end up writing different code for different machines (BAD Tal,
BAD!!!). However I do want to keep it as light weight and internal as
possible. This means that any kind of system configuration is out. Also
assume that I will not have control over the target systems.

Thanks,
Tal

PS

THANK YOU EVERYONE WHO CONTRIBUTED AND CONTINUES TO CONTRIBUTE!!!!
Your input is a great help!

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Andrew M. Langmead
Sent: Wednesday, July 14, 2004 11:24 PM
To: 'Boston.PM'
Subject: Re: [Boston.pm] Is there a module to access memory usage?

On Jul 14, 2004, at 3:56 PM, Mike Williams wrote:
> Tal Cohen wrote:
> On Wed, Jul 14, 2004 at 02:05:07PM -0400, Tal Cohen wrote:
>
> >>  I need to write a script that will return how much memory (RAM) is 
> a
> >> system as well as how much of it is being used. Can anyone assist?

One question that I have just to clarify things. Are you wondering how 
much memory the machine has? Or trying to figure out how much you can 
use? Just because the system has it, doesn't mean that it will give it 
to you. On BSD-ish Unix systems, 
<http://search.cpan.org/~jhi/BSD-Resource-1.24/> will let your perl 
program ask the system what might be available to it.

>>> Yeah, I thought of that. I was hoping for a platform independent 
>>> mechanism.
>>> If not, then I can use this type of methodology, but how do I 
>>> account for
>>> Windows based machines?
>
> You could either use `mem` or the Win32::SystemInfo module on windoze.
>
> If you can access /proc/meminfo on the linux (you didn't specify..) 
> boxes you can read that instead of spawning a process.

For asking the system how much memory it has in total, the answer is 
pretty system dependent, and in this sense "Unix" describes a family of 
operating systems, and not single implementation. The "vmstat", which 
is common on Unix doesn't even give you quite what you need, because 
the ordering and spelling of words such as "swapped" and "free" differ 
between implementations.

On Solaris, look at /usr/sbin/prtconf and vmstat.
On Linux, try /usr/bin/free.
On Mac OS X you could use either  /usr/bin/vm_stat or 
/usr/sbin/system_profiler SPHardwareDataType|awk -F: '/Memory/{print 
$2}'

(or
"/usr/sbin/system_profiler -xml SPHardwareDataType"
passed through this XSLT stylesheet)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0" >
     <xsl:output media-type="text/plain" omit-xml-declaration="yes"/>
     <xsl:template match="/">
        <xsl:value-of select="/plist/array/dict/array/dict/key[text() = 
'physical_memory']/following-sibling::string[1]" />
    </xsl:template>
</xsl:stylesheet>

but I mention that only to show a neat way of getting info out of an OS 
X plist and a comparison between XML processing tools and traditional 
unix tools like awk.
)

On BSD systems, there is also a sysctl() system call, but I don't see a 
perl module that interfaces to it.

On windows, this sort of information will be in the registry under the 
HKEY_PERFORMANCE_DATA key.

Chris Devers' recommendation elsewhere on using SNMP is something to 
consider, since it would essentially be taking the platform dependent 
behavior that someone has already written and accessing it with a 
common API.



-- 
"When I write 'Barbie', am I supposed to add the little R in a  circle 
around it?" -- Samantha Langmead, age 7.


"When I write 'Barbie', am I supposed to add the little R in a
circle around it?"" -- Samantha Langmead, age 7.


_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm



_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to