book collections email follower instructable user
Picture of How to graph home router metrics

Isn't the tech-world wonderful? All these great services and free softwares popping up everywhere. I would like to share my first experience with Grafana and InfluxDB with the purpose of making persistent, beautiful, flexible graphs of your router stat's.

The problem: My router metrics are to be found all over the place in the Web-UI. Some measurements offer real-time graphs over the last couple of minutes, some don't. All stat's are reset when I reboot. I want to back in time and see throughput, temperatures, etc.

The solution: InfluxDB for persistent storage and Grafana for visualization.

InfluxDB is a so called Time Series Database (TSDB) which is specialized for storing data history, tag-value-time.

Grafana is a free self contained web-based graphing tool for InfluxDB (and other TSDBs).

Both softwares are easy to get started with yet powerful. By the way, I am in no way affiliated with eiter project. This project is just to get you going. Once you get started you may find that yourself graphing all sorts of things. This is very well suited for IOT-applications. E. g. I am using the same setup for home automation sensor metrics (temperatures, humidity, etc.) in conjunction with Openhab.

Flames and praise in the comments, please. And let me know if something doesn't work so I can fix it!

Step 1: Prerequisites

The router

In order to get started with this project you need a Linux based router with the following features:

  1. Command line login root access (telnet or ssh)
  2. Cron support
  3. Local file store on internal JFFS or USB storage. This is for storing scripts.

The above features usually don't come in stock firmware so you probably have to go with DDWRT, Tomato or similar. In my case I use ASUSWRT Merlin. ASUS had the good sense to open-source their stock firmware and the Merlin build adds minimal but crucial features. I used a ASUS RT-N66U for this project.

The server

The second pre-req is a x86-based Linux server. It doesn't have to be super powerful. For this project I used a HP microserver with Ubuntu Server 13.04 LTS and 4GB RAM. In theory you could run this off a different processor architecture (e. g. ARM) but you would not be able to use the pre-built packages. The server doesn't have to be dedicated for InfluxDB.

A PC

You need a PC or Mac with terminal software (e. g. Putty or MobaXterm. I prefer the latter).

Some knowledge

This Instructable is for people who have a basic understanding of command-line Linux,

zandrsn1 year ago

Thanks for the super useful instructions! I'm running into a problem with the todb.sh script. I used vi to create all of these script in the /jffs/scripts/routerstats/ directory on my RT-A87U router. After making them all executable I am able to run ./routerstats.sh without receiving any errors. However for some reason the data from these scripts is not reaching my influxDB database.... I updated the dbname and dbhost variable as required, but otherwise I can't really figure out what the problem is. Any ideas how I can figure this out? Thanks!

Just revisiting this instructable after playing with it about a year ago. the influxDB api's have changed since this was created, try this in the todb.sh to insert the payload.

wget --quiet --post-data "$payload" "http://$dbhost/write?db=$dbname" -O /dev/null

ehsmaes (author)  zandrsn1 year ago

Hi, Unfortunately the router I did this project on has been thrown out by now so I can't really look into it. However, one thing to check might be the influx data format. They evolve fast and I am pretty sure that the input format has changed. Unless you installed the old version used in the guide.

BilliamG2 years ago
Has anyone created any additional scripts to go along with the six provided?
birdjazz2 years ago

First thing: thanks for the clear instructions!

Quick note for others: be sure to install the versions mentioned for Influx, then when Grafana is installed, you should need the Influx 0.8x plugin.

My router is a different model, the RT-AC68U. I was able to install the scripts, test them, add them to Cron, get results in Influx. Looks good, but I will need to fiddle with the Internet Throughput, the numbers are off, this is surely due to the different model.

My actual question, is: I imported the included json into Grafana. I now have a Router Stats Dashboard with 6 panels for CPU, memory, temp, etc... My problem is that all panels have a warning message "Cannot read property '_seriesQuery' of undefined".

Possiblilities: The Grafana version is much higher than the posted version.

If I find an answer I will Post!

ScottS3722 years ago

2 things:

I don't have nice available on my router.

/jffs/bin/routerstats.sh: line 7: nice: not found

I can fix this by just removing the nice part of the script and run the sh file directly but I am still getting a permission error no matter what I try. All scripts are executable.

/jffs/bin/router_mem.sh: line 8: /jffs/bin/todb.sh: Permission denied

(I only enabled the one script for testing)

Are you still around having issues, mate?

@ehsmaes, are you still around mate? If so, I'd love to chat with you regarding this guide!