From: Michael Tremer Date: Mon, 21 Sep 2020 14:37:49 +0000 (+0000) Subject: interrupts: Collect data for all interrupts X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f41e95b486ee332198ef93d31c975dd0ddbba2bb;p=collecty.git interrupts: Collect data for all interrupts Signed-off-by: Michael Tremer --- diff --git a/src/collecty/plugins/base.py b/src/collecty/plugins/base.py index 16bc0e4..3a7fd5e 100644 --- a/src/collecty/plugins/base.py +++ b/src/collecty/plugins/base.py @@ -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 diff --git a/src/collecty/plugins/interrupts.py b/src/collecty/plugins/interrupts.py index b8cacd1..bff704d 100644 --- a/src/collecty/plugins/interrupts.py +++ b/src/collecty/plugins/interrupts.py @@ -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)