]>
git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/latency.py
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 import collecty
._collecty
28 from ..colours
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
):
47 _
= self
.locale
.translate
51 # Compute the biggest loss and convert into percentage
52 "CDEF:ploss=loss6,loss4,MAX,100,*",
54 # Compute standard deviation
55 "CDEF:stddevarea6=stddev6,2,*",
56 "CDEF:spacer6=latency6,stddev6,-",
57 "CDEF:stddevarea4=stddev4,2,*",
58 "CDEF:spacer4=latency4,stddev4,-",
60 "CDEF:l005=ploss,0,5,LIMIT,UN,UNKN,INF,IF",
61 "CDEF:l010=ploss,5,10,LIMIT,UN,UNKN,INF,IF",
62 "CDEF:l025=ploss,10,25,LIMIT,UN,UNKN,INF,IF",
63 "CDEF:l050=ploss,25,50,LIMIT,UN,UNKN,INF,IF",
64 "CDEF:l099=ploss,50,99,LIMIT,UN,UNKN,INF,IF",
66 "LINE2:latency6_avg%s:%s" % (
67 util
.transparency(COLOUR_IPV6
, .5),
68 _("Average latency (IPv6)"),
70 "LINE2:latency4_avg%s:%s\\r" % (
71 util
.transparency(COLOUR_IPV4
, .5),
72 _("Average latency (IPv4)"),
75 "COMMENT:%s" % _("Packet Loss"),
77 util
.transparency(colour_bg
, .2), _("0-5%"),
80 util
.transparency(colour_bg
, .4), _("5-10%"),
83 util
.transparency(colour_bg
, .6), _("10-25%"),
86 util
.transparency(colour_bg
, .8), _("25-50%"),
88 "AREA:l099%s:%s\\r" % (colour_bg
, _("50-99%")),
90 "COMMENT: \\n", # empty line
93 "AREA:stddevarea4%s:STACK" % util
.lighten(COLOUR_IPV4
, STDDEV_OPACITY
),
94 "LINE2:latency4%s:%s" % (COLOUR_IPV4
, _("Latency (IPv4)")),
95 "GPRINT:latency4_max:%12s\:" % _("Maximum") + " %6.2lf",
96 "GPRINT:latency4_min:%12s\:" % _("Minimum") + " %6.2lf",
97 "GPRINT:latency4_avg:%12s\:" % _("Average") + " %6.2lf\\n",
100 "AREA:stddevarea6%s:STACK" % util
.lighten(COLOUR_IPV6
, STDDEV_OPACITY
),
101 "LINE2:latency6%s:%s" % (COLOUR_IPV6
, _("Latency (IPv6)")),
102 "GPRINT:latency6_max:%12s\:" % _("Maximum") + " %6.2lf",
103 "GPRINT:latency6_min:%12s\:" % _("Minimum") + " %6.2lf",
104 "GPRINT:latency6_avg:%12s\:" % _("Average") + " %6.2lf\\n",
108 def graph_title(self
):
109 _
= self
.locale
.translate
110 return _("Latency to %s") % self
.object.hostname
113 def graph_vertical_label(self
):
114 _
= self
.locale
.translate
115 return _("Milliseconds")
118 def rrd_graph_args(self
):
120 "--legend-direction=bottomup",
124 class LatencyObject(base
.Object
):
126 "DS:latency6:GAUGE:0:U",
127 "DS:stddev6:GAUGE:0:U",
128 "DS:loss6:GAUGE:0:100",
129 "DS:latency4:GAUGE:0:U",
130 "DS:stddev4:GAUGE:0:U",
131 "DS:loss4:GAUGE:0:100",
135 return "<%s %s>" % (self
.__class
__.__name
__, self
.hostname
)
137 def init(self
, hostname
):
138 self
.hostname
= hostname
147 for family
in (socket
.AF_INET6
, socket
.AF_INET
):
149 p
= collecty
._collecty
.Ping(self
.hostname
, family
=family
)
150 p
.ping(count
=5, deadline
=10)
152 result
+= (p
.average
, p
.stddev
, p
.loss
)
154 except collecty
._collecty
.PingAddHostError
as e
:
155 self
.log
.debug(_("Could not add host %(host)s for family %(family)s") \
156 % { "host" : self
.hostname
, "family" : family
})
159 result
+= (None, None, None)
162 except collecty
._collecty
.PingNoReplyError
:
163 # Unknown but 100% loss
164 result
+= (None, None, 1)
167 except collecty
._collecty
.PingError
as e
:
168 self
.log
.warning(_("Could not run latency check for %(host)s: %(msg)s") \
169 % { "host" : self
.hostname
, "msg" : e
})
171 # A hundred percent loss
172 result
+= (None, None, 1)
177 class LatencyPlugin(base
.Plugin
):
179 description
= "Latency (ICMP ping) Plugin"
181 templates
= [GraphTemplateLatency
]
185 for hostname
in PING_HOSTS
:
186 yield LatencyObject(self
, hostname
)