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