Monitor DD-WRT CPU Temp, load, and free ram: How I did it

Just flashed my old TP-Link Archer C9v1 with dd-wrt and it is working fine. I just want to have a glance of the router CPU Temperature, load and free ram. The end result looks like this:
image

FYI, my Hassio runs on Ubuntu server.

The rather simple ones are CPU load and free ram which has known SNMP OID values. The more complicated part is the CPU temperature which needs more steps to achieve.

CPU Load:
For the CPU load, I can find only the SNMP OID values for the 1-min, 5-min, and 15-min average load. So I use the 1-min average load to convert to percentage. Due to a dual-core CPU, the average load value 2 should represent 100% (both cores run at full load).

ps. Don’t forget to enable SNMP in your router, under Services tab, and set a more secured RO Community password.

SNMP OID values:
cpu avg load 1 min .1.3.6.1.4.1.2021.10.1.3.1
cpu avg load 5 min .1.3.6.1.4.1.2021.10.1.3.2
cpu avg load 15 min .1.3.6.1.4.1.2021.10.1.3.3

In configuration.yaml, under sensors section:

# Archer C9 CPU Load
  - platform: snmp
    name: AP C9 CPU Load
    host: 192.168.2.254
    community: !secret snmp_community_C9
    baseoid: 1.3.6.1.4.1.2021.10.1.3.1
    accept_errors: true
    unit_of_measurement: '%'
    # Dual CPU, so if value is 2, it means 100%, so multiply by 50
    value_template: '{{ value | multiply(50) | round(1) }}'

Ram Free:
total ram free OID: .1.3.6.1.4.1.2021.4.11.0
it keeps ram free value in KB, I converted it to MB

In configuration.yaml, under sensors section:

# Archer C9 Ram free
  - platform: snmp
    name: AP C9 RAM Free
    host: 192.168.2.254
    community: !secret snmp_community_C9
    baseoid: 1.3.6.1.4.1.2021.4.11.0
    accept_errors: true
    unit_of_measurement: 'MB'
    value_template: '{{ value | multiply(0.001) | round(1) }}'

CPU Temperature:
The CPU temperature in my dd-wrt router is stored in file: /proc/dmu/temperature . The stored value must be divided by 10 to get the correct degree celcius.
image
I then have to create a script on my Hassio server and use cron job (at root level) to run it every minute (you can use a longer interval). The script is basically copying the raw temp value from my router to homeassistant config subfolder (mine is /usr/share/hassio/homeassistant/ddwrt).

However, we cannot simply copy it across server with a single steps. Here is my script:

#1/bin/sh
#copy temperature data from pseudo file on ddwrt to a temp file on ddwrt
ssh [email protected] 'cat /proc/dmu/temperature > /tmp/var/tmp/cpu_temp.txt'
#copy temperature data from a temp file on ddwrt to homeassistant config subdirectory
scp [email protected]:/tmp/var/tmp/cpu_temp.txt /usr/share/hassio/homeassistant/ddwrt/cpu_temp.txt

The cron job on my Hassio server (by using ‘sudo crontab -e’ command)

*/1 * * * * sh /home/yourusername/archerc9cputemp.sh

The reason to run cron job at root level because I need to copy the temperature file to the root folder (Homeassistant folders, for me, at ’ /usr/share/hassio/homeassistant/ddwrt’).

A preparation before running the above script is that both the ssh and scp commands in the script requires you to gen private and public keys on your Hassio server at root level (using command ‘ssh-keygen’ at root user). Then you have to copy the content inside the generated public key file to the DD-WRT router (open DD-WRT gui, Services tab)

Once you have both keys in the proper places, the above script can run as a background job without interactive inputs.

2 Likes

This is really cool. I should try something like this on my DD-WRT. One question - what is snmp_community_C9 you’ve got in this line and what is it for?

community: !secret snmp_community_C9

To access snmp data on your router, you need to specify the right snmp read-only password which you set on your router. I kept the password in the secured secrets.yaml file instead of putting it in plain sight in the less-secured configuration.yaml file.

Thanks. I do know about the way to keep secrets in a separate file, just wasn’t aware about the snmp password, but that makes sense.

Thanks for this. I Struggled to find my own OID, but I got it to work.
But I noticed that sometimes some negatives values are calculated for both in and out sensors (mbps).
Did you notice any issue like this? So the graph turns to be a mess. But most of the time, numbers seem to be right.
image

I’ve never monitored download/upload speed. Could you share the OIDs? I may try it and see how it goes.

Sorry, I posted in the wrong thread.
You can follow the right one here.
I used OID: 1.3.6.1.2.1.2.2.1.10.11 (IN) 1.3.6.1.2.1.2.2.1.16.11 (OUT)

Wanted to revive this since this thread is a top result for getting temperature from DD-WRT. I didn’t want to go through the trouble above with generating the keys, enabling ssh, etc and found an easier way to accomplish it.

In configuration.yaml

rest:
  - authentication: basic
    username: "admin"
    password: !secret ddwrt_pw
    scan_interval: 60
    resource: https://router_ip/Status_Router.live.asp
    verify_ssl: false
    sensor: 
      - name: "DDWRT-Temp"
        value_template: "{{ ((value.split('cpu_temp::CPU')[1] | regex_findall_index('\\d+\\.?\\d*') | float) * 9/5) + 32 | round }}"

This is giving it to me in Fahrenheit. If you want Celsius just modify the template.
I am on 49866

1 Like