Part II (FreeNAS): Advanced SNMP monitoring, part two: FreeNAS
Part III (pfSense): TBC
Note: the initial tutorial used the exec directive which has been deprecated from the Asuswrt firmware. For completeness purposes I’ve left also the initial values.
SNMP already provides some OIDs (such as 1/5/15 load, CPU time, etc); however, most of the items included in the router’s GUI (temperature, memory usage, CPU usage) are not available through SNMP.
Although 1/5/15 loads are available over SNMP, CPU usage is a rather different animal. Additional description of the two: https://en.wikipedia.org/wiki/Load_(computing)
In order to extend the depth of the info available, results of scripts could be passed to SNMP (by using an empty OID - started with .1.3.6.1.2.1.25.1.8) by loading them into snmpd.conf (from /jffs/configs).
Probably this works on other routers that are based on Linux kernel too (Tomato, dd-wrt, etc).
This topic doesn’t deal with setting up the router (or installation of Merlin build) or with the security aspects of enabling SNMP access over external access.
Use at own risk!!!
Requirements:
- Asus router with Merlin build;
- SNMP monitoring activated (Administration->SNMP);
- JFFS custom scripts and configs enabled (Administration->System); additional info: https://github.com/RMerl/asuswrt-merlin/wiki/Custom-config-files
- SSH client.
Step 1: Create snmpd.conf.add file in /jffs/configs
nano /jffs/configs/snmpd.conf.add
Populate the file with the links to the scripts used:
extend .1.3.6.1.2.1.25.1.8 temp /bin/sh /jffs/scripts/snmp/temp.sh
extend .1.3.6.1.2.1.25.1.9 dhcp /bin/sh /jffs/scripts/snmp/dhcp.sh
extend .1.3.6.1.2.1.25.1.10 connected /bin/sh /jffs/scripts/snmp/connected.sh
extend .1.3.6.1.2.1.25.1.11 chip1 /bin/sh /jffs/scripts/snmp/chip1.sh
extend .1.3.6.1.2.1.25.1.12 chip2 /bin/sh /jffs/scripts/snmp/chip2.sh
extend .1.3.6.1.2.1.25.1.13 mem /bin/sh /jffs/scripts/snmp/mem.sh
extend .1.3.6.1.2.1.25.1.14 idle /bin/sh /jffs/scripts/snmp/idle.sh
extend .1.3.6.1.2.1.25.1.15 uptime /bin/sh /jffs/scripts/snmp/uptime.sh
extend .1.3.6.1.2.1.25.1.16 jffs /bin/sh /jffs/scripts/snmp/jffs.sh
Step 2: create the scripts on the router with the following form:
nano /jffs/scripts/snmp/name_of_the_script.sh
-
processor temperature
#!/bin/sh
output=$(cat /proc/dmu/temperature); echo $output | cut -c19-20
-
number of active DHCP leases
#!/bin/sh
cat /var/lib/misc/dnsmasq.leases| wc -l
-
number of connected clients
#!/bin/sh
arp -a | awk '$4!="<incomplete>"' | wc -l
-
wireless chips temperature
-
Chip1 (2.4Ghz)
#!/bin/sh
wl -i eth1 phy_tempsense | awk '{print $1}'
-
Chip2 (5Ghz)
#!/bin/sh
wl -i eth2 phy_tempsense | awk '{print $1}'
-
Memory Used
#!/bin/sh
top -bn1 | head -3 | awk '/Mem/ {print $2}'
-
Idle processor (in HA the usage is computed by 100 - idle)
#!/bin/sh
top -bn1 | head -3 | awk '/CPU/ {print $8}'
-
Uptime
#!/bin/sh
uptime | cut -d ',' -f1 | sed 's/^.\{12\}//g'
-
JFFS (or other disk, just replace jffs with sdx) used space
#!/bin/sh
df | awk '/jffs/ {print $5}'
Step 3: create Home Assistant sensors
- platform: snmp
host: ip.of.your.router
baseoid: 1.3.6.1.2.1.25.1.8.3.1.1.4.116.101.109.112 #previous (with exec directive) 1.3.6.1.2.1.25.1.8.101.1
name: router_temp
accept_errors: true
default_value: 0
value_template: '{{value | float | round (0) }}'
version: 2c
unit_of_measurement: '°C'
scan_interval: 35
- platform: snmp
host: ip.of.your.router
baseoid: 1.3.6.1.2.1.25.1.9.3.1.1.4.100.104.99.112 #previous (with exec directive) 1.3.6.1.2.1.25.1.9.101.1
name: router_dhcp_leases
accept_errors: true
default_value: 0
value_template: '{{value | float | round (0) }}'
version: 2c
unit_of_measurement: ' '
scan_interval: 35
- platform: snmp
host: ip.of.your.router
baseoid: 1.3.6.1.2.1.25.1.10.3.1.1.9.99.111.110.110.101.99.116.101.100 #previous (with exec directive) 1.3.6.1.2.1.25.1.10.101.1
name: router_connected
accept_errors: true
default_value: 0
value_template: '{{value | float | round (0) }}'
version: 2c
unit_of_measurement: ' '
scan_interval: 35
- platform: snmp
host: ip.of.your.router
baseoid: 1.3.6.1.2.1.25.1.11.3.1.1.5.99.104.105.112.49 #previous (with exec directive) 1.3.6.1.2.1.25.1.11.101.1
name: router_24_temp
accept_errors: true
default_value: 0
value_template: '{{value | float | round (0) }}'
version: 2c
unit_of_measurement: '°C'
scan_interval: 35
- platform: snmp
host: ip.of.your.router
baseoid: 1.3.6.1.2.1.25.1.12.3.1.1.5.99.104.105.112.50 #previous (with exec directive) 1.3.6.1.2.1.25.1.12.101.1
name: router_5_temp
accept_errors: true
default_value: 0
value_template: '{{value | float | round (0) }}'
version: 2c
unit_of_measurement: '°C'
scan_interval: 35
- platform: snmp
host: ip.of.your.router
baseoid: 1.3.6.1.2.1.25.1.13.3.1.1.3.109.101.109 #previous (with exec directive) 1.3.6.1.2.1.25.1.13.101.1
name: router_mem
accept_errors: true
default_value: 0
value_template: '{{((value | replace("K","") | float ) /5000 | float ) | round (0) }}'
version: 2c
unit_of_measurement: '%'
scan_interval: 35
- platform: snmp
host: ip.of.your.router
baseoid: 1.3.6.1.2.1.25.1.14.3.1.1.4.105.100.108.101 #previous (with exec directive) 1.3.6.1.2.1.25.1.14.101.1
name: router_proc
accept_errors: true
default_value: 0
version: 2c
value_template: '{{( 100 - (value | replace("%","")) | float )| round (2) }}'
unit_of_measurement: '%'
scan_interval: 35
Step 4: Customize sensors (icons, names, grouping etc)
Bonus: Lovelace card (most of the info from the router’s webpage and also switches for blocking internet access: Internet kill switch (for both wireless & wired devices)
card:
cards:
- content: >
[Web access Router](http://192.168.0.1) Uptime:
{{states.sensor.ac88u_uptime.state}}
type: markdown
- cards:
- entity: sensor.ac88u_dhcp_leases
title: Leases
type: 'custom:bignumber-card'
- entity: sensor.ac88u_connected
title: Connected
type: 'custom:bignumber-card'
type: horizontal-stack
- entities:
- sensor.wan_traffic_in_2
- sensor.wan_traffic_out_2
type: history-graph
- cards:
- entity: sensor.ac88u_proc
severity:
green: 50
red: 90
yellow: 80
type: gauge
- entity: sensor.ac88u_temp
max: 120
min: 60
severity:
green: 80
red: 120
yellow: 90
type: gauge
type: horizontal-stack
- bar_style: null
entity: sensor.ac88u_15min_load
height: 35 px
max: 2
min: 0
padding-left: 2px
severity:
- color: seagreen
value: 0.7
- color: orange
value: 0.8
- color: red
value: 1.5
text-align: left
title: Processsor load
title_position: inside
type: 'custom:bar-card'
- entities:
- entity: sensor.ac88u_15min_load
- entity: sensor.ac88u_1min_load
type: history-graph
- bar_style: null
entity: sensor.ac88u_mem
height: 35 px
max: 100
min: 0
padding-left: 2px
severity:
- color: seagreen
value: 70
- color: orange
value: 80
- color: red
value: 96
text-align: left
title: Memory use
title_position: inside
type: 'custom:bar-card'
- entities:
- sensor.ac88u_mem
type: history-graph
- entities:
- entity: switch.receiver
- entity: switch.xbox_one
- entity: switch.dvd
show_header_toggle: false
title: Block internet access
type: entities
title: AC88u
type: 'custom:vertical-stack-in-card'
type: 'custom:card-loader'
wait:
- bar-card
- bignumber-card
- vertical-stack-in-card