Using Grafana, InfluxDB and Telegraf on unRAID to monitor my Peplink Router

I wanted to graph and monitor my Internet usage. I already have some great system monitoring and graphing setup using Grafana, InfluxDB and Telegraf on my unRAID boxes by following PanzerschreckGER’s Reddit Tutorial.

This post will assume you have setup and are using the docker containers specified in the Reddit Tutorial and unRAID version 6.5.1 with a Peplink Balance One Router using Firmware version 7.1.0.

I decided the best way to get data from my Peplink Balance One Router was using SNMP thanks to this post by Alex Muthmann.

Preparation

Thanks to Reddit user /u/8ceyusp for pointing out that this preparation step is needed for most people!

To test your SNMP connection in this tutorial, you will need some SNMP tools installed on unRAID. SNMP requires perl to function properly, so you need to start with the NerdPack Plugin. If you have Community Applications installed, just search for NerdPack and install, or install it directly using this link. Once you have NerdPack installed, go to the Settings page of your unRAID server, select NerdPack and install Perl.

Now you will need to install the SNMP Plugin. This will give you the “snmpwalk” and “snmptable” commands that we will be using in this tutorial. If you have Community Applications installed, search for SNMP and install the plugin or install it directly using this link. Once it is installed, you can use the SNMP commands directly from your unRAID server command line.

Router Setup and testing

Log into your Peplink Router, go to System > SNMP and enable SNMPv2c . Make sure to set a SNMP port, or leave it the default. Press the “Add SNMP Community” button and add a community named whatever you like with the Allowed Network set to your server IP / 255.255.255.0 (/24).

Use Putty or your favorite terminal emulator to connect to your unRAID server as root.

Test that you can connect to your router using the “snmpwalk” tool in your terminal window.

snmpwalk -v 2c -c YOURCOMMUNITYNAMEHERE YOUR.ROUTER.IP.HERE

If it times out, you didn’t get it setup right. If you see a long list of values fly by, you should be good to go! As Mr. Muthmann explains in his post, you are interested in network related metrics in the “IF-MIB::” object and that the table we want is the same “ifXTable” that he references, with the same relevant fields of “ifHCInOctets” and “ifHCOutOctets”.

Since we have a Peplink Router with multiple WAN connections, we get a little different output when running the “snmptable” command

snmptable -v 2c -c YOURCOMMUNITYNAMEHERE YOUR.ROUTER.IP.HERE IF-MIB::ifXTable

SNMP table: IF-MIB::ifXTable ifName ifInMulticastPkts ifInBroadcastPkts ifOutMulticastPkts ifOutBroadcastPkts ifHCInOctets ifHCInUcastPkts ifHCInMulticastPkts ifHCInBroadcastPkts ifHCOutOctets ifHCOutUcastPkts ifHCOutMulticastPkts ifHCOutBroadcastPkts ifLinkUpDownTrapEnable ifHighSpeed ifPromiscuousMode ifConnectorPresent ifAlias ifCounterDiscontinuityTime LAN 0 0 0 0 361654455 2007507 0 0 2314308589 2194170 0 0 ? 1000 false true 0:0:00:00.00 Verizon Home Internet 0 0 0 0 0 0 0 0 0 0 0 0 ? 10 false true 0:0:00:00.00 Viaero 0 0 0 0 2319958951 2136455 0 0 197488127 1429547 0 0 ? 1000 false true 0:0:00:00.00

You can see that I get all of my prenamed Networks from my router, plus LAN traffic:

This is great! Now I can monitor all my WAN connections separately.

telegraf setup

You can setup your telegraf exactly as our reference post shows.

[[inputs.snmp]] agents = [ "YOUR.ROUTER.IP.HERE:YOURPORTHERE" ] version = 2 community = "YOURCOMMUNITYHERE" name = "snmp" [[inputs.snmp.field]] name = "hostname" oid = "RFC1213-MIB::sysName.0" is_tag = true [[inputs.snmp.table]] name = "snmp" inherit_tags = [ "hostname" ] oid = "IF-MIB::ifXTable" [[inputs.snmp.table.field]] name = "ifName" oid = "IF-MIB::ifName" is_tag = true

I did have to restart my telegraf docker container after adding the updates to the config file before I could get results, so consider doing that here. Because we are using a telegraf docker container, our test command is a little more complex, but works the exact same

docker exec -it telegraf telegraf --test | grep snmp

The command we use enters our docker and executes the “telegraf –test” command. Because I already setup telegraf, I have a LOT more output than the reference post shows, so I piped the output into a “grep snmp” command to limit it to the relevant lines. My output is as follows:

