]> git.ipfire.org Git - collecty.git/commitdiff
Add context switches plugin
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 23 Nov 2015 00:56:23 +0000 (00:56 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 23 Nov 2015 00:56:23 +0000 (00:56 +0000)
This monitors the number of context switches of the entire system.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/collecty/plugins/__init__.py
src/collecty/plugins/contextswitches.py [new file with mode: 0644]

index 2a2f233438613bb9df033d0c487b4a8639706d01..1c4808ebddbf78506787778000865e3936d901a9 100644 (file)
@@ -86,6 +86,7 @@ collectydir = $(pythondir)/collecty
 
 collectyplugins_PYTHON = \
        src/collecty/plugins/base.py \
+       src/collecty/plugins/contextswitches.py \
        src/collecty/plugins/conntrack.py \
        src/collecty/plugins/cpufreq.py \
        src/collecty/plugins/disk.py \
index 648ac83b4abbbae6581c0209cdc3f7244dee93f1..a82e236a1b47fe38cc2cfcf2550a14a23a6a2d37 100644 (file)
@@ -22,6 +22,7 @@
 from .base import Timer, get
 
 from . import base
+from . import contextswitches
 from . import conntrack
 from . import cpufreq
 from . import disk
diff --git a/src/collecty/plugins/contextswitches.py b/src/collecty/plugins/contextswitches.py
new file mode 100644 (file)
index 0000000..f9194a0
--- /dev/null
@@ -0,0 +1,87 @@
+#!/usr/bin/python3
+###############################################################################
+#                                                                             #
+# collecty - A system statistics collection daemon for IPFire                 #
+# Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+import re
+
+from . import base
+
+from ..i18n import _
+
+class GraphTemplateContextSwitches(base.GraphTemplate):
+       name = "context-switches"
+
+       @property
+       def rrd_graph(self):
+               _ = self.locale.translate
+
+               return [
+                       "DEF:ctxt=%(file)s:ctxt:AVERAGE",
+
+                       "AREA:ctxt#90EE90:%-15s" % _("Context Switches"),
+                       "VDEF:ctxtmax=ctxt,MAXIMUM",
+                       "VDEF:ctxtmin=ctxt,MINIMUM",
+                       "VDEF:ctxtavg=ctxt,AVERAGE",
+                       "GPRINT:ctxtmax:%12s\:" % _("Maximum") + " %6.2lf" ,
+                       "GPRINT:ctxtmin:%12s\:" % _("Minimum") + " %6.2lf" ,
+                       "GPRINT:ctxtavg:%12s\:" % _("Average") + " %6.2lf\\n",
+               ]
+
+       lower_limit = 0
+
+       @property
+       def graph_title(self):
+               _ = self.locale.translate
+               return _("Context Switches")
+
+       @property
+       def graph_vertical_label(self):
+               _ = self.locale.translate
+               return _("Context Switches/s")
+
+
+class ContextSwitchesObject(base.Object):
+       rrd_schema = [
+               "DS:ctxt:DERIVE:0:U",
+       ]
+
+       @property
+       def id(self):
+               return "default"
+
+       def collect(self):
+               expr = re.compile(r"^ctxt (\d+)$")
+
+               with open("/proc/stat") as f:
+                       for line in f.readlines():
+                               m = re.match(expr, line)
+                               if m:
+                                       return m.group(1)
+
+
+class ContextSwitchesPlugin(base.Plugin):
+       name = "context-switches"
+       description = "Context Switches Plugin"
+
+       templates = [GraphTemplateContextSwitches]
+
+       @property
+       def objects(self):
+               yield ContextSwitchesObject(self)