]> git.ipfire.org Git - collecty.git/blame - src/collecty/plugins/conntrack.py
conntrack: Refactor plugin
[collecty.git] / src / collecty / plugins / conntrack.py
CommitLineData
f37913e8 1#!/usr/bin/python3
0ec1854a
MT
2###############################################################################
3# #
4# collecty - A system statistics collection daemon for IPFire #
5# Copyright (C) 2015 IPFire development team #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
f37913e8 22from . import base
0ec1854a 23
03ba5630 24from ..colours import *
9b315095 25from ..constants import *
0308c0f3 26
9b315095
MT
27class ConntrackGraphTemplate(base.GraphTemplate):
28 name = "conntrack"
0308c0f3 29
9b315095 30 lower_limit = 0
0308c0f3
MT
31
32 @property
33 def rrd_graph(self):
fa43c345 34 _ = self.locale.translate
0308c0f3 35
0308c0f3 36 return [
9b315095
MT
37 "COMMENT:%s" % EMPTY_LABEL,
38 "COMMENT:%s" % (COLUMN % _("Current")),
39 "COMMENT:%s" % (COLUMN % _("Average")),
40 "COMMENT:%s" % (COLUMN % _("Minimum")),
41 "COMMENT:%s\\j" % (COLUMN % _("Maximum")),
42
43 "AREA:count%s:%s" % (
44 transparency(PRIMARY, AREA_OPACITY),
45 LABEL % _("Entries"),
46 ),
47 "GPRINT:count_cur:%s" % INTEGER,
48 "GPRINT:count_avg:%s" % INTEGER,
49 "GPRINT:count_min:%s" % INTEGER,
50 "GPRINT:count_max:%s" % INTEGER,
51 "LINE1:count%s" % PRIMARY,
52
53 # Draw maximum line
54 "LINE:max%s:%s:dashes:skipscale" % (
55 COLOUR_CRITICAL, LABEL % _("Maximum"),
56 ),
76c12e91 57 ]
cd8bba0b 58
0308c0f3
MT
59 @property
60 def graph_title(self):
fa43c345 61 _ = self.locale.translate
0308c0f3 62
9b315095 63 return _("Connection Tracking Table")
0308c0f3
MT
64
65 @property
66 def graph_vertical_label(self):
fa43c345 67 _ = self.locale.translate
0308c0f3 68
9b315095 69 return _("Entries")
0308c0f3
MT
70
71
0ec1854a 72class ConntrackObject(base.Object):
0ec1854a 73 rrd_schema = [
9b315095
MT
74 "DS:count:GAUGE:0:U",
75 "DS:max:GAUGE:0:U",
0ec1854a
MT
76 ]
77
78 @property
79 def id(self):
9b315095 80 return "default"
0ec1854a
MT
81
82 def collect(self):
9b315095
MT
83 """
84 Read count and max values from /proc
85 """
86 return (
87 self.read_file_integer("/proc/sys/net/netfilter/nf_conntrack_count"),
88 self.read_file_integer("/proc/sys/net/netfilter/nf_conntrack_max"),
89 )
0ec1854a
MT
90
91
92class ConntrackPlugin(base.Plugin):
93 name = "conntrack"
94 description = "Conntrack Plugin"
95
0308c0f3 96 templates = [
9b315095 97 ConntrackGraphTemplate,
0308c0f3 98 ]
0ec1854a
MT
99
100 @property
101 def objects(self):
9b315095 102 yield ConntrackObject(self)