]> git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/conntrack.py
psi: Add graph template
[collecty.git] / src / collecty / plugins / conntrack.py
1 #!/usr/bin/python3
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
22 from . import base
23
24 from ..colours import *
25 from ..constants import *
26 from ..i18n import _
27
28 class ConntrackGraphTemplate(base.GraphTemplate):
29 name = "conntrack"
30
31 lower_limit = 0
32
33 @property
34 def rrd_graph(self):
35 return [
36 "COMMENT:%s" % EMPTY_LABEL,
37 "COMMENT:%s" % (COLUMN % _("Current")),
38 "COMMENT:%s" % (COLUMN % _("Average")),
39 "COMMENT:%s" % (COLUMN % _("Minimum")),
40 "COMMENT:%s\\j" % (COLUMN % _("Maximum")),
41
42 "AREA:count%s:%s" % (
43 transparency(PRIMARY, AREA_OPACITY),
44 LABEL % _("Entries"),
45 ),
46 "GPRINT:count_cur:%s" % INTEGER,
47 "GPRINT:count_avg:%s" % INTEGER,
48 "GPRINT:count_min:%s" % INTEGER,
49 "GPRINT:count_max:%s" % INTEGER,
50 "LINE1:count%s" % PRIMARY,
51
52 # Draw maximum line
53 "LINE:max%s:%s:dashes:skipscale" % (
54 COLOUR_CRITICAL, LABEL % _("Maximum"),
55 ),
56 ]
57
58 @property
59 def graph_title(self):
60 return _("Connection Tracking Table")
61
62 @property
63 def graph_vertical_label(self):
64 return _("Entries")
65
66
67 class ConntrackObject(base.Object):
68 rrd_schema = [
69 "DS:count:GAUGE:0:U",
70 "DS:max:GAUGE:0:U",
71 ]
72
73 @property
74 def id(self):
75 return "default"
76
77 def collect(self):
78 """
79 Read count and max values from /proc
80 """
81 return (
82 self.read_file_integer("/proc/sys/net/netfilter/nf_conntrack_count"),
83 self.read_file_integer("/proc/sys/net/netfilter/nf_conntrack_max"),
84 )
85
86
87 class ConntrackPlugin(base.Plugin):
88 name = "conntrack"
89 description = "Conntrack Plugin"
90
91 templates = [
92 ConntrackGraphTemplate,
93 ]
94
95 @property
96 def objects(self):
97 yield ConntrackObject(self)