diff options
author | Jo-Philipp Wich <jo@mein.io> | 2017-07-28 15:30:06 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2017-07-28 15:30:06 +0200 |
commit | e32168f9b73c32abd2ad11f3d2e79887193d6f94 (patch) | |
tree | 1ecd579c026e31590a44dec79294b178a3033a52 /net/nlbwmon/files/nlbwmon.init | |
parent | 43aadd7f7d8c8b568b76f6deb1df5edcdd9861fd (diff) |
nlbwmon: add package
This commit introduces nlbwmon, the lightweight NetLink BandWidth Montor.
The nlbwmon daemon gathers per-host traffic statistics by querying netlink
accounting data. Due to this approach, the executable is very small and does
not rely on libpcap and CPU intensive raw sockets to monitor traffic.
Besides raw per-host traffic counters, nlbwmon also support rudimentary
traffic classification by observing IP protocols and used port numbers.
Gathered accounting data is stored into a series of database files which
are regularily committed to persistent storage.
Refresh, commit and accounting intervals are freely configurable as well
as the layer7 protocol mapping rules and observed source subnets.
This package also bundles a cli client which can be used to dump the
gathered traffic data as JSON, CSV or plaintext data. A pull request to
add a graphical LuCI frontend for nlbwmon is pending.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'net/nlbwmon/files/nlbwmon.init')
-rwxr-xr-x | net/nlbwmon/files/nlbwmon.init | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/net/nlbwmon/files/nlbwmon.init b/net/nlbwmon/files/nlbwmon.init new file mode 100755 index 000000000..3f01d0f58 --- /dev/null +++ b/net/nlbwmon/files/nlbwmon.init @@ -0,0 +1,89 @@ +#!/bin/sh /etc/rc.common + +START=60 + +USE_PROCD=1 +NAME=nlbwmon +PROG=/usr/sbin/nlbwmon + +add_subnet() { + local network="$1" + local range ranges + + case "$network" in + *.*|*:*) + procd_append_param command '-s' "$network" + ;; + *) + if network_get_subnets ranges "$network"; then + for range in $ranges; do + procd_append_param command '-s' "$range" + done + fi + + if network_get_subnets6 ranges "$network"; then + for range in $ranges; do + procd_append_param command '-s' "$range" + done + fi + ;; + esac +} + +add_option() { + local cfg="$1" + local flag="$2" + local option="$3" + local default="$4" + local value + + config_get value "$cfg" "$option" "$default" + [ -n "$value" ] && procd_append_param command "$flag" "$value" +} + +add_bool() { + local cfg="$1" + local flag="$2" + local option="$3" + local default="$4" + local value + + config_get_bool value "$cfg" "$option" "$default" + [ $value -eq 1 ] && procd_append_param command "$flag" +} + +parse_config() { + . /lib/functions/network.sh + + local cfg="$1" + local dir + + config_get dir "$cfg" database_directory /var/lib/nlbwmon + + mkdir -p "$dir" + procd_append_param command -o "$dir" + + add_option "$cfg" -i commit_interval 24h + add_option "$cfg" -r refresh_interval 30s + add_option "$cfg" -p protocol_database /usr/share/nlbwmon/protocols + add_option "$cfg" -G database_generations 10 + add_option "$cfg" -I database_interval 1 + add_option "$cfg" -L database_limit 10000 + + add_bool "$cfg" -P database_prealloc 0 + add_bool "$cfg" -Z database_compress 1 + + config_list_foreach "$cfg" local_network add_subnet +} + +start_service() { + procd_open_instance + procd_set_param stderr 1 + procd_set_param command "$PROG" + + config_load nlbwmon + config_foreach parse_config nlbwmon + + procd_close_instance +} + |