import netsnmp
CPU_TYPE = '.1.3.6.1.2.1.25.3.1.3'
CORE_USAGE = '.1.3.6.1.2.1.25.3.3.1.2.' # +ID
CORE_NAME = '.1.3.6.1.2.1.25.3.2.1.3.' # +ID
def get_cpu_usage(host,version=2,community='public'):
s = netsnmp.Session(DestHost=host, Version=version, Community=community)
vars = netsnmp.VarList(netsnmp.Varbind('.1.3.6.1.2.1.25.3.2.1.1'))
#count resouces
resources = s.walk(vars)
cpu_res = {}
for res in resources:
oid = ".1.3.6.1.2.1.25.3.2.1.2.%s" % res
vars = netsnmp.VarList(netsnmp.Varbind(oid))
value = s.get(vars)
#print oid, value
if value[0] == CPU_TYPE:
oid = CORE_USAGE + res
vars = netsnmp.VarList(netsnmp.Varbind(oid))
value = s.get(vars)
print "CORE:%s, Usage:%s" % (res, value[0])
cpu_res[res] = int(value[0])
return cpu_res
print get_cpu_usage('192.168.1.29')