问题
I have a couple of Perl scripts that allow me to monitor remote Windows machinses through WMI. Right now I can check CPU usage, Memory usage, Disk usage and Installed Software. But what if I want to do the same job on a remote Linux machine? Ofcourse there's no WMI so I guess I shall use something similar. I have read on another old StackOverflow question that Linux exposes informations through /proc and /sys but can I query them from a remote computer? And how can I do that exactly in Perl? Is there a dedicated module?
EDIT: Just to clarify, the script MUST be agent-free.
回答1:
Check these :
http://www.net-snmp.org/docs/mibs/host.html
http://www.oidview.com/mibs/0/RFC1213-MIB.html
This will give you memory / disk usage :
snmptable -v1 -c public localhost hrStorageTable
snmptable -v1 -c public localhost .1.3.6.1.2.1.25.2.3
This will give you processor utilisation :
snmptable -v1 -c public localhost hrProcessorTable
snmptable -v1 -c public localhost .1.3.6.1.2.1.25.3.3
Interface Status :
snmptable -v1 -c public localhost ifTable
snmptable -v1 -c public localhost .1.3.6.1.2.1.2.2
If you use rpm-based linux, this will give you installed software :
snmptable -v1 -c public localhost hrSWInstalledTable
snmptable -v1 -c public localhost .1.3.6.1.2.1.25.6.3
You can make this work for .deb flavours of linux :
http://community.zenoss.org/blogs/zenossblog/2009/02/18/tip-of-the-month-snmp-software-inventory-for-debian-and-ubuntu-machines
Sample output of `snmptable -v1 -c public localhost hrProcessorTable`
hrProcessorFrwID hrProcessorLoad
SNMPv2-SMI::zeroDotZero 54
SNMPv2-SMI::zeroDotZero 22
On the box you are querying, does public have read access to .1.3.6.1.2.1.25 ?
You may need to add something like this to your /etc/snmp/snmpd.conf
com2sec monitor default monitor
group monitorGroup v1 monitor
group monitorGroup v2c monitor
view hardware included .1.3.6.1.2.1.25
view hardware included .1.3.6.1.2.1.2
access monitorGroup "" any noauth exact hardware none none
The restart snmpd
Then specify -c monitor
in the commands above instead of -c public
回答2:
I don't think so, perhaps you can use Net::SSH
to access these files, but I think it would make more sense if you install snmp agent and use Net::SNMP
for the purpose.
Monitoring installed software may get trickier, will depend on the linux distribution and will probably be easiest over ssh.
EDIT: Ignore the snmp
part, since you want to be agent-free.
来源:https://stackoverflow.com/questions/8339457/how-to-monitor-remote-linux-machines-and-retrieve-installed-software-in-perl