[svn] r6102 - in trunk/tools/dstat: . plugins

packagers at lists.rpmforge.net packagers at lists.rpmforge.net
Sat Jan 19 05:10:48 CET 2008


Author: dag
Date: 2008-01-19 05:10:46 +0100 (Sat, 19 Jan 2008)
New Revision: 6102

Added:
   trunk/tools/dstat/plugins/dstat_vmknic.py
Modified:
   trunk/tools/dstat/ChangeLog
   trunk/tools/dstat/plugins/dstat_cpufreq.py
Log:
Added VMware ESX dstat_vmknic plugin

Modified: trunk/tools/dstat/ChangeLog
===================================================================
--- trunk/tools/dstat/ChangeLog	2008-01-18 19:21:34 UTC (rev 6101)
+++ trunk/tools/dstat/ChangeLog	2008-01-19 04:10:46 UTC (rev 6102)
@@ -18,6 +18,7 @@
 - Added external dstat_mysql5_* plugins (Frederic Descamps)
 - Reinstated the use of -D md0 which got lost (Peter Rabbitson)
 - Improvement to cpufreq module for SMP systems (Bert de Bruijn)
+- Added VMware ESX dstat_vmknic plugin (Bert de Bruijn)
 
 * 0.6.6 - Unemployed - released 28/04/2007
 - Removed SwapCached from the Cached counter (Dbt 418326, Peter Rabbitson)

Modified: trunk/tools/dstat/plugins/dstat_cpufreq.py
===================================================================
--- trunk/tools/dstat/plugins/dstat_cpufreq.py	2008-01-18 19:21:34 UTC (rev 6101)
+++ trunk/tools/dstat/plugins/dstat_cpufreq.py	2008-01-19 04:10:46 UTC (rev 6102)
@@ -13,12 +13,12 @@
         self.name = 'frequency'
         self.format = ('p', 4, 34)
 #       self.vars = os.listdir('/sys/devices/system/cpu/')
+#       self.nick = [string.lower(name) for name in self.vars]
         self.vars = []
-        for name in glob.glob('/sys/devices/system/cpu/cpu?'):
-            self.vars.append(os.path.basename(name))
-#       self.nick = [string.lower(name) for name in self.vars]
         self.nick = []
-        for name in self.vars:
+        for name in glob.glob('/sys/devices/system/cpu/cpu[0-9]*'):
+            name = os.path.basename(name)
+            self.vars.append(name)
             self.nick.append(string.lower(name))
         self.init(self.vars, 1)
 

Added: trunk/tools/dstat/plugins/dstat_vmknic.py
===================================================================
--- trunk/tools/dstat/plugins/dstat_vmknic.py	                        (rev 0)
+++ trunk/tools/dstat/plugins/dstat_vmknic.py	2008-01-19 04:10:46 UTC (rev 6102)
@@ -0,0 +1,83 @@
+### VMware ESX kernel vmknic stats
+### Displays VMkernel port statistics on VMware ESX servers
+###
+### Authority: bert+dstat at debruijn.be
+
+# NOTE TO USERS: command-line plugin configuration is not yet possible, so I've
+# "borrowed" the -N argument.
+# EXAMPLES:
+# # dstat -M vmknic -N vmk1
+# You can even combine the Linux and VMkernel network stats (just don't just "total").
+# # dstat -M vmknic -n -N vmk0,vswif0
+# NB Data comes from /proc/vmware/net/tcpip/ifconfig
+
+class dstat_vmknic(dstat):
+	def __init__(self):
+		self.name = 'vmknic'
+		self.format = ('f', 5, 1024)
+		self.open('/proc/vmware/net/tcpip/ifconfig')
+		self.nick = ('recv', 'send')
+		self.discover = self.discover()
+		self.vars = self.vars()
+		self.name = ['net/'+name for name in self.vars]
+		self.init(self.vars + ['total',], 2)
+
+	def discover(self, *list):
+		ret = []
+		for line in self.fd[0].readlines():
+			l = line.replace(' /','/').split()
+			if len(l) != 12: continue
+			if l[2][:5] == '<Link': continue
+			if ','.join(l) == 'Name,Mtu/TSO,Network,Address,Ipkts,Ierrs,Ibytes,Opkts,Oerrs,Obytes,Coll,Time': continue
+			if l[0] == 'lo0': continue
+			if l[0] == 'Usage:': continue
+			ret.append(l[0])
+		ret.sort()
+		for item in list: ret.append(item)
+		return ret
+
+	def vars(self):
+		ret = []
+		if op.netlist:
+			list = op.netlist
+		else:
+			list = self.discover
+			list.sort()
+		for name in list:
+			if name in self.discover + ['total']:
+				ret.append(name)
+		return ret
+
+	def check(self): 
+		info(1, 'The vmknic module is an EXPERIMENTAL module.')
+		ret = True
+		try:
+			os.listdir('/proc/vmware')
+		except:
+			ret = False
+			raise Exception, 'Needs VMware ESX'
+		return ret
+
+	def extract(self):
+		self.cn2['total'] = [0, 0]
+		for line in self.readlines():
+			l = line.replace(' /','/').split()
+			if len(l) != 12: continue
+			if l[2][:5] == '<Link': continue
+			if ','.join(l) == 'Name,Mtu/TSO,Network,Address,Ipkts,Ierrs,Ibytes,Opkts,Oerrs,Obytes,Coll,Time': continue
+			if l[0] == 'Usage:': continue
+			name = l[0]
+			if name in self.vars:
+				self.cn2[name] = ( long(l[6]), long(l[9]) )
+			if name != 'lo0':
+				self.cn2['total'] = ( self.cn2['total'][0] + long(l[6]), self.cn2['total'][1] + long(l[9]) )
+		if update:
+			for name in self.cn2.keys():
+				self.val[name] = (
+					(self.cn2[name][0] - self.cn1[name][0]) * 1.0 / tick,
+					(self.cn2[name][1] - self.cn1[name][1]) * 1.0 / tick,
+				)
+		if step == op.delay:
+			self.cn1.update(self.cn2)
+
+# vim:ts=4:sw=4



More information about the svn-commits mailing list