Python operational Script python Monitoring memory (swap) utilization

Source: Internet
Author: User
Tags snmp

#!/usr/bin/env python#-*-coding=utf-8-*-#Using GPL v2.7#Author: [email protected]#python monitoring Memory (swap) Utilization" "1, the realization principle: obtains the system information through the SNMP protocol, then carries on the corresponding computation and the format, the final output result 2, the special attention: the monitoring machine needs to support SNMP. Yum install-y net-snmp* Installation" "#!/usr/bin/pythonImportOSdefGetallitems (Host, OID): SN1= Os.popen ('snmpwalk-v 2c-c Public'+ Host +' '+ OID). Read (). Split ('\ n') [:-1]        returnSN1defGetswaptotal (Host): Swap_total= Getallitems (Host,'ucd-snmp-mib::memtotalswap.0') [0].split (' ') [3]        returnSwap_totaldefgetswapused (Host): Swap_avail= Getallitems (Host,'ucd-snmp-mib::memavailswap.0') [0].split (' ') [3] Swap_total=getswaptotal (host) swap_used= Str (Round ((float (swap_total)-float (swap_avail)/float (swap_total)) *100, 2)) +'%'        returnswap_useddefGetmemtotal (Host): Mem_total= Getallitems (Host,'ucd-snmp-mib::memtotalreal.0') [0].split (' ') [3]        returnMem_totaldefgetmemused (Host): Mem_total=getmemtotal (host) Mem_avail= Getallitems (Host,'ucd-snmp-mib::memavailreal.0') [0].split (' ') [3] mem_used= Str (Round ((float (mem_total)-float (mem_avail)/float (mem_total)) *100, 2)) +'%'        returnmem_usedif __name__=='__main__': Hosts= ['192.168.10.1','192.168.10.2']        Print "monitoring Memory Usage"         forHostinchhosts:mem_used=getmemused (host) swap_used=getswapused (host)Print '=========='+ Host +'=========='                Print 'mem_used =%-15s swap_used =%-15s'%(mem_used, swap_used)Print

Python operational Script python Monitoring memory (swap) utilization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.