]> git.ipfire.org Git - oddments/collecty.git/commitdiff
interrupts: Collect data for all interrupts
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Sep 2020 14:37:49 +0000 (14:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Sep 2020 14:37:49 +0000 (14:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/collecty/plugins/base.py
src/collecty/plugins/interrupts.py

index 16bc0e4da3827ba0ddcd86202c85eaf03e099014..3a7fd5eec98a16f2ddb0b561f608010adc04f849 100644 (file)
@@ -263,7 +263,7 @@ class Object(object):
                self.create()
 
        def __repr__(self):
-               return "<%s>" % self.__class__.__name__
+               return "<%s %s>" % (self.__class__.__name__, self.id)
 
        def __lt__(self, other):
                return self.id < other.id
index b8cacd1e46d8cce544cfe5f45575575b48b6d605..bff704d0a45d8c181932f31a10cdd5233f9cec74 100644 (file)
@@ -19,6 +19,7 @@
 #                                                                             #
 ###############################################################################
 
+import os
 import re
 
 from . import base
@@ -55,23 +56,35 @@ class GraphTemplateSystemInterrupts(base.GraphTemplate):
                return _("System Interrupts/s")
 
 
-class SystemInterruptsObject(base.Object):
+class SystemInterruptObject(base.Object):
        rrd_schema = [
                "DS:intr:DERIVE:0:U",
        ]
 
+       def init(self, irq=None):
+               self.irq = irq
+
        @property
        def id(self):
-               return "default"
+               if self.irq is None:
+                       return "default"
+
+               return "%s" % self.irq
 
        def collect(self):
-               expr = r"^intr (\d+)"
+               stat = self.read_proc_stat()
+
+               # Get a list of all interrupt events
+               interrupts = stat.get("intr").split()
+
+               # The first value is the sum of all interrupts
+               total = interrupts.pop(0)
 
-               with open("/proc/stat") as f:
-                       for line in f.readlines():
-                               m = re.match(expr, line)
-                               if m:
-                                       return m.group(1)
+               if self.irq is None:
+                       return total
+
+               # Otherwise return the value for a specific IRQ
+               return interrupts[self.irq]
 
 
 class SystemInterruptsPlugin(base.Plugin):
@@ -82,4 +95,12 @@ class SystemInterruptsPlugin(base.Plugin):
 
        @property
        def objects(self):
-               yield SystemInterruptsObject(self)
+               yield SystemInterruptObject(self)
+
+               for irq in os.listdir("/sys/kernel/irq"):
+                       try:
+                               irq = int(irq)
+                       except (ValueError, TypeError):
+                               continue
+
+                       yield SystemInterruptObject(self, irq)