]>
git.ipfire.org Git - collecty.git/blob - collecty/plugins/interface.py
2 ###############################################################################
4 # collecty - A system statistics collection daemon for IPFire #
5 # Copyright (C) 2012 IPFire development team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 from __future__
import division
30 SYS_CLASS_NET
= "/sys/class/net"
32 class DataSourceInterface(base
.DataSource
):
34 description
= "Interface Statistics Data Source"
39 "DS:bytes_rx:DERIVE:0:U",
40 "DS:bytes_tx:DERIVE:0:U",
41 "DS:collisions:DERIVE:0:U",
42 "DS:dropped_rx:DERIVE:0:U",
43 "DS:dropped_tx:DERIVE:0:U",
44 "DS:errors_rx:DERIVE:0:U",
45 "DS:errors_tx:DERIVE:0:U",
46 "DS:multicast:DERIVE:0:U",
47 "DS:packets_rx:DERIVE:0:U",
48 "DS:packets_tx:DERIVE:0:U",
52 def autocreate(cls
, collecty
, **kwargs
):
53 if not os
.path
.exists(SYS_CLASS_NET
):
57 for interface
in os
.listdir(SYS_CLASS_NET
):
58 path
= os
.path
.join(SYS_CLASS_NET
, interface
)
59 if not os
.path
.isdir(path
):
62 instance
= cls(collecty
, interface
=interface
)
63 instances
.append(instance
)
67 def init(self
, **kwargs
):
68 self
.interface
= kwargs
.get("interface")
72 return "-".join((self
.name
, self
.interface
))
76 "rx_bytes", "tx_bytes",
78 "rx_dropped", "tx_dropped",
79 "rx_errors", "tx_errors",
81 "rx_packets", "tx_packets",
83 ret
= ["%s" % self
.now
,]
86 path
= os
.path
.join(SYS_CLASS_NET
, self
.interface
, "statistics", file)
88 # Open file and read it's content.
97 self
.data
.append(":".join(ret
))