#!/usr/bin/Envpython#-*-coding=utf-8-*-#Using GPL v2.7#Author: [email protected]126. Com#python Monitoring System Load"""1, the realization principle: obtains the system information through the SNMP protocol, then carries on the corresponding computation and the format, the final output result2, special note: SNMP is required on the monitored machine.Yum Install-Y net-snmp*installation"""#!/usr/bin/pythonimport osdef getallitems (Host, OID): SN1= Os.popen ('snmpwalk-v 2c-c Public'+ Host +' '+ OID). Read ().Split('\ n') return SN1 def getload (host,loid): Load_oids='1.3.6.1.4.1.2021.10.1.3.'+Str (loid) return Getallitems (host,load_oids) [0].Split(':')[3] if__name__ = ='__main__': Hosts= ['192.168.10.1','192.168.10.2'] #check_system_load Print'==============system load==============' forHostinchHosts:load1= Getload (Host,1) Load10= Getload (Host,2) Load15= Getload (Host,3) Print'%s Load (1min):%s, Load (10min):%s, Load (15min):%s'% (HOST,LOAD1,LOAD10,LOAD15)
Python Ops script Python monitors system load