Permalink
Browse files

Renamed DD-WRT plugins as SNMP plugins, and added some more

  • Loading branch information...
dagwieers committed Feb 12, 2014
1 parent 92e09a4 commit af09a0098d6002e55e8c58ae4c9f7144a703da23
View
@@ -0,0 +1,38 @@
+### Author: Dag Wieers <dag$wieers,com>
+
+class dstat_plugin(dstat):
+ def __init__(self):
+ self.name = 'total cpu'
+ self.vars = ( 'usr', 'sys', 'idl' )
+ self.type = 'p'
+ self.width = 3
+ self.scale = 34
+ self.server = os.getenv('DSTAT_SNMPSERVER') or '192.168.1.1'
+ self.community = os.getenv('DSTAT_SNMPCOMMUNITY') or 'public'
+
+ def check(self):
+ try:
+ global cmdgen
+ from pysnmp.entity.rfc3413.oneliner import cmdgen
+ except:
+ raise Exception, 'Needs pysnmp and pyasn1 modules'
+
+ def extract(self):
+ self.set2['usr'] = int(snmpget(self.server, self.community, (1,3,6,1,4,1,2021,11,50,0)))
+ self.set2['sys'] = int(snmpget(self.server, self.community, (1,3,6,1,4,1,2021,11,52,0)))
+ self.set2['idl'] = int(snmpget(self.server, self.community, (1,3,6,1,4,1,2021,11,53,0)))
+# self.set2['usr'] = int(snmpget(self.server, self.community, (('UCD-SNMP-MIB', 'ssCpuRawUser'), 0)))
+# self.set2['sys'] = int(snmpget(self.server, self.community, (('UCD-SNMP-MIB', 'ssCpuRawSystem'), 0)))
+# self.set2['idl'] = int(snmpget(self.server, self.community, (('UCD-SNMP-MIB', 'ssCpuRawIdle'), 0)))
+
+ if update:
+ for name in self.vars:
+ if sum(self.set2.values()) > sum(self.set1.values()):
+ self.val[name] = 100.0 * (self.set2[name] - self.set1[name]) / (sum(self.set2.values()) - sum(self.set1.values()))
+ else:
+ self.val[name] = 0
+
+ if step == op.delay:
+ self.set1.update(self.set2)
+
+# vim:ts=4:sw=4:et
View
@@ -0,0 +1,24 @@
+### Author: Dag Wieers <dag$wieers,com>
+
+class dstat_plugin(dstat):
+ def __init__(self):
+ self.name = 'load avg'
+ self.nick = ('1m', '5m', '15m')
+ self.vars = ('load1', 'load5', 'load15')
+ self.type = 'f'
+ self.width = 4
+ self.scale = 0.5
+ self.server = os.getenv('DSTAT_SNMPSERVER') or '192.168.1.1'
+ self.community = os.getenv('DSTAT_SNMPCOMMUNITY') or 'public'
+
+ def check(self):
+ try:
+ global cmdgen
+ from pysnmp.entity.rfc3413.oneliner import cmdgen
+ except:
+ raise Exception, 'Needs pysnmp and pyasn1 modules'
+
+ def extract(self):
+ map(lambda x, y: self.val.update({x: float(y)}), self.vars, snmpwalk(self.server, self.community, (1,3,6,1,4,1,2021,10,1,3)))
+
+# vim:ts=4:sw=4:et
File renamed without changes.
View
@@ -0,0 +1,34 @@
+### Author: Dag Wieers <dag$wieers,com>
+
+class dstat_plugin(dstat):
+ def __init__(self):
+ self.nick = ('recv', 'send')
+ self.type = 'b'
+ self.cols = 2
+ self.server = os.getenv('DSTAT_SNMPSERVER') or '192.168.1.1'
+ self.community = os.getenv('DSTAT_SNMPCOMMUNITY') or 'public'
+
+ def check(self):
+ try:
+ global cmdgen
+ from pysnmp.entity.rfc3413.oneliner import cmdgen
+ except:
+ raise Exception, 'Needs pysnmp and pyasn1 modules'
+
+ def name(self):
+ return self.vars
+
+ def vars(self):
+ return [ str(x) for x in snmpwalk(self.server, self.community, (1,3,6,1,2,1,2,2,1,2)) ]
+
+ def extract(self):
+ map(lambda x, y, z: self.set2.update({x: (int(y), int(z))}), self.vars, snmpwalk(self.server, self.community, (1,3,6,1,2,1,2,2,1,10)), snmpwalk(self.server, self.community, (1,3,6,1,2,1,2,2,1,16)))
+
+ if update:
+ for name in self.set2.keys():
+ self.val[name] = map(lambda x, y: (y - x) * 1.0 / elapsed, self.set1[name], self.set2[name])
+
+ if step == op.delay:
+ self.set1.update(self.set2)
+
+# vim:ts=4:sw=4:et
File renamed without changes.
File renamed without changes.

0 comments on commit af09a00

Please sign in to comment.