Skip to content

Commit

Permalink
Added --cpu-use plugin with onlu CPU usage per CPU (Christian Neukirc…
Browse files Browse the repository at this point in the history
…hen)
  • Loading branch information
dagwieers committed Aug 19, 2014
1 parent 7dc74cb commit d5ae649
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Print decimal values as decimals where possible (so 0 instead of 0.0)
- Added external dstat_ddwrt_* plugins using DD-WRT counters using SNMP infrastructure
- Fixed improper process names using spaces instead of \0 (Edward Smith)
- Added --cpu-use plugin with onlu CPU usage per CPU (Christian Neukirchen)

* 0.7.2 - Real soon now - release 15/06/2010
- Added external dstat_disk_tps plugin to show transactions per second
Expand Down
28 changes: 28 additions & 0 deletions dstat
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,34 @@ class dstat_cpu(dstat):
if step == op.delay:
self.set1.update(self.set2)

class dstat_cpu_use(dstat_cpu):
def __init__(self):
self.name = 'cpu usage'
self.type = 'p'
self.width = 3
self.scale = 34
self.open('/proc/stat')
self.cols = 7
if not op.cpulist:
self.vars = [ str(x) for x in range(cpunr) ]

def extract(self):
for l in self.splitlines():
if len(l) < 9: continue
for name in self.vars:
if l[0] == 'cpu' + name or ( l[0] == 'cpu' and name == 'total' ):
self.set2[name] = ( long(l[1]) + long(l[2]), long(l[3]), long(l[4]), long(l[5]), long(l[6]), long(l[7]), long(l[8]) )

for name in self.vars:
if sum(self.set2[name]) > sum(self.set1[name]):
self.val[name] = 100.0 - 100.0 * (self.set2[name][2] - self.set1[name][2]) / (sum(self.set2[name]) - sum(self.set1[name]))
else:
self.val[name] = 0
# print >>sys.stderr, "Error: tick problem detected, this should never happen !"

if step == op.delay:
self.set1.update(self.set2)

class dstat_cpu_adv(dstat_cpu):
def __init__(self):
self.nick = ( 'usr', 'sys', 'idl', 'wai', 'hiq', 'siq', 'stl' )
Expand Down

0 comments on commit d5ae649

Please sign in to comment.