]> git.ipfire.org Git - collecty.git/blobdiff - src/collecty/plugins/latency.py
graph templates: Make some atttibutes easier to set
[collecty.git] / src / collecty / plugins / latency.py
index b269221da990bf15489ab5a209b8763a3d91c111..a6db8d0bd29bb9d56132020eb79a691518007b15 100644 (file)
@@ -32,6 +32,8 @@ PING_HOSTS = [
 class GraphTemplateLatency(base.GraphTemplate):
        name = "latency"
 
+       lower_limit = 0
+
        @property
        def rrd_graph(self):
                return [
@@ -73,57 +75,41 @@ class GraphTemplateLatency(base.GraphTemplate):
                ]
 
        @property
-       def rrd_graph_args(self):
-               return [
-                       "--title", _("Latency to %(host)s"),
-                       "--vertical-label", _("Milliseconds"),
-
-                       "--lower-limit", "0", "--rigid",
-               ]
-
+       def graph_title(self):
+               return _("Latency to %(host)s")
 
-class LatencyPlugin(base.Plugin):
-       name = "latency"
-       description = "Latency (ICMP ping) Data Source"
+       @property
+       def graph_vertical_label(self):
+               return _("Milliseconds")
 
-       templates = [GraphTemplateLatency,]
 
+class LatencyObject(base.Object):
        rrd_schema = [
                "DS:latency:GAUGE:0:U",
                "DS:latency_loss:GAUGE:0:100",
                "DS:latency_stddev:GAUGE:0:U",
        ]
 
-       @property
-       def id(self):
-               return "-".join((self.name, self.host))
-
-       @classmethod
-       def autocreate(cls, collecty, **kwargs):
-               ret = []
-               for host in PING_HOSTS:
-                       ds = cls(collecty, host=host, **kwargs)
-                       ret.append(ds)
-
-               return ret
+       def __repr__(self):
+               return "<%s %s>" % (self.__class__.__name__, self.hostname)
 
-       def init(self, **kwargs):
-               self.host = kwargs.get("host")
-               assert self.host
+       def init(self, hostname, deadline=None):
+               self.hostname = hostname
+               self.deadline = deadline
 
        @property
-       def deadline(self):
-               return self.interval - 10
+       def id(self):
+               return self.hostname
 
-       def read(self):
+       def collect(self):
                # Send up to five ICMP echo requests.
                try:
-                       ping = collecty.ping.Ping(destination=self.host, timeout=20000)
+                       ping = collecty.ping.Ping(destination=self.hostname, timeout=20000)
                        ping.run(count=5, deadline=self.deadline)
-       
+
                except collecty.ping.PingError, e:
                        self.log.warning(_("Could not run latency check for %(host)s: %(msg)s") \
-                               % { "host" : self.host, "msg" : e.msg })
+                               % { "host" : self.hostname, "msg" : e.msg })
                        return
 
                return ":".join((
@@ -131,3 +117,19 @@ class LatencyPlugin(base.Plugin):
                        "%.10f" % ping.loss,
                        "%.10f" % ping.stddev,
                ))
+
+
+class LatencyPlugin(base.Plugin):
+       name = "latency"
+       description = "Latency (ICMP ping) Plugin"
+
+       templates = [GraphTemplateLatency]
+
+       interval = 60
+
+       @property
+       def objects(self):
+               deadline = self.interval / len(PING_HOSTS)
+
+               for hostname in PING_HOSTS:
+                       yield LatencyObject(self, hostname, deadline=deadline)