From fdf41d343c6054165eff27dabf9f034ba8d3665b Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 1 Dec 2021 23:24:16 +0000 Subject: [PATCH] plugins: Read Pressure Stall Information from the kernel Signed-off-by: Michael Tremer --- Makefile.am | 1 + src/collecty/daemon.py | 3 - src/collecty/plugins/__init__.py | 1 + src/collecty/plugins/psi.py | 99 ++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 src/collecty/plugins/psi.py diff --git a/Makefile.am b/Makefile.am index d86a0de..dcc7a9e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -105,6 +105,7 @@ collectyplugins_PYTHON = \ src/collecty/plugins/latency.py \ src/collecty/plugins/loadavg.py \ src/collecty/plugins/memory.py \ + src/collecty/plugins/psi.py \ src/collecty/plugins/processor.py \ src/collecty/plugins/sensors.py diff --git a/src/collecty/daemon.py b/src/collecty/daemon.py index 22af2b0..cac236c 100644 --- a/src/collecty/daemon.py +++ b/src/collecty/daemon.py @@ -357,9 +357,6 @@ class QueueObject(object): @staticmethod def _format_data(data): - if not isinstance(data, tuple) and not isinstance(data, list): - return data - # Replace all Nones by UNKNOWN s = [] diff --git a/src/collecty/plugins/__init__.py b/src/collecty/plugins/__init__.py index 147a1b6..41b47f5 100644 --- a/src/collecty/plugins/__init__.py +++ b/src/collecty/plugins/__init__.py @@ -33,5 +33,6 @@ from . import ipfrag from . import latency from . import loadavg from . import processor +from . import psi from . import memory from . import sensors diff --git a/src/collecty/plugins/psi.py b/src/collecty/plugins/psi.py new file mode 100644 index 0000000..f9fe0b1 --- /dev/null +++ b/src/collecty/plugins/psi.py @@ -0,0 +1,99 @@ +#!/usr/bin/python3 +############################################################################### +# # +# collecty - A system statistics collection daemon for IPFire # +# Copyright (C) 2021 IPFire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +import os + +from . import base + +class PSIObject(base.Object): + rrd_schema = [ + # some + "DS:some_avg10:GAUGE:0:100", + "DS:some_avg60:GAUGE:0:100", + "DS:some_avg300:GAUGE:0:100", + "DS:some_total:DERIVE:0:U", + + # full + "DS:full_avg10:GAUGE:0:100", + "DS:full_avg60:GAUGE:0:100", + "DS:full_avg300:GAUGE:0:100", + "DS:full_total:DERIVE:0:U", + ] + + def __repr__(self): + return "<%s %s>" % (self.__class__.__name__, self.item) + + def init(self, item): + self.item = item + + self.path = os.path.join("/proc/pressure", self.item) + + @property + def id(self): + return self.item + + def collect(self): + lines = self.read_file("/proc/pressure", self.item) + + # Do nothing if nothing could be read + if not lines: + return + + # Parse all input lines + values = {} + for line in lines.splitlines(): + values.update(self._parse_psi(line)) + + # Return all values in order + for share in ("some", "full"): + for value in ("avg10", "avg60", "avg300", "total"): + yield values.get("%s-%s" % (share, value), None) + + def _parse_psi(self, line): + words = line.split(" ") + + share = None + values = {} + + for i, word in enumerate(words): + # Store the share of time + if i == 0: + share = word + continue + + # Split word + key, delim, value = word.partition("=") + + # Store it in the values array + values["%s-%s" % (share, key)] = value + + # Return everything + return values + + +class PSIPlugin(base.Plugin): + name = "psi" + description = "Pressure Stall Information Plugin" + + @property + def objects(self): + for item in os.listdir("/proc/pressure"): + yield PSIObject(self, item) -- 2.47.2