graph templates: Make some atttibutes easier to set
[collecty.git] / src / collecty / plugins / memory.py
index ae90968..7fcf115 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")
 
+       @property
+       def graph_vertical_label(self):
+               return _("Percent")
 
-class DataSourceMemory(base.DataSource):
-       name = "memory"
-       description = "Memory Usage Data Source"
-
-       templates = [GraphTemplateMemory,]
 
+class MemoryObject(base.Object):
        rrd_schema = [
                "DS:used:GAUGE:0:100",
                "DS:cached:GAUGE:0:100",
@@ -101,12 +97,11 @@ class DataSourceMemory(base.DataSource):
                "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 DataSourceMemory(base.DataSource):
                finally:
                        if f:
                                f.close()
+
+
+class MemoryPlugin(base.Plugin):
+       name = "memory"
+       description = "Memory Usage Plugin"
+
+       templates = [GraphTemplateMemory]
+
+       @property
+       def objects(self):
+               yield MemoryObject(self)