From eb06d20a67dbdbc039f730798b5e1f9345542f62 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 24 Sep 2020 14:01:42 +0000 Subject: [PATCH] latency: Refactor graph Signed-off-by: Michael Tremer --- src/collecty/colours.py | 4 +-- src/collecty/constants.py | 1 + src/collecty/plugins/latency.py | 62 +++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/collecty/colours.py b/src/collecty/colours.py index 570a619..a539157 100644 --- a/src/collecty/colours.py +++ b/src/collecty/colours.py @@ -43,14 +43,14 @@ def _add(colour, amount): return "#%s" % ret.hex() -def lighten(colour, scale=0.1): +def lighten(colour, scale=0.25): """ Takes a hexadecimal colour code and brightens the colour. """ return _add(colour, scale) -def darken(colour, scale=0.1): +def darken(colour, scale=0.25): """ Takes a hexadecimal colour code and darkens the colour. diff --git a/src/collecty/constants.py b/src/collecty/constants.py index 952ab77..7fd13be 100644 --- a/src/collecty/constants.py +++ b/src/collecty/constants.py @@ -78,6 +78,7 @@ FLOAT = "%14.2lf" LARGE_FLOAT = "%12.2lf %s" BPS = "%9.2lf %sbps" PPS = "%9.2lf %spps" +MS = "%11.2lf ms" EMPTY_LINE = "COMMENT: \\n" HEADLINE = "COMMENT:---- %s ----\\c" diff --git a/src/collecty/plugins/latency.py b/src/collecty/plugins/latency.py index aa5fe8f..3334782 100644 --- a/src/collecty/plugins/latency.py +++ b/src/collecty/plugins/latency.py @@ -26,6 +26,7 @@ from ..i18n import _ from . import base from ..colours import * +from ..constants import * PING_HOSTS = [ # gateway is a special name that is automatically @@ -45,7 +46,6 @@ class GraphTemplateLatency(base.GraphTemplate): def rrd_graph(self): _ = self.locale.translate - colour_bg = AMBER return [ # Compute the biggest loss and convert into percentage "CDEF:ploss=loss6,loss4,MAX,100,*", @@ -62,45 +62,61 @@ class GraphTemplateLatency(base.GraphTemplate): "CDEF:l050=ploss,25,50,LIMIT,UN,UNKN,INF,IF", "CDEF:l099=ploss,50,99,LIMIT,UN,UNKN,INF,IF", - "LINE2:latency6_avg%s:%s" % ( - transparency(COLOUR_IPV6, .5), - _("Average latency (IPv6)"), + # Draw average lines + "LINE:latency6_avg%s::dashes" % ( + lighten(COLOUR_IPV6), ), - "LINE2:latency4_avg%s:%s\\r" % ( - transparency(COLOUR_IPV4, .5), - _("Average latency (IPv4)"), + "LINE:latency4_avg%s::dashes" % ( + lighten(COLOUR_IPV4), ), + # Colour background on packet loss "COMMENT:%s" % _("Packet Loss"), "AREA:l005%s:%s" % ( - transparency(colour_bg, .2), _("0-5%"), + transparency(BLACK, .2), _("0-5%"), ), "AREA:l010%s:%s" % ( - transparency(colour_bg, .4), _("5-10%"), + transparency(BLACK, .4), _("5-10%"), ), "AREA:l025%s:%s" % ( - transparency(colour_bg, .6), _("10-25%"), + transparency(BLACK, .6), _("10-25%"), ), "AREA:l050%s:%s" % ( - transparency(colour_bg, .8), _("25-50%"), + transparency(BLACK, .8), _("25-50%"), ), - "AREA:l099%s:%s\\r" % (colour_bg, _("50-99%")), + "AREA:l099%s:%s\\r" % (BLACK, _("50-99%")), - "COMMENT: \\n", # empty line + EMPTY_LINE, + # Plot standard deviation "AREA:spacer4", - "AREA:stddevarea4%s:STACK" % lighten(COLOUR_IPV4, STDDEV_OPACITY), - "LINE2:latency4%s:%s" % (COLOUR_IPV4, _("Latency (IPv4)")), - "GPRINT:latency4_max:%12s\:" % _("Maximum") + " %6.2lf", - "GPRINT:latency4_min:%12s\:" % _("Minimum") + " %6.2lf", - "GPRINT:latency4_avg:%12s\:" % _("Average") + " %6.2lf", + "AREA:stddevarea4%s:STACK" % transparency(COLOUR_IPV4, STDDEV_OPACITY), + "LINE2:latency4%s:%s" % ( + COLOUR_IPV4, + LABEL % _("Latency (IPv4)"), + ), + "GPRINT:latency4_cur:%s" % MS, + "GPRINT:latency4_avg:%s" % MS, + "GPRINT:latency4_min:%s" % MS, + "GPRINT:latency4_max:%s\\j" % MS, "AREA:spacer6", - "AREA:stddevarea6%s:STACK" % lighten(COLOUR_IPV6, STDDEV_OPACITY), - "LINE2:latency6%s:%s" % (COLOUR_IPV6, _("Latency (IPv6)")), - "GPRINT:latency6_max:%12s\:" % _("Maximum") + " %6.2lf", - "GPRINT:latency6_min:%12s\:" % _("Minimum") + " %6.2lf", - "GPRINT:latency6_avg:%12s\:" % _("Average") + " %6.2lf", + "AREA:stddevarea6%s:STACK" % transparency(COLOUR_IPV6, STDDEV_OPACITY), + "LINE2:latency6%s:%s" % ( + COLOUR_IPV6, + LABEL % _("Latency (IPv6)"), + ), + "GPRINT:latency6_cur:%s" % MS, + "GPRINT:latency6_avg:%s" % MS, + "GPRINT:latency6_min:%s" % MS, + "GPRINT:latency6_max:%s\\j" % MS, + + # Headline + "COMMENT:%s" % EMPTY_LABEL, + "COMMENT:%s" % (COLUMN % _("Current")), + "COMMENT:%s" % (COLUMN % _("Average")), + "COMMENT:%s" % (COLUMN % _("Minimum")), + "COMMENT:%s\\j" % (COLUMN % _("Maximum")), ] @property -- 2.47.2