[svn] r6271 - trunk/tools/dstat/plugins

packagers at lists.rpmforge.net packagers at lists.rpmforge.net
Fri Apr 18 12:12:18 CEST 2008


Author: dag
Date: 2008-04-18 11:12:18 +0100 (Fri, 18 Apr 2008)
New Revision: 6271

Added:
   trunk/tools/dstat/plugins/dstat_net_packets.py
Log:
Added external dstat_net_packets plugin to show the number of packets per inte
rface

Added: trunk/tools/dstat/plugins/dstat_net_packets.py
===================================================================
--- trunk/tools/dstat/plugins/dstat_net_packets.py	                        (rev 0)
+++ trunk/tools/dstat/plugins/dstat_net_packets.py	2008-04-18 10:12:18 UTC (rev 6271)
@@ -0,0 +1,57 @@
+class dstat_net_packets(dstat):
+    def __init__(self):
+        self.format = ('f', 5, 1000)
+        self.open('/proc/net/dev')
+        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.readlines():
+            l = line.replace(':', ' ').split()
+            if len(l) < 17: continue
+            if l[2] == '0' and l[10] == '0': continue
+            name = l[0]
+            if name not in ('lo', 'face'):
+                ret.append(name)
+        ret.sort()
+        for item in list: ret.append(item)
+        return ret
+
+    def vars(self):
+        ret = []
+        if op.netlist:
+            list = op.netlist
+        elif not op.full:
+            list = ('total',)
+        else:
+            list = self.discover
+#           if len(list) > 2: list = list[0:2]
+            list.sort()
+        for name in list:
+            if name in self.discover + ['total', 'lo']:
+                ret.append(name)
+        return ret
+
+    def extract(self):
+        self.cn2['total'] = [0, 0]
+        for line in self.readlines():
+            l = line.replace(':', ' ').split()
+            if len(l) < 17: continue
+            if l[2] == '0' and l[10] == '0': continue
+            name = l[0]
+            if name in self.vars :
+                self.cn2[name] = ( long(l[2]), long(l[10]) )
+            if name not in ('lo','face'):
+                self.cn2['total'] = ( self.cn2['total'][0] + long(l[2]), self.cn2['total'][1] + long(l[10]))
+        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)



More information about the svn-commits mailing list