]>
git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/latency.py
27cdc668290393ae80ad2b1d58441c0a40b5880d
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 ###############################################################################
24 from .. import _collecty
27 from ..colours
import *
28 from ..constants
import *
32 # gateway is a special name that is automatically
33 # resolved by myhostname to the default gateway.
36 # The IPFire main server
40 class GraphTemplateLatency(base
.GraphTemplate
):
48 # Compute the biggest loss and convert into percentage
49 "CDEF:ploss=loss6,loss4,MAX,100,*",
51 # Compute standard deviation
52 "CDEF:stddevarea6=stddev6,2,*",
53 "CDEF:spacer6=latency6,stddev6,-",
54 "CDEF:stddevarea4=stddev4,2,*",
55 "CDEF:spacer4=latency4,stddev4,-",
57 "CDEF:l005=ploss,0,5,LIMIT,UN,UNKN,INF,IF",
58 "CDEF:l010=ploss,5,10,LIMIT,UN,UNKN,INF,IF",
59 "CDEF:l025=ploss,10,25,LIMIT,UN,UNKN,INF,IF",
60 "CDEF:l050=ploss,25,50,LIMIT,UN,UNKN,INF,IF",
61 "CDEF:l099=ploss,50,99,LIMIT,UN,UNKN,INF,IF",
64 "LINE:latency6_avg%s::dashes" % (
67 "LINE:latency4_avg%s::dashes" % (
71 # Colour background on packet loss
72 "COMMENT:%s" % _("Packet Loss"),
74 transparency(BLACK
, .2), _("0-5%"),
77 transparency(BLACK
, .4), _("5-10%"),
80 transparency(BLACK
, .6), _("10-25%"),
83 transparency(BLACK
, .8), _("25-50%"),
85 "AREA:l099%s:%s\\r" % (BLACK
, _("50-99%")),
89 # Plot standard deviation
91 "AREA:stddevarea4%s:STACK" % transparency(COLOUR_IPV4
, STDDEV_OPACITY
),
92 "LINE2:latency4%s:%s" % (
94 LABEL
% _("Latency (IPv4)"),
96 "GPRINT:latency4_cur:%s" % MS
,
97 "GPRINT:latency4_avg:%s" % MS
,
98 "GPRINT:latency4_min:%s" % MS
,
99 "GPRINT:latency4_max:%s\\j" % MS
,
102 "AREA:stddevarea6%s:STACK" % transparency(COLOUR_IPV6
, STDDEV_OPACITY
),
103 "LINE2:latency6%s:%s" % (
105 LABEL
% _("Latency (IPv6)"),
107 "GPRINT:latency6_cur:%s" % MS
,
108 "GPRINT:latency6_avg:%s" % MS
,
109 "GPRINT:latency6_min:%s" % MS
,
110 "GPRINT:latency6_max:%s\\j" % MS
,
113 "COMMENT:%s" % EMPTY_LABEL
,
114 "COMMENT:%s" % (COLUMN
% _("Current")),
115 "COMMENT:%s" % (COLUMN
% _("Average")),
116 "COMMENT:%s" % (COLUMN
% _("Minimum")),
117 "COMMENT:%s\\j" % (COLUMN
% _("Maximum")),
121 def graph_title(self
):
122 if self
.object.hostname
== "gateway":
123 hostname
= _("Default Gateway")
125 hostname
= self
.object.hostname
127 return _("Latency to %s") % hostname
130 def graph_vertical_label(self
):
131 return _("Milliseconds")
134 def rrd_graph_args(self
):
136 "--legend-direction=bottomup",
140 class LatencyObject(base
.Object
):
142 "DS:latency6:GAUGE:0:U",
143 "DS:stddev6:GAUGE:0:U",
144 "DS:loss6:GAUGE:0:100",
145 "DS:latency4:GAUGE:0:U",
146 "DS:stddev4:GAUGE:0:U",
147 "DS:loss4:GAUGE:0:100",
150 def init(self
, hostname
):
151 self
.hostname
= hostname
160 for family
in (socket
.AF_INET6
, socket
.AF_INET
):
162 p
= _collecty
.Ping(self
.hostname
, family
=family
)
163 p
.ping(count
=10, deadline
=10)
165 result
+= (p
.average
, p
.stddev
, p
.loss
)
167 except _collecty
.PingAddHostError
as e
:
168 self
.log
.debug(_("Could not add host %(host)s for family %(family)s") \
169 % { "host" : self
.hostname
, "family" : family
})
172 result
+= (None, None, None)
175 except _collecty
.PingNoReplyError
:
176 # Unknown but 100% loss
177 result
+= (None, None, 1)
180 except _collecty
.PingError
as e
:
181 self
.log
.warning(_("Could not run latency check for %(host)s: %(msg)s") \
182 % { "host" : self
.hostname
, "msg" : e
})
184 # A hundred percent loss
185 result
+= (None, None, 1)
190 class LatencyPlugin(base
.Plugin
):
192 description
= "Latency (ICMP ping) Plugin"
194 templates
= [GraphTemplateLatency
]
196 # Because this plugin has the potential to block, we give it a slightly lower priority
201 for hostname
in PING_HOSTS
:
202 yield LatencyObject(self
, hostname
)