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>
89 lines
1.7 KiB
Bash
Executable file
89 lines
1.7 KiB
Bash
Executable file
#!/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
|
|
}
|
|
|