Skip to main content

Raymii.org Raymii.org Logo

Quis custodiet ipsos custodes?
Home | About | All pages | Cluster Status | RSS Feed

Line total (up+down sum) in PHP Network Weathermap

Published: 13-11-2018 | Author: Remy van Elst | Text only version of this article


❗ This post is over five years old. It may no longer be up to date. Opinions may have changed.


With PHP Network Weathermap you can create a birds-eye view of network components from your monitoring system (like LibreNMS, Cacti or anything else with an RRD database). It can display simple maps with components and links between, showing up and down traffic, but also complex systems with custom components, like Nagios status, temperature or other information. For network and system administrators seeing the seperate in and out traffic of a link is fine, we can sum up two numbers. A co worker filling the role of service manager asked me if it was possible to sum up in and out and show that, including the scale (different colours depending on link usage). This co worker is not interested in the seperate up/down link speed but wants to know how much traffic a location is using in total. Using a clever workaround, you can display a line's total usage, including the scale. This article also gives some more tips on weathermap, colouring and scale.

Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:

I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!

Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.

You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $200 credit for 60 days. Spend $25 after your credit expires and I'll get $25!

Example

The picture below shows a section of a weathermap to a location, where the line is a 20 mbit line. The first picture is without the total summary. Green means 40-50% usage and yellow means 55-70% usage. It is not very clear that the line is at max capacity if you just see yellow and green:

By adding the total (sum of up and down) it is clear right away that this line is at max capacity:

Here is another example:

Configuration

The weathermap has the concept of "nodes" and "links". A node has one or more links and a link is between two nodes. A link has a "target", which points to an RRD file in most cases. There is no math support in the configuration syntax, so you cannot say "up + down" in the label. But, you can add multiple RRD files to the "target" of a link, for example when you want to show multiple lines which form one logical unit.

I found a forum post that stated that "nodes" can also have targets. You can do more advanced mapping with custom data formats with this, but in our case we can also use it to sum up the links.

The trick is that a target configuration line has this format:

filename.rrd:INOCTETS:OUTOCTETS

By replacing the parameters with a dash (-), that part is ignored. So, we can add the same RRD file two times and specifying the INOCTETS and OUTOCTETS as "in" and placing - as out. The weathermap will add up all the "in" data, which, because we added the same file, is a sum of up and down. Here is an example, for a 10 mbit line:

NODE amersfoort
        LABEL Amersfoort
        INFOURL https://[...]/librenms/device/device=461/
        OVERLIBGRAPH https://[...]/librenms/graph.php?width=...
        ICON images/Router.png
        POSITION 580 280


NODE amersfoortSUM
        LABEL {node:this:bandwidth_in:%k}
        LABELFONT 3
        LABELFONTCOLOR contrast
        TARGET ./amersfoort/port-id10886.rrd:INOCTETS:- ./amersfoort/port-id10886.rrd:OUTOCTETS:-
        POSITION amersfoort 0 +20
        MAXVALUE 10M

In the documentation this is explained:

You can also specify '-' for either DS name, which tells Weathermap to ignore this rrd file for the purposes of the input or output value. This is mainly useful in combination with the aggregation feature, where you can take the input data from one rrd file, and the output data from another.

We do a few things next to the two target files. As you can see, the LABEL line is:

{node:this:bandwidth_in:%k}

These advanced parameters are explained in the Weathermap advanced documentation.

The POSITION is relative to the "amersfoort" node. Since there is no way to do newlines in a label (due to gd issues) I choose this way. Also, this way the label of the actual node stays white, which makes the entire drawing less cluttered.

The MAXVALUE line in the NODE part is the same as the BANDWIDTH part of a LINK. This value is needed for the SCALE.

The LABELFONTCOLOR contrast is one of those other wonderfull well thought through parts of this software. Depending on the scale and load, the background of the link or node can be dark or light. If you manually specify this node to have a white background, then that will be hard to read when the load is 0-1% or 40-70%, since those loads trigger a white, light yellow or light green background.

The contrast option lets the weathermap figure out what text colour is best for this scale. So, dark scale colours have white text and light scale colors have black text. These two example show that:

To get the total amount for a device with many ports, like an 48 port switch, you can use a for loop to get the correct syntax. This example is for LibreNMS, but speaks for itself (go to correct folder, loop over all files):

cd /opt/librenms/rrd/
for i in  ./device.ext/port-id*.rrd; do echo -n "$i:INOCTETS:- $i:OUTOCTETS:- "; done

You should place the entire line (make sure there are no newlines) after the TARGET section in the NODE.

Scale

I've slightly changed the default scale, adding one step from 95% to 100%, the default is 85% to 100%. Here is the scale image:

This is the weathermap config:

KEYPOS DEFAULT 14 580 Traffic Load
KEYTEXTCOLOR 0 0 0
KEYOUTLINECOLOR 0 0 0
KEYBGCOLOR 255 255 255
BGCOLOR 255 255 255
TITLECOLOR 0 0 0
TIMECOLOR 0 0 0
SCALE DEFAULT 0    0    192 192 192
SCALE DEFAULT 0    1    255 255 250
SCALE DEFAULT 1    10   140   0 255
SCALE DEFAULT 10   25    32  32 255
SCALE DEFAULT 25   40     0 192 255
SCALE DEFAULT 40   55     0 240   0
SCALE DEFAULT 55   70   240 240   0
SCALE DEFAULT 70   85   255 192   0
SCALE DEFAULT 85   95   255   0 144
SCALE DEFAULT 95   100  163   1   1

SET key_hidezero_DEFAULT 1

If you have capacity problems, it's helps (in our case at least) to see just a bit more detail, like so:

Weathermap example

The below picture shows one of my weathermaps for a network overview of all the satelite locations (connected to one main office via an MPLS network):

Tags: bash , icinga , librenms , logging , monitoring , nagios , network-weathermap , observium , php-weathermap , plugin , python , rrd , tutorials