"Fossies" - the Fresh Open Source Software Archive 
Member "dstat-0.7.4/plugins/dstat_snmp_cpu.py" (17 Jan 2019, 1635 Bytes) of package /linux/privat/dstat-0.7.4.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "dstat_snmp_cpu.py" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
0.7.3_vs_0.7.4.
1 ### Author: Dag Wieers <dag$wieers,com>
2
3 class dstat_plugin(dstat):
4 def __init__(self):
5 self.name = 'total cpu'
6 self.vars = ( 'usr', 'sys', 'idl' )
7 self.type = 'p'
8 self.width = 3
9 self.scale = 34
10 self.server = os.getenv('DSTAT_SNMPSERVER') or '192.168.1.1'
11 self.community = os.getenv('DSTAT_SNMPCOMMUNITY') or 'public'
12
13 def check(self):
14 try:
15 global cmdgen
16 from pysnmp.entity.rfc3413.oneliner import cmdgen
17 except:
18 raise Exception('Needs pysnmp and pyasn1 modules')
19
20 def extract(self):
21 self.set2['usr'] = int(snmpget(self.server, self.community, (1,3,6,1,4,1,2021,11,50,0)))
22 self.set2['sys'] = int(snmpget(self.server, self.community, (1,3,6,1,4,1,2021,11,52,0)))
23 self.set2['idl'] = int(snmpget(self.server, self.community, (1,3,6,1,4,1,2021,11,53,0)))
24 # self.set2['usr'] = int(snmpget(self.server, self.community, (('UCD-SNMP-MIB', 'ssCpuRawUser'), 0)))
25 # self.set2['sys'] = int(snmpget(self.server, self.community, (('UCD-SNMP-MIB', 'ssCpuRawSystem'), 0)))
26 # self.set2['idl'] = int(snmpget(self.server, self.community, (('UCD-SNMP-MIB', 'ssCpuRawIdle'), 0)))
27
28 if update:
29 for name in self.vars:
30 if sum(self.set2.values()) > sum(self.set1.values()):
31 self.val[name] = 100.0 * (self.set2[name] - self.set1[name]) / (sum(self.set2.values()) - sum(self.set1.values()))
32 else:
33 self.val[name] = 0
34
35 if step == op.delay:
36 self.set1.update(self.set2)
37
38 # vim:ts=4:sw=4:et