]> git.ipfire.org Git - collecty.git/blobdiff - src/collecty/plugins/entropy.py
Rewrite plugin architecture
[collecty.git] / src / collecty / plugins / entropy.py
index 7966e8b83e2d3fa6a63a9acc4f06b754d3ee3d16..f800f9a068ea78f77228bff68558ad7837e99995 100644 (file)
@@ -53,32 +53,30 @@ class GraphTemplateEntropy(base.GraphTemplate):
        ]
 
 
-class EntropyPlugin(base.Plugin):
-       name = "entropy"
-       description = "Entropy Data Source"
-
-       templates = [GraphTemplateEntropy,]
-
+class EntropyObject(base.Object):
        rrd_schema = [
                "DS:entropy:GAUGE:0:U",
        ]
 
-       @classmethod
-       def autocreate(cls, collecty, **kwargs):
-               if not os.path.exists(ENTROPY_FILE):
-                       self.log.debug(_("Entropy kernel interface does not exist."))
-                       return
+       @property
+       def id(self):
+               return "default"
 
-               return cls(collecty, **kwargs)
+       def collect(self):
+               with open(ENTROPY_FILE) as f:
+                       return f.readline().strip()
 
-       def read(self):
-               f = None
 
-               try:
-                       f = open(ENTROPY_FILE)
-                       entropy = f.readline()
+class EntropyPlugin(base.Plugin):
+       name = "entropy"
+       description = "Entropy Plugin"
+
+       templates = [GraphTemplateEntropy,]
+
+       @property
+       def objects(self):
+               if not os.path.exists(ENTROPY_FILE):
+                       self.log.debug(_("Entropy kernel interface does not exist"))
+                       return []
 
-                       return entropy.strip()
-               finally:
-                       if f:
-                               f.close()
+               return [EntropyObject(self)]