]>
git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/latency.py
c6cc5472559d8cb4721d2f9a1fdc715eb3730d06
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
33 class GraphTemplateLatency(base
.GraphTemplate
):
40 _
= self
.locale
.translate
43 "DEF:latency6=%(file)s:latency6:AVERAGE",
44 "DEF:loss6=%(file)s:loss6:AVERAGE",
45 "DEF:stddev6=%(file)s:stddev6:AVERAGE",
47 "DEF:latency4=%(file)s:latency4:AVERAGE",
48 "DEF:loss4=%(file)s:loss4:AVERAGE",
49 "DEF:stddev4=%(file)s:stddev4:AVERAGE",
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 "VDEF:latency6min=latency6,MINIMUM",
67 "VDEF:latency6max=latency6,MAXIMUM",
68 "VDEF:latency6avg=latency6,AVERAGE",
69 "VDEF:latency4min=latency4,MINIMUM",
70 "VDEF:latency4max=latency4,MAXIMUM",
71 "VDEF:latency4avg=latency4,AVERAGE",
73 "LINE1:latency6avg#00ff0066:%s" % _("Average latency (IPv6)"),
74 "LINE1:latency4avg#ff000066:%s\\r" % _("Average latency (IPv4)"),
76 "COMMENT:%s" % _("Packet Loss"),
77 "AREA:l005#ffffff:%s" % _("0-5%%"),
78 "AREA:l010#cccccc:%s" % _("5-10%%"),
79 "AREA:l025#999999:%s" % _("10-25%%"),
80 "AREA:l050#666666:%s" % _("25-50%%"),
81 "AREA:l099#333333:%s" % _("50-99%%") + "\\r",
83 "COMMENT: \\n", # empty line
86 "AREA:stddevarea4#ff000033:STACK",
87 "LINE2:latency4#ff0000:%s" % _("Latency (IPv4)"),
88 "GPRINT:latency4max:%12s\:" % _("Maximum") + " %6.2lf",
89 "GPRINT:latency4min:%12s\:" % _("Minimum") + " %6.2lf",
90 "GPRINT:latency4avg:%12s\:" % _("Average") + " %6.2lf\\n",
93 "AREA:stddevarea6#00ff0033:STACK",
94 "LINE2:latency6#00ff00:%s" % _("Latency (IPv6)"),
95 "GPRINT:latency6max:%12s\:" % _("Maximum") + " %6.2lf",
96 "GPRINT:latency6min:%12s\:" % _("Minimum") + " %6.2lf",
97 "GPRINT:latency6avg:%12s\:" % _("Average") + " %6.2lf\\n",
101 def graph_title(self
):
102 _
= self
.locale
.translate
103 return _("Latency to %s") % self
.object.hostname
106 def graph_vertical_label(self
):
107 _
= self
.locale
.translate
108 return _("Milliseconds")
111 def rrd_graph_args(self
):
113 "--legend-direction=bottomup",
117 class LatencyObject(base
.Object
):
119 "DS:latency6:GAUGE:0:U",
120 "DS:stddev6:GAUGE:0:U",
121 "DS:loss6:GAUGE:0:100",
122 "DS:latency4:GAUGE:0:U",
123 "DS:stddev4:GAUGE:0:U",
124 "DS:loss4:GAUGE:0:100",
128 return "<%s %s>" % (self
.__class
__.__name
__, self
.hostname
)
130 def init(self
, hostname
):
131 self
.hostname
= hostname
140 for family
in (socket
.AF_INET6
, socket
.AF_INET
):
142 p
= collecty
._collecty
.Ping(self
.hostname
, family
=family
)
143 p
.ping(count
=5, deadline
=10)
145 result
+= (p
.average
, p
.stddev
, p
.loss
)
147 except collecty
._collecty
.PingAddHostError
as e
:
148 self
.log
.debug(_("Could not add host %(host)s for family %(family)s") \
149 % { "host" : self
.hostname
, "family" : family
})
152 result
+= (None, None, None)
155 except collecty
._collecty
.PingError
as e
:
156 self
.log
.warning(_("Could not run latency check for %(host)s: %(msg)s") \
157 % { "host" : self
.hostname
, "msg" : e
})
159 # A hundred percent loss
160 result
+= (None, None, 1)
165 class LatencyPlugin(base
.Plugin
):
167 description
= "Latency (ICMP ping) Plugin"
169 templates
= [GraphTemplateLatency
]
173 for hostname
in PING_HOSTS
:
174 yield LatencyObject(self
, hostname
)