Logging Gateway Statistics from OPNsense to InfluxDB using Node-Red
I log data from my OPNsense firewall using Telegfaf, but there are some statistics in OPNsense which I’d like to keep track of which aren’t available to be pushed, but are accessible via The API. In particular, I want to keep track of the gateway statistics.
Gateway stats come from continuously pinging the gateway, and are used to determine if a gateway is available for routing. Normally, gateway monitoring is used with multi-WAN setups to remove a gateway from a load-balancing group, or fail over to the next tier in a failover group (or both). However, even with a single WAN gateway, gateway monitoring can be useful to keep statistics on the reliability of the ISP, or notify on failure. I’ve found that my cable modem periodically locks up and rebooting it fixes the problem, so looking for the gateway error rate and gateway status is a good indication that the modem should be rebooted. This flow handles any number of gateways, so you can still use it to keep track of multiple WAN or outgoing VPN gateways, I just don’t need it for that.
The API endpoint that I use is /api/routes/gateway/status, and it returns an array with the status of each gateway, containing the following information which I capture:
- Name of the gateway (from OPNsense)
- Address of the gateway
- Status, either ’none’ (no errors), ’loss’, or ‘down’
- Delay (ms) ping to the gateway
- Std. Dev (ms) of the ping to the gateway
To use the flow, you should create an API user in OPNsense. It does not require any plugins in OPNsense, but does require node-red-contrib-influxdb in node-red. As always, my work is licensed CC-BY-SA unless otherwise specified. Link to the flow