Permalink
Browse files

Added a dstat_vz plugin for openvz cpu statistics

  • Loading branch information...
dagwieers committed Oct 14, 2006
1 parent 0853108 commit 86a3dbecd3947e97b379e3b3c488bffeee31ca88
Showing with 78 additions and 10 deletions.
  1. +2 −1 ChangeLog
  2. +9 −9 dstat
  3. +67 −0 plugins/dstat_vz.py
View
@@ -1,5 +1,6 @@
-* 0.6.3svn - ... - released ../../2006
+* 0.6.3svn - ... - released 14/10/2006
- Fixed dstat_clock to use localtime() instead of gmtime()
+- Added external plugin dstat_vz for openvz cpu statistics
* 0.6.3 - Amsterdam - released 26/06/2006
- Changed default (silver) color of delimiter to gray
View
18 dstat
@@ -434,15 +434,6 @@ class dstat_cpu(dstat):
self.name = self.name()
self.init(self.vars + ['total',], 6)
- def name(self):
- ret = []
- for name in self.vars:
- if name == 'total':
- ret.append('total cpu usage')
- else:
- ret.append('cpu' + name + ' usage')
- return ret
-
def discover(self, *list):
ret = []
if self.fd:
@@ -455,6 +446,15 @@ class dstat_cpu(dstat):
for item in list: ret.append(item)
return ret
+ def name(self):
+ ret = []
+ for name in self.vars:
+ if name == 'total':
+ ret.append('total cpu usage')
+ else:
+ ret.append('cpu' + name + ' usage')
+ return ret
+
def vars(self):
ret = []
if op.cpulist:
View
@@ -0,0 +1,67 @@
+global string
+import string
+
+#Version: 2.2
+#VEID user nice system uptime idle strv uptime used maxlat totlat numsched
+#302 142926 0 10252 152896388 852779112954062 0 427034187248480 1048603937010 0 0 0
+#301 27188 0 7896 152899846 853267000490282 0 427043845492614 701812592320 0 0 0
+
+class dstat_vz(dstat):
+ def __init__(self):
+ self.format = ('p', 3, 34)
+ self.open('/proc/vz/vestat')
+ self.nick = ('usr', 'sys', 'idl', 'nic')
+ self.discover = self.discover()
+ self.vars = self.vars()
+ self.name = self.name()
+ self.init(self.vars + ['total'], 4)
+ info(1, 'Module dstat_vz is still experimental.')
+
+ def discover(self, *list):
+ ret = []
+ if self.fd:
+ self.fd.seek(0)
+ for line in self.fd.readlines():
+ l = line.split()
+ if len(l) < 6 or l[0] == 'VEID': continue
+ ret.append(l[0])
+ ret.sort()
+ for item in list: ret.append(item)
+ return ret
+
+ def name(self):
+ ret = []
+ for name in self.vars:
+ if name == 'total':
+ ret.append('total ve usage')
+ else:
+ ret.append('ve ' + name + ' usage')
+ return ret
+
+ def vars(self):
+ ret = []
+ if not op.full:
+ list = ('total', )
+ else:
+ list = self.discover
+ for name in list:
+ if name in self.discover + ['total']:
+ ret.append(name)
+ return ret
+
+ def extract(self):
+ self.cn2['total'] = [0, 0, 0, 0]
+ self.fd.seek(0)
+ for line in self.fd.readlines():
+ l = line.split()
+ if len(l) < 6 or l[0] == 'VEID': continue
+ name = l[0]
+ self.cn2[name] = ( long(l[1]), long(l[3]), long(l[4]) - long(l[1]) - long(l[2]) - long(l[3]), long(l[2]) )
+ self.cn2['total'] = ( self.cn2['total'][0] + long(l[1]), self.cn2['total'][1] + long(l[3]), self.cn2['total'][2] + long(l[4]) - long(l[1]) - long(l[2]) - long(l[3]), self.cn2['total'][3] + long(l[2]) )
+ for name in self.vars:
+ for i in range(4):
+ self.val[name][i] = 100.0 * (self.cn2[name][i] - self.cn1[name][i]) / (sum(self.cn2[name]) - sum(self.cn1[name]))
+ if step == op.delay:
+ self.cn1.update(self.cn2)
+
+# vim:ts=4:sw=4

0 comments on commit 86a3dbe

Please sign in to comment.