* Plugin: inputs.snmp, Collection 1 > snmp,agent_host=192.168.1.1,host=Cadderly,hostname=Balance_80D6,ifName=Verizon\ Home\ Internet ifPromiscuousMode=2i,ifName="Verizon Home Internet",ifInMulticastPkts=0i,ifHCInOctets=0i,ifHCInBroadcastPkts=0i,ifHCOutOctets=0i,ifHCOutMulticastPkts=0i,ifHCOutBroadcastPkts=0i,ifConnectorPresent=1i,ifInBroadcastPkts=0i,ifOutBroadcastPkts=0i,ifCounterDiscontinuityTime=0i,ifHCInUcastPkts=0i,ifHCOutUcastPkts=0i,ifHighSpeed=10i,ifOutMulticastPkts=0i,ifHCInMulticastPkts=0i 1525646854000000000 > snmp,agent_host=192.168.1.1,host=Cadderly,hostname=Balance_80D6,ifName=Viaero ifHCInMulticastPkts=0i,ifHCOutOctets=201315949i,ifOutMulticastPkts=0i,ifOutBroadcastPkts=0i,ifHCInOctets=2329963573i,ifHCInUcastPkts=2150702i,ifHCOutBroadcastPkts=0i,ifConnectorPresent=1i,ifCounterDiscontinuityTime=0i,ifInMulticastPkts=0i,ifHCInBroadcastPkts=0i,ifHighSpeed=1000i,ifPromiscuousMode=2i,ifInBroadcastPkts=0i,ifHCOutUcastPkts=1442436i,ifHCOutMulticastPkts=0i,ifName="Viaero" 1525646854000000000 > snmp,agent_host=192.168.1.1,host=Cadderly,hostname=Balance_80D6,ifName=LAN ifHCInMulticastPkts=0i,ifHCInBroadcastPkts=0i,ifHCInUcastPkts=2023701i,ifHCOutMulticastPkts=0i,ifHighSpeed=1000i,ifPromiscuousMode=2i,ifName="LAN",ifInMulticastPkts=0i,ifOutBroadcastPkts=0i,ifCounterDiscontinuityTime=0i,ifInBroadcastPkts=0i,ifOutMulticastPkts=0i,ifHCOutBroadcastPkts=0i,ifConnectorPresent=1i,ifHCInOctets=366093447i,ifHCOutOctets=2324360696i,ifHCOutUcastPkts=2209104i 1525646854000000000

Looking great! All my WAN and LAN connections are showing up!

Configuring grafana

When configuring your Grafana, the most important thing to remember is that the output of the SNMP is in Octets so it needs to be multiplied by 8 so that you can display your results in bits/sec. A major difference from the reference post is that we need to specify the “agent_host” to be the router IP, but also need to specify the “ifName” since we’re dealing with more than one WAN connection. I did an entry for both my WAN connections in one graph.

Based on a helpful tip from reddit user /u/pengee, to display the upload value below the y-axis, go to the “Display” tab, choose “series override” from the left side menu and press the “Add Override” button. In the “alias or regex” box, type your alias (for me, it is Viaero.upload) and add the “Transform: negative-y”.

For anybody that wants to copy/paste my JSON directly into their Grafana, here it is:

{ "aliasColors": {}, "bars": false, "dashLength": 10, "dashes": false, "datasource": "Cadderly", "fill": 1, "gridPos": { "h": 8, "w": 24, "x": 0, "y": 9 }, "id": 2, "legend": { "alignAsTable": true, "avg": false, "current": true, "max": true, "min": false, "rightSide": true, "show": true, "total": false, "values": true }, "lines": true, "linewidth": 1, "links": [], "nullPointMode": "null", "percentage": false, "pointradius": 5, "points": false, "renderer": "flot", "seriesOverrides": [ { "alias": "Viaero.Upload", "transform": "negative-Y" }, { "alias": "Verizon Home Internet.Upload", "transform": "negative-Y" } ], "spaceLength": 10, "stack": false, "steppedLine": false, "targets": [ { "alias": "$tag_ifName.$col", "groupBy": [ { "params": [ "$__interval" ], "type": "time" }, { "params": [ "ifName" ], "type": "tag" }, { "params": [ "null" ], "type": "fill" } ], "measurement": "snmp", "orderByTime": "ASC", "policy": "default", "refId": "A", "resultFormat": "time_series", "select": [ [ { "params": [ "ifHCInOctets" ], "type": "field" }, { "params": [], "type": "mean" }, { "params": [ "1s" ], "type": "derivative" }, { "params": [ "*8" ], "type": "math" }, { "params": [ "Download" ], "type": "alias" } ], [ { "params": [ "ifHCOutOctets" ], "type": "field" }, { "params": [], "type": "mean" }, { "params": [ "1s" ], "type": "derivative" }, { "params": [ "*8" ], "type": "math" }, { "params": [ "Upload" ], "type": "alias" } ] ], "tags": [ { "key": "agent_host", "operator": "=", "value": "192.168.1.1" }, { "condition": "AND", "key": "ifName", "operator": "=", "value": "Viaero" } ] }, { "alias": "$tag_ifName.$col", "groupBy": [ { "params": [ "$__interval" ], "type": "time" }, { "params": [ "ifName" ], "type": "tag" }, { "params": [ "null" ], "type": "fill" } ], "measurement": "snmp", "orderByTime": "ASC", "policy": "default", "refId": "B", "resultFormat": "time_series", "select": [ [ { "params": [ "ifHCInOctets" ], "type": "field" }, { "params": [], "type": "mean" }, { "params": [ "1s" ], "type": "derivative" }, { "params": [ "*8" ], "type": "math" }, { "params": [ "Download" ], "type": "alias" } ], [ { "params": [ "ifHCOutOctets" ], "type": "field" }, { "params": [], "type": "mean" }, { "params": [ "1s" ], "type": "derivative" }, { "params": [ "*8" ], "type": "math" }, { "params": [ "Upload" ], "type": "alias" } ] ], "tags": [ { "key": "agent_host", "operator": "=", "value": "192.168.1.1" }, { "condition": "AND", "key": "ifName", "operator": "=", "value": "Verizon Home Internet" } ] } ], "thresholds": [], "timeFrom": null, "timeShift": null, "title": "WAN Connections", "tooltip": { "shared": true, "sort": 0, "value_type": "individual" }, "type": "graph", "xaxis": { "buckets": null, "mode": "time", "name": null, "show": true, "values": [] }, "yaxes": [ { "format": "bps", "label": null, "logBase": 1, "max": null, "min": null, "show": true }, { "decimals": null, "format": "dtdurations", "label": null, "logBase": 1, "max": null, "min": null, "show": true } ], "yaxis": { "align": false, "alignLevel": null } }

Like this: Like Loading...