Visualising Latency Variance in Grafana in 2019

SmokePing-like graphs in Grafana.

The Problem:

I use a tool called SmokePing to visualise my home internet latency. I run it in a Docker container. It's a very nice tool that is quick and easy to set up and produces graphs like this one below.

SmokePing Example Graph

This is a great solution to visualising latency but I also have a Grafana Docker container running for other purposes such as graphing my server's hard drive temperatures and my network throughput using InfluxDB and Telegraf. Grafana's graphs are also a lot more visually appealIing so I wanted to build a solution which would give me SmokePing-like graphs in Grafana.

SmokePing-like Grafana Graph

When trying to figure out the best way to accomplish this, I stumbled across this article by Tor Hveem from 2015. It showed how to make the exact graphs I wanted but used a custom pinging solution which doesn't compile any more due to changes with the InfluxDB Go API.

The Solution:

My solution was to use the same graphs but use the in-built pinging functionality of Telegraf.

First of all, you're going to need to set up Telegraf to connect to InfluxDB then add InfluxDB as a datasource in Grafana. That is not going to be covered by this article as there are plenty of resources for setting up InfluxDB already.

After you've got that going, you're going to need to uncomment the [[inputs.ping]] block in your telegraf.conf file. Edit the count to be more than 1 in order to get the variance of your latency otherwise your min and max ping are going to be the same. Add in as many URLs/IP addresses as you want to ping.

Here is a snippet from my configuration.

[[inputs.ping]]

## List of urls to ping

urls = ["208.67.222.222", "208.67.220.220", "8.8.8.8", "8.8.4.4", "1.1.1.1", "1.0.0.1", "facebook.com", "google.com", "youtube.com"]

## Number of pings to send per collection (ping -c <COUNT>)

count = 4

## Interval, in s, at which to ping. 0 == default (ping -i <PING_INTERVAL>)

## Not available in Windows.

ping_interval = 1.0

Now we need to set up Grafana to get the pretty graphs as shown above.

Add a new panel to Grafana.

Add four queries as pictured or written below.

SELECT min("minimum_response_ms") FROM "ping" WHERE ("url" = '1.1.1.1') AND $timeFilter GROUP BY time($__interval), "url" fill(none)

SELECT max("average_response_ms") FROM "ping" WHERE ("url" = '1.1.1.1') AND $timeFilter GROUP BY time($__interval), "url" fill(none)

SELECT max("maximum_response_ms") FROM "ping" WHERE ("url" = '1.1.1.1') AND $timeFilter GROUP BY time($__interval), "url" fill(none)

SELECT max("percent_packet_loss") FROM "ping" WHERE ("url" = '1.1.1.1') AND $timeFilter GROUP BY time($__interval), "url" fill(0)

Grafana Latency Graph Query Settings

Modify the visualisation like below.

Grafana Latency Graph Visualisation Settings

Conclusion:

Now you should have beautiful latency graphs. Just duplicate the panel and change the IP in the queries to show various latency graphs to different destinations.

SmokePing-like Grafana Graph

I would also recommend this great dashboard to show other latency metrics at a glance. Simply import the dashboard into your Grafana to get all these stats. It will automatically get the endpoints from your Telegraf configuration.

Internet Uptime Monitor Dashboard

Note: All the tools mentioned in this article are open source, free to self host, and have been linked to.