]> git.ipfire.org Git - collecty.git/blobdiff - src/collecty/plugins/memory.py
graph templates: Make some atttibutes easier to set
[collecty.git] / src / collecty / plugins / memory.py
index e66e22393f727392d6a732b7d664387ebb0bdf41..7fcf1154b2444dd81cf7472cf178a66b2f91940e 100644 (file)
@@ -28,6 +28,9 @@ from ..i18n import _
 class GraphTemplateMemory(base.GraphTemplate):
        name = "memory"
 
+       upper_limit = 100
+       lower_limit = 0
+
        rrd_graph = [
                "DEF:used=%(file)s:used:AVERAGE",
                "DEF:cached=%(file)s:cached:AVERAGE",
@@ -76,23 +79,16 @@ class GraphTemplateMemory(base.GraphTemplate):
                "GPRINT:swapavg:%12s\:" % _("Average") + " %6.2lf\\n",
        ]
 
-       rrd_graph_args = [
-               "--title", _("Memory Usage"),
-               "--vertical-label", _("Percent"),
-
-               # Limit y axis.
-               "--upper-limit", "100",
-               "--lower-limit", "0",
-               "--rigid",
-       ]
-
+       @property
+       def graph_title(self):
+               return _("Memory Usage")
 
-class MemoryPlugin(base.Plugin):
-       name = "memory"
-       description = "Memory Usage Data Source"
+       @property
+       def graph_vertical_label(self):
+               return _("Percent")
 
-       templates = [GraphTemplateMemory,]
 
+class MemoryObject(base.Object):
        rrd_schema = [
                "DS:used:GAUGE:0:100",
                "DS:cached:GAUGE:0:100",
@@ -101,12 +97,11 @@ class MemoryPlugin(base.Plugin):
                "DS:swap:GAUGE:0:100",
        ]
 
-       @classmethod
-       def autocreate(cls, collecty, **kwargs):
-               # Every system has got memory.
-               return cls(collecty, **kwargs)
+       @property
+       def id(self):
+               return "default"
 
-       def read(self):
+       def collect(self):
                f = None
 
                try:
@@ -141,3 +136,14 @@ class MemoryPlugin(base.Plugin):
                finally:
                        if f:
                                f.close()
+
+
+class MemoryPlugin(base.Plugin):
+       name = "memory"
+       description = "Memory Usage Plugin"
+
+       templates = [GraphTemplateMemory]
+
+       @property
+       def objects(self):
+               yield MemoryObject(self)