X-Git-Url: http://git.ipfire.org/?p=collecty.git;a=blobdiff_plain;f=src%2Fcollecty%2Fplugins%2Finterface.py;h=3ad6e8b0137062afe1008be9471ec18ddbea629f;hp=fbf715ab150dea49b1cf2749211bdadd42a0a685;hb=f181246a44db1e5e80a6181bd94ca70502878cc3;hpb=5d140577539b719cd6fcba07fd68e480bfc9869d diff --git a/src/collecty/plugins/interface.py b/src/collecty/plugins/interface.py index fbf715a..3ad6e8b 100644 --- a/src/collecty/plugins/interface.py +++ b/src/collecty/plugins/interface.py @@ -82,11 +82,12 @@ class GraphTemplateInterfaceBits(base.GraphTemplate): ] @property - def rrd_graph_args(self): - return [ - "--title", _("Bandwidth usage on %(interface)s"), - "--vertical-label", _("Bit/s"), - ] + def graph_title(self): + return _("Bandwidth usage on %(interface)s") + + @property + def graph_vertical_label(self): + return _("Bit/s") class GraphTemplateInterfacePackets(base.GraphTemplate): @@ -122,11 +123,12 @@ class GraphTemplateInterfacePackets(base.GraphTemplate): ] @property - def rrd_graph_args(self): - return [ - "--title", _("Transferred packets on %(interface)s"), - "--vertical-label", _("Packets/s"), - ] + def graph_title(self): + return _("Transferred packets on %(interface)s") + + @property + def graph_vertical_label(self): + return _("Packets/s") class GraphTemplateInterfaceErrors(base.GraphTemplate): @@ -190,23 +192,15 @@ class GraphTemplateInterfaceErrors(base.GraphTemplate): ] @property - def rrd_graph_args(self): - return [ - "--title", _("Errors/dropped packets on %(interface)s"), - "--vertical-label", _("Packets/s"), - ] + def graph_title(self): + return _("Errors/dropped packets on %(interface)s") + @property + def graph_vertical_label(self): + return _("Packets/s") -class InterfacePlugin(base.Plugin): - name = "interface" - description = "Interface Statistics Data Source" - - templates = [ - GraphTemplateInterfaceBits, - GraphTemplateInterfacePackets, - GraphTemplateInterfaceErrors, - ] +class InterfaceObject(base.Object): rrd_schema = [ "DS:bytes_rx:DERIVE:0:U", "DS:bytes_tx:DERIVE:0:U", @@ -220,34 +214,17 @@ class InterfacePlugin(base.Plugin): "DS:packets_tx:DERIVE:0:U", ] - @classmethod - def autocreate(cls, collecty, **kwargs): - if not os.path.exists(SYS_CLASS_NET): - return - - instances = [] - for interface in os.listdir(SYS_CLASS_NET): - # Skip some unwanted interfaces. - if interface == "lo" or interface.startswith("mon."): - continue - - path = os.path.join(SYS_CLASS_NET, interface) - if not os.path.isdir(path): - continue - - instance = cls(collecty, interface=interface) - instances.append(instance) - - return instances + def __repr__(self): + return "<%s %s>" % (self.__class__.__name__, self.interface) - def init(self, **kwargs): - self.interface = kwargs.get("interface") + def init(self, interface): + self.interface = interface @property def id(self): - return "-".join((self.name, self.interface)) + return self.interface - def read(self): + def collect(self): interface_path = os.path.join(SYS_CLASS_NET, self.interface) # Check if the interface exists. @@ -286,3 +263,33 @@ class InterfacePlugin(base.Plugin): f.close() return ":".join(ret) + + +class InterfacePlugin(base.Plugin): + name = "interface" + description = "Interface Statistics Plugin" + + templates = [ + GraphTemplateInterfaceBits, + GraphTemplateInterfacePackets, + GraphTemplateInterfaceErrors, + ] + + interval = 20 + + def get_interfaces(self): + for interface in os.listdir(SYS_CLASS_NET): + # Skip some unwanted interfaces. + if interface == "lo" or interface.startswith("mon."): + continue + + path = os.path.join(SYS_CLASS_NET, interface) + if not os.path.isdir(path): + continue + + yield interface + + @property + def objects(self): + for interface in self.get_interfaces(): + yield InterfaceObject(self, interface=interface)