This is third in series of posts on monitoring your wireless router. In this post we will setup a script to pull temperature information from the router and expose it to prometheus using node exporter. Check this post if you need instructions on how to setup node exporter on your router.
Caution: There is very little chance that these instructions will be portable as-is to any firmware other than Asus WRT Merlin.
I have an Asus RT-AC68U with AsusWRT-Merlin firmware installed on it. This allows me to setup cron jobs and custom scripts on the router which is required to setup the monitoring. The instructions here should work on other Asus routers with Meriln firmware but are unlikely to work on other firmwares.
For pulling and persisting the metrics I am be using Prometheus which is an open-source monitoring solution. I have it installed on a home server which is up 24x7 and connected to the router. A static IP is configured for the server which makes things convenient but the setup will also work with a dynamic IP address assignment.
Prerequisites
You need to be able to SSH into the router and have node_exporter installed on it. Check here
for instructions on how to setup node exporter on your router. You need to enable Custom JFFS scripts from Administration > System
in your WebUI.
For the sake of this post I am assuming that we have an external USB stick connected to the router which is mounted at /mnt/<disk>
and we have following
directory structure created:
/mnt/<disk> |- bin |- etc |- services |- var |- log |- run |- lib |- node_exporter |- home |- user |- tmp
You can create the directory structure using following command. (Change <disk> to the name of your disk.)
Setting up the script
We will be storing the data extraction script on the external drive. Create a file /mnt/<disk>/bin/hw-temp
with following content in it.
The script will report following 4 metrics:
router_temperature_duration_seconds
: runtime ofnvram_free
script in secondsrouter_temperature_last_run_seconds
: unix timestamp of last runrouter_temperature_celcius
: current temperature. This metric is exported with a labeltype
:cpu
: Current CPU temperatureantenna_5
: 5G antenna temperatureantenna_24
: 2.4G antenna temperature
Mark this script as executable.
Run the script once and check if it creates the text file with metrics in /mnt/<disk>/var/lib/node_exporter/temperature.prom
. Following is a sample content from file.
router_temperature_celcius{type="cpu"} 73 router_temperature_celcius{type="antenna_5"} 54 router_temperature_celcius{type="antenna_24"} 51 router_temperature_duration_seconds 0 router_temperature_last_run_seconds 1596466501
Next we setup cron job to run this script every minute using the cru
command.
The cron job entry will be gone after reboot. To persist it we will need to add the command to user script which is called on boot. Since we
are storing the hw-temp
command on external disk we also need to ensure that the disk is mounted before we add the cron job. We will be
using the post-mount
script. Create a file /jffs/scripts/post-mount
if it not already exists. Add following content to the file. The
post-mount
script is passed the mountpoint as the first argument.
Now we have a script which periodically checks the temperature and reports the data in prometheus format in a file. The only thing remaining is to
tell our node exporter to pickup the file on every scrape. To do this change the startup command for node exporter by adding --collector.textfile.directory
parameter. If you followed the first post to setup the node exporter following is the updated service script.
To restart the node exporter you can use following commands.
Thats it! You can visit http://<your_router_ip>:9101/metrics
and check if router_temperature_
metrics are being reported.