Skip to content

himanshu007-creator/openwrt-openwisp-monitoring

 
 

Repository files navigation

openwrt-openwisp-monitoring

CI build status Test Coverage support chat

The OpenWISP Monitoring agent for OpenWRT.

Want to help OpenWISP? Find out how to help us grow here.

Configuration options

UCI configuration options must go in /etc/config/openwisp-monitoring.

  • monitored_interfaces: interfaces that needs to be monitored, defaults to * for all interfaces.
  • interval: time after which device data should be sent to server, defaults to 300.
  • debug_mode: can be enabled (set to 1) to ease debugging in case of issues, defaults to 0 (disabled).
  • required_memory: available memory required to save data temporarily, defaults to 0.05 (5 percent).
  • max_retries: maximum number of retries in case of failures to send data to server in case of failure, defaults to 5 retries.

In case, maximum retries are reached, agent will try sending data again in next cycle.

Collecting vs Sending

We use two procd services in monitoring agent, one for collecting the data and other for sending the data.

This helps handle failure in sending the data in more flexible way. Old data saved during network connectivity issues can be sent while new data is being collected. If old data has piled up and takes several minutes to be uploaded, new data will be collected without waiting for the sending to complete.

Monitoring agent uses two different modes to handle this, send and collect.

Collect Mode

If openwisp-monitoring agent is called with this mode, then the agent will keep charge of collecting and saving data.

Agent will periodically check if enough memory is available. If true, data will be collected and saved in temporary storage with the timestamp (in UTC timezone).

Once the data is saved, a signal will be sent to the other agent to ensure data is sent as soon as it is collected.

Note: Date and time on device should be set correctly. Otherwise, data will be saved with wrong timestamp in timeseries database.

Send Mode

If openwisp-monitoring agent is called with this mode, then the agent will keep charge of sending data.

Agent will check if any data file is available in temporary storage.

If there is no data file, the agent will sleep for the time interval and check for the data file again. This will be continued until a data file is found. If a signal is received from the other agent, then the sleep will be interrupted and agent will start sending data.

If agent fails to send data to the server, an exponential backoff will be used to retry until max_retries is reached. If all attempts of sending data failed, the agent will try to send data in the next cycle.

If data is sent successfully, then the data file will be deleted and agent will look for another file.

SIGUSR1 signals are used to instantly send the data when collected. However, the service will keep trying to send data periodically.

Compiling openwrt-openwisp-monitoring

There are 2 packages for openwisp-netjson-monitoring:

  • netjson-monitoring: provides NetJSON Device Monitoring output
  • openwisp-monitoring: depends on netjson-monitoring and openwisp-config

There are four variants of openwisp-monitoring:

  • openwisp-monitoring-openssl: depends on openwisp-config-openssl and netjson-monitoring
  • openwisp-monitoring-mbedtls: depends on openwisp-config-mbedtls and netjson-monitoring
  • openwisp-monitoring-wolfssl: depends on openwisp-config-wolfssl and netjson-monitoring
  • openwisp-monitoring-nossl: depends on openwisp-config-nossl and netjson-monitoring

The following procedure illustrates how to compile all variants of openwisp-monitoring, netjson-monitoring and their dependencies:

git clone https://git.openwrt.org/openwrt/openwrt.git
cd openwrt
git checkout openwrt-21.02

# configure feeds
echo "src-git monitoring https://github.com/openwisp/openwrt-openwisp-monitoring.git" > feeds.conf
cat feeds.conf.default >> feeds.conf
./scripts/feeds update -a
./scripts/feeds install -a
echo "CONFIG_PACKAGE_netjson-monitoring=y" >> .config
echo "CONFIG_PACKAGE_openwisp-monitoring-mbedtls=y" >> .config
echo "CONFIG_PACKAGE_openwisp-monitoring-nossl=y" >> .config
echo "CONFIG_PACKAGE_openwisp-monitoring-openssl=y" >> .config
echo "CONFIG_PACKAGE_openwisp-monitoring-wolfssl=y" >> .config
make defconfig
make tools/install
make toolchain/install
make package/openwrt-openwisp-monitoring/compile

The compiled packages will go in bin/packages/*/openwisp.

Alternatively, you can configure your build interactively with make menuconfig, in this case you will need to select the openwisp-monitoring variant and netjson-monitoring by going to Administration > admin > openwisp:

git clone https://git.openwrt.org/openwrt/openwrt.git
cd openwrt
git checkout openwrt-21.02

# configure feeds
echo "src-git openwisp https://github.com/openwisp/openwisp-monitoring.git" > feeds.conf
cat feeds.conf.default >> feeds.conf
./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig
# go to Administration > admin > openwisp and select the packages you need interactively
make tools/install
make toolchain/install
make package/openwrt-openwisp-monitoring/compile

Once installed openwisp-monitoring needs to be configured (see Configuration options) and then started with:

/etc/init.d/openwisp-monitoring restart

Debugging

Debugging openwisp-monitoring package can be easily done by using the logread command:

logread | grep openwisp-monitoring

In case of any issue, you can enable debug_mode.

If you are in that doubt openwisp-monitoring is running at all or not, you can check with:

ps | grep openwisp-monitoring

You should see something like:

2712 root      1224 S    /bin/sh /usr/sbin/openwisp-monitoring --interval 300 --monitored_interfaces ...
2713 root      1224 S    /bin/sh /usr/sbin/openwisp-monitoring --url http://192.168.1.195:8000 ...

You can inspect the version of openwisp-monitoring currently installed with:

openwisp-monitoring --version

Quality Assurance Checks

We use LuaFormatter and shfmt to format lua files and shell scripts respectively.

Once they are installed, you can format all files by:

./qa-format

Run quality assurance tests with:

#install openwisp-utils QA tools first
pip install openwisp-utils[qa]

#run QA checks before committing code
./run-qa-checks

Run tests

To run the unit tests, you must install the required dependencies first; to do this, you can take a look at the install-dev.sh script.

Install test requirements:

sudo ./install-dev.sh

You can run all unit tests by launching the dedicated script:

./runtests

Alternatively, you can run specific tests, e.g.:

cd openwrt-openwisp-monitoring/tests/
lua test_utils.lua -v

Contributing

Please read the OpenWISP contributing guidelines.

Changelog

See CHANGELOG.

License

See LICENSE.

Support

See OpenWISP Support Channels.

About

OpenWRT monitoring scripts for openwisp-monitoring

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 80.7%
  • Shell 16.0%
  • Makefile 3.3%