Link to home
Start Free TrialLog in
Avatar of toooki
toooki

asked on

Perl program to obtain a machine's memory usage

I am trying to use the below code to obtain the memory usage (used, unused, etc) of a machine. I need to use CPAN module (not system command like "free -m").

#myprog.pl=====
#!/usr/bin/perl
use Sys::MemInfo qw(totalmem freemem totalswap);
print "total memory: ".(&totalmem / 1024)."\n";
print "free memory:  ".(&freemem / 1024)."\n";
print "total swap: ".(&totalswap / 1024)."\n";
print "free swap:  ".(Sys::MemInfo::get("freeswap") / 1024)."\n";
#======

But I get error that the module Sys::MemInfo does not exist. Could you please assist me to resolve the issue. It is urgent. Thank you.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toooki
toooki

ASKER

Thank you. When I try the command 'cpan install Sys::MemInfo' , I get all kind of errors. I could not follow the alternatives. cpan App::cpanminus is this a command on the command line -- did not work. Thank you.
What kinds of errors?
toooki, please answer the following questions

1) Which version of Perl are you using?
2) On what platform are you running Perl?
3) What kind of errors are you getting? Please provide a screenshot of the terminal / errors
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Split:
-- ozo (http:#a40662893)
-- Shaji (http:#a40663295)


If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

suhasbharadwaj
Experts-Exchange Cleanup Volunteer