Monitoring WAN status on OpenWRT using Alarm Pinger


I am connected to the Internet using wireless link which is sometime not very stable. I decided to monitor status of the link to make sure that I am aware of the problem. Initially i tried to monitor link with Monit or Nagios + fping, but results were not very good, this software is not designed for continues monitoring with very small interval. So I decided to find some alternatives.

About Alarm Pinger

I was using Alarm Pinger (apinger) with pfSense distribution — it was used to monitor WAN links to switch between them if needed.

Alarm Pinger (apinger) is a little tool which monitors various IP devices by simple ICMP echo requests. There are various other tools, that can do this, but most of them are shell or perl scripts, spawning many processes, thus much CPU-expensive, especially when one wants continuous monitoring and fast response on target failure. Alarm Pinger is a single program written in C, so it doesn’t need much CPU power even when monitoring many targets with frequent probes. Alarm Pinger supports both IPv4 and IPv6.

This tool supports multiply monitoring targets, external scripts, email notification, daemon mode. Only problem was that tool was not available as OpenWRT package. So i decided to port it.

OpenWRT port

After few tests I found, that code can be compiled with only few minor patches (autoconf related). You can grab Makefile for package from this pull request. Hopefully it will be integrated in the official packages feed soon. Update: port merged.
Port provides init.d script and sample configuration. In the feature I am also planning to make Luci integration to show link status from the web interface.

To buid package on Turris I would recommend to use my turris buildroot docker image.

## Service configuration

I am using very simple configuration to monitor status of the Wireless link using pings to the ISP gateway:

# we need to use root because "rainbow" tool fails to work from other uid. 
user "root"
group "root"

# status file with link quality information
status {
    file "/tmp/apinger.status"
    interval 1s
# command to run, with alarm type and reason
# if used with multiply targets %t needs to be added
alarm default {
    command on "/root/ %A %r"
    command off "/root/ %A %r"
# This alarm will be fired when target doesn't respond for 30 seconds.
alarm down "down" {
    time 30s
# This alarm will be fired when responses are delayed more than 80ms
# it will be canceled, when the delay drops below 50ms
alarm delay "delay" {
    delay_low 50ms
    delay_high 80ms
# This alarm will be fired when packet loss goes over 5%
# it will be canceled, when the loss drops below 3%
alarm loss "loss" {
    percent_low 3
    percent_high 5
target default {
    interval 1s
    avg_delay_samples 10
    avg_loss_samples 50
    avg_loss_delay_samples 20
    alarms "down","delay","loss"
# ISP Gateway host to monitor. You can define many targets in case of MultiWAN. 
target "" {
    description "ISP Gateway"

Also I am using simple script to change WAN LED color in case of problems:


DEF_COLOR=33FF33 # see

logger "event: $@"
# read data from status file
STATUS=`grep  "Active alarms:" /tmp/apinger.status`

case "$@" in
"delay ALARM")
  touch /tmp/apinger.delay.flag
"delay alarm canceled")
  rm -f /tmp/apinger.delay.flag
"down ALARM")
  touch /tmp/apinger.down.flag
"down alarm canceled")
  rm -f /tmp/apinger.down.flag
"loss ALARM")
  touch /tmp/apinger.loss.flag
"loss alarm canceled")
  rm -f /tmp/apinger.loss.flag
# link is down
if [ -e /tmp/apinger.down.flag ]; then
# loss or delay
if [ -e /tmp/apinger.loss.flag -o -e /tmp/apinger.delay.flag ]; then
# no active alarms found

This works pretty good – if line is down – WAN color is red, if it is unstable or congested – yellow. We can also monitor link status manually:

root@turris:~# cat /tmp/apinger.status
Fri Apr 10 12:39:24 2015

Description: ISP Gateway
Last reply received: #2876 Fri Apr 10 12:39:23 2015
Average delay: 3.247ms
Average packet loss: 0.0%
Active alarms: None
Received packets buffer: ################################################## ###################.


I am planning to extend functionality of the script with some cool features:

  • Integrate with Luci to show status in the web interface.
  • Add support for the failover switch to the LTE channel if link is down (and LTE dongle connected).
  • Enable rrdtools support provided by apinger.
Tagged , , , ,

6 thoughts on “Monitoring WAN status on OpenWRT using Alarm Pinger

  1. Rich D says:

    I just installed OpenWRT (final Chaos Calmer) on my Linksys 1900AC router and was looking to use this program to monitor my internet connection to help easily determine when the problem is my connection compared to the router, etc. Could you list the steps necessary to implement this? I was able to do basic configuration via Luci but I haven’t done anything more advanced like custom scripts such as above.

    • sammczk says:

      actually all steps are in the article. You have to install apinger tool and configure it.

      • Rich D says:

        Sorry for the “noob” questions but I have installed apinger and I see the process is running. I just don’t know what file to edit/configure. I am using the final release of OpernWRT CC. I see the apinger file in init.d, the symlink S80apinger in rc.d, and the apinger file in /usr/sbin. I don’t see any steps on what to do next.

      • Rich D says:

        You can ignore my last comment – I found the apinger.conf file in /etc

  2. Thank you very much, Alex, for sharing this setup. It was exactly what I was looking for! Спасибо!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: