]> git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/ipfrag.py
Introduce a colour scheme and fix design of the graphs
[collecty.git] / src / collecty / plugins / ipfrag.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 import os
23
24 from .. import util
25 from . import base
26
27 from ..colours import *
28 from ..constants import *
29 from ..i18n import _
30
31 class GraphTemplateIPv6Fragmentation(base.GraphTemplate):
32 name = "ipv6-fragmentation"
33
34 @property
35 def rrd_graph(self):
36 _ = self.locale.translate
37
38 return [
39 "CDEF:ip6_reasm_real_fails=ip6_reasm_fails,ip6_reasm_timeout,-",
40
41 # Reassembly
42 "AREA:ip6_reasm_real_fails%s:%-24s" % \
43 (util.lighten(COLOUR_ERROR), _("Failed Reassemblies")),
44 "GPRINT:ip6_reasm_fails_cur:%s %%5.0lf%%s" % _("Now"),
45 "GPRINT:ip6_reasm_fails_avg:%s %%5.0lf%%s" % _("Avg"),
46 "GPRINT:ip6_reasm_fails_max:%s %%5.0lf%%s" % _("Max"),
47 "GPRINT:ip6_reasm_fails_min:%s %%5.0lf%%s\\j" % _("Min"),
48
49 "AREA:ip6_reasm_timeout%s:%-24s:STACK" % \
50 (util.lighten(COLOUR_WARN), _("Reassembly Timeouts")),
51 "GPRINT:ip6_reasm_timeout_cur:%s %%5.0lf%%s" % _("Now"),
52 "GPRINT:ip6_reasm_timeout_avg:%s %%5.0lf%%s" % _("Avg"),
53 "GPRINT:ip6_reasm_timeout_max:%s %%5.0lf%%s" % _("Max"),
54 "GPRINT:ip6_reasm_timeout_min:%s %%5.0lf%%s\\j" % _("Min"),
55
56 "LINE2:ip6_reasm_oks%s:%-24s" % (BLACK, _("Successful Reassemblies")),
57 "GPRINT:ip6_reasm_oks_cur:%s %%5.0lf%%s" % _("Now"),
58 "GPRINT:ip6_reasm_oks_avg:%s %%5.0lf%%s" % _("Avg"),
59 "GPRINT:ip6_reasm_oks_max:%s %%5.0lf%%s" % _("Max"),
60 "GPRINT:ip6_reasm_oks_min:%s %%5.0lf%%s\\j" % _("Min"),
61
62 "COMMENT: \\n", # empty line
63
64 # Fragmentation
65 "LINE2:ip6_frags_fails%s:%-24s" % (COLOUR_ERROR, _("Failed Fragmentations")),
66 "GPRINT:ip6_frags_fails_cur:%s %%5.0lf%%s" % _("Now"),
67 "GPRINT:ip6_frags_fails_avg:%s %%5.0lf%%s" % _("Avg"),
68 "GPRINT:ip6_frags_fails_max:%s %%5.0lf%%s" % _("Max"),
69 "GPRINT:ip6_frags_fails_min:%s %%5.0lf%%s\\j" % _("Min"),
70
71 "LINE2:ip6_frags_oks%s:%-24s" % (COLOUR_OK, _("Fragmented Packets")),
72 "GPRINT:ip6_frags_oks_cur:%s %%5.0lf%%s" % _("Now"),
73 "GPRINT:ip6_frags_oks_avg:%s %%5.0lf%%s" % _("Avg"),
74 "GPRINT:ip6_frags_oks_max:%s %%5.0lf%%s" % _("Max"),
75 "GPRINT:ip6_frags_oks_min:%s %%5.0lf%%s\\j" % _("Min"),
76 ]
77
78 @property
79 def graph_title(self):
80 _ = self.locale.translate
81
82 if self.object.interface:
83 return _("IPv6 Fragmentation on %s") % self.object.interface
84
85 return _("IPv6 Fragmentation")
86
87 @property
88 def graph_vertical_label(self):
89 _ = self.locale.translate
90 return _("Packets/s")
91
92 @property
93 def rrd_graph_args(self):
94 return [
95 "--base", "1000",
96 "--legend-direction=bottomup",
97 ]
98
99
100 class GraphTemplateIPv4Fragmentation(base.GraphTemplate):
101 name = "ipv4-fragmentation"
102
103 @property
104 def rrd_graph(self):
105 _ = self.locale.translate
106
107 return [
108 "CDEF:ip4_reasm_real_fails=ip4_reasm_fails,ip4_reasm_timeout,-",
109
110 # Reassembly
111 "AREA:ip4_reasm_real_fails%s:%-24s" % \
112 (util.lighten(COLOUR_ERROR), _("Failed Reassemblies")),
113 "GPRINT:ip4_reasm_fails_cur:%s %%5.0lf%%s" % _("Now"),
114 "GPRINT:ip4_reasm_fails_avg:%s %%5.0lf%%s" % _("Avg"),
115 "GPRINT:ip4_reasm_fails_max:%s %%5.0lf%%s" % _("Max"),
116 "GPRINT:ip4_reasm_fails_min:%s %%5.0lf%%s\\j" % _("Min"),
117
118 "AREA:ip4_reasm_timeout%s:%-24s:STACK" % \
119 (util.lighten(COLOUR_WARN), _("Reassembly Timeouts")),
120 "GPRINT:ip4_reasm_timeout_cur:%s %%5.0lf%%s" % _("Now"),
121 "GPRINT:ip4_reasm_timeout_avg:%s %%5.0lf%%s" % _("Avg"),
122 "GPRINT:ip4_reasm_timeout_max:%s %%5.0lf%%s" % _("Max"),
123 "GPRINT:ip4_reasm_timeout_min:%s %%5.0lf%%s\\j" % _("Min"),
124
125 "LINE2:ip4_reasm_oks%s:%-24s" % (BLACK, _("Successful Reassemblies")),
126 "GPRINT:ip4_reasm_oks_cur:%s %%5.0lf%%s" % _("Now"),
127 "GPRINT:ip4_reasm_oks_avg:%s %%5.0lf%%s" % _("Avg"),
128 "GPRINT:ip4_reasm_oks_max:%s %%5.0lf%%s" % _("Max"),
129 "GPRINT:ip4_reasm_oks_min:%s %%5.0lf%%s\\j" % _("Min"),
130
131 "COMMENT: \\n", # empty line
132
133 # Fragmentation
134 "LINE2:ip4_frags_fails%s:%-24s" % (COLOUR_ERROR, _("Failed Fragmentations")),
135 "GPRINT:ip4_frags_fails_cur:%s %%5.0lf%%s" % _("Now"),
136 "GPRINT:ip4_frags_fails_avg:%s %%5.0lf%%s" % _("Avg"),
137 "GPRINT:ip4_frags_fails_max:%s %%5.0lf%%s" % _("Max"),
138 "GPRINT:ip4_frags_fails_min:%s %%5.0lf%%s\\j" % _("Min"),
139
140 "LINE2:ip4_frags_oks%s:%-24s" % (COLOUR_OK, _("Fragmented Packets")),
141 "GPRINT:ip4_frags_oks_cur:%s %%5.0lf%%s" % _("Now"),
142 "GPRINT:ip4_frags_oks_avg:%s %%5.0lf%%s" % _("Avg"),
143 "GPRINT:ip4_frags_oks_max:%s %%5.0lf%%s" % _("Max"),
144 "GPRINT:ip4_frags_oks_min:%s %%5.0lf%%s\\j" % _("Min"),
145 ]
146
147 @property
148 def graph_title(self):
149 _ = self.locale.translate
150
151 if self.object.interface:
152 return _("IPv4 Fragmentation on %s") % self.object.interface
153
154 return _("IPv4 Fragmentation")
155
156 @property
157 def graph_vertical_label(self):
158 _ = self.locale.translate
159 return _("Packets/s")
160
161 @property
162 def rrd_graph_args(self):
163 return [
164 "--base", "1000",
165 "--legend-direction=bottomup",
166 ]
167
168
169 class IPFragmentationObject(base.Object):
170 rrd_schema = [
171 "DS:ip6_frags_oks:DERIVE:0:U",
172 "DS:ip6_frags_fails:DERIVE:0:U",
173 "DS:ip6_frags_creates:DERIVE:0:U",
174 "DS:ip6_reasm_timeout:DERIVE:0:U",
175 "DS:ip6_reasm_reqds:DERIVE:0:U",
176 "DS:ip6_reasm_oks:DERIVE:0:U",
177 "DS:ip6_reasm_fails:DERIVE:0:U",
178 "DS:ip4_frags_oks:DERIVE:0:U",
179 "DS:ip4_frags_fails:DERIVE:0:U",
180 "DS:ip4_frags_creates:DERIVE:0:U",
181 "DS:ip4_reasm_timeout:DERIVE:0:U",
182 "DS:ip4_reasm_reqds:DERIVE:0:U",
183 "DS:ip4_reasm_oks:DERIVE:0:U",
184 "DS:ip4_reasm_fails:DERIVE:0:U",
185 ]
186
187 def __repr__(self):
188 if self.interface:
189 return "<%s %s>" % (self.__class__.__name__, self.interface)
190
191 return "<%s>" % self.__class__.__name__
192
193 def init(self, interface=None):
194 self.interface = interface
195
196 @property
197 def id(self):
198 return self.interface or "default"
199
200 def collect(self):
201 p = util.ProcNetSnmpParser(self.interface)
202
203 # Description in RFC2465
204 results = [
205 p.get("Ip6", "FragOKs"),
206 p.get("Ip6", "FragFails"),
207 p.get("Ip6", "FragCreates"),
208 p.get("Ip6", "ReasmTimeout"),
209 p.get("Ip6", "ReasmReqds"),
210 p.get("Ip6", "ReasmOKs"),
211 p.get("Ip6", "ReasmFails"),
212 p.get("Ip", "FragOKs"),
213 p.get("Ip", "FragFails"),
214 p.get("Ip", "FragCreates"),
215 p.get("Ip", "ReasmTimeout"),
216 p.get("Ip", "ReasmReqds"),
217 p.get("Ip", "ReasmOKs"),
218 p.get("Ip", "ReasmFails"),
219 ]
220
221 return results
222
223
224 class IPFragmentationPlugin(base.Plugin):
225 name = "ip-fragmentation"
226 description = "IP Fragmentation Plugin"
227
228 templates = [
229 GraphTemplateIPv6Fragmentation,
230 GraphTemplateIPv4Fragmentation,
231 ]
232
233 @property
234 def objects(self):
235 # Overall statistics
236 yield IPFragmentationObject(self)
237
238 # Stats per interface
239 for interface in util.get_network_interfaces():
240 yield IPFragmentationObject(self, interface)