mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-02-14 19:41:51 +00:00
Update vnstat
This commit is contained in:
parent
cb4dce3f03
commit
155e56460e
6 changed files with 298 additions and 0 deletions
113
vnstat/Makefile
Normal file
113
vnstat/Makefile
Normal file
|
@ -0,0 +1,113 @@
|
|||
#
|
||||
# Copyright (C) 2006-2014 OpenWrt.org
|
||||
# Copyright (C) 2019 Ycarus (Yannick Chabanois) <ycarus@zugaina.org> for OpenMPTCProuter
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=vnstat
|
||||
PKG_VERSION:=2.4
|
||||
PKG_RELEASE:=2
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=http://humdi.net/vnstat
|
||||
PKG_HASH:=a0955999abd56d5463d257ffdccc9b1e9ad9ea504de81e64ba4c197f1245abaa
|
||||
PKG_MAINTAINER:=Ycarus <ycarus@zugaina.org>
|
||||
|
||||
PKG_INSTALL:=1
|
||||
|
||||
PKG_BUILD_DEPENDS:=libgd
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/vnstat/Default
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
URL:=http://humdi.net/vnstat/
|
||||
endef
|
||||
|
||||
define Package/vnstat
|
||||
$(call Package/vnstat/Default)
|
||||
TITLE:=Console-based network traffic monitor
|
||||
endef
|
||||
|
||||
define Package/vnstat/description
|
||||
vnStat is a network traffic monitor for Linux that keeps a log of daily
|
||||
network traffic for the selected interface(s). vnStat isn't a packet
|
||||
sniffer. The traffic information is analyzed from the /proc -filesystem,
|
||||
so vnStat can be used without root permissions.
|
||||
endef
|
||||
|
||||
define Package/vnstati
|
||||
$(call Package/vnstat/Default)
|
||||
DEPENDS+=vnstat +libgd
|
||||
TITLE:=PNG image output support for vnStat
|
||||
endef
|
||||
|
||||
define Package/vnstati/description
|
||||
The purpose of vnstati is to provide image output support for statistics
|
||||
collected using vnstat(1). However, the image file format is limited to
|
||||
png. All basic outputs of vnStat are supported excluding live traffic
|
||||
features. The image can be outputted either to a file or to standard
|
||||
output.
|
||||
endef
|
||||
|
||||
define Package/vnstat/conffiles
|
||||
/etc/vnstat.conf
|
||||
/etc/config/vnstat
|
||||
endef
|
||||
|
||||
define Build/Compile/vnstat
|
||||
+$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
|
||||
$(TARGET_CONFIGURE_OPTS) \
|
||||
CFLAGS="$(TARGET_CFLAGS)" \
|
||||
LDFLAGS="$(TARGET_LDFLAGS)"
|
||||
endef
|
||||
|
||||
define Build/Compile/vnstati
|
||||
+$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
|
||||
$(TARGET_CONFIGURE_OPTS) \
|
||||
CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include" \
|
||||
LDFLAGS="$(TARGET_LDFLAGS) -Wl,-rpath-link,$(STAGING_DIR)/usr/lib" \
|
||||
all
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(call Build/Compile/vnstat)
|
||||
$(call Build/Compile/vnstati)
|
||||
endef
|
||||
|
||||
define Package/vnstat/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/bin/vnstat $(1)/usr/bin/
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/sbin/vnstatd $(1)/usr/sbin/
|
||||
$(INSTALL_DIR) $(1)/etc
|
||||
$(INSTALL_CONF) $(PKG_BUILD_DIR)/cfg/vnstat.conf $(1)/etc/
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) ./files/vnstat.config $(1)/etc/config/vnstat
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/vnstat.init $(1)/etc/init.d/vnstat
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/vnstat.defaults $(1)/etc/uci-defaults/vnstat
|
||||
$(INSTALL_DIR) $(1)/usr/libexec/rpcd
|
||||
$(INSTALL_BIN) ./files/vnstat.rpcd $(1)/usr/lib/libexec/rpcd/vnstat
|
||||
endef
|
||||
|
||||
define Package/vnstati/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/bin/vnstati $(1)/usr/bin/
|
||||
endef
|
||||
|
||||
define Package/vnstat/postinst
|
||||
#!/bin/sh
|
||||
[ -n "$${IPKG_INSTROOT}" ] || (. /etc/uci-defaults/vnstat) && rm -f /etc/uci-defaults/vnstat
|
||||
exit 0
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,vnstat))
|
||||
$(eval $(call BuildPackage,vnstati))
|
5
vnstat/files/vnstat.config
Normal file
5
vnstat/files/vnstat.config
Normal file
|
@ -0,0 +1,5 @@
|
|||
config vnstat
|
||||
list interface br-lan
|
||||
# list interface eth0.1
|
||||
# option remote http://example.org/vnstat/
|
||||
# option symlink /www/vnstat
|
13
vnstat/files/vnstat.defaults
Normal file
13
vnstat/files/vnstat.defaults
Normal file
|
@ -0,0 +1,13 @@
|
|||
#!/bin/sh
|
||||
|
||||
wan="$(uci -P/var/state get network.wan.ifname)"
|
||||
|
||||
if [ -n "$wan" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
del_list vnstat.@vnstat[-1].interface=$wan
|
||||
add_list vnstat.@vnstat[-1].interface=$wan
|
||||
commit vnstat
|
||||
EOF
|
||||
fi
|
||||
|
||||
exit 0
|
86
vnstat/files/vnstat.init
Normal file
86
vnstat/files/vnstat.init
Normal file
|
@ -0,0 +1,86 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2008-2011 OpenWrt.org
|
||||
|
||||
START=99
|
||||
|
||||
USE_PROCD=1
|
||||
|
||||
vnstat_option() {
|
||||
sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \
|
||||
/etc/vnstat.conf
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local lib="$(vnstat_option DatabaseDir)"
|
||||
|
||||
[ -n "$lib" ] || {
|
||||
echo "Error: No DatabaseDir set in vnstat.conf" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
mkdir -p "$lib"
|
||||
|
||||
init_ifaces() {
|
||||
local cfg="$1"
|
||||
local url lnk
|
||||
|
||||
init_iface() {
|
||||
local ifn="$1"
|
||||
|
||||
if [ -n "$url" ]; then
|
||||
local try=0
|
||||
local max=3
|
||||
local hostname="$(cat /proc/sys/kernel/hostname)"
|
||||
|
||||
while [ $((++try)) -le $max ]; do
|
||||
if wget -q -O "$lib/$ifn" "$url/${hostname}_$ifn" 2>/dev/null && [ -e "$lib/$ifn" ]; then
|
||||
logger -t "vnstat" "Downloaded backup for database $ifn"
|
||||
break
|
||||
else
|
||||
logger -t "vnstat" "Download try $try/$max for database $ifn failed"
|
||||
sleep 30
|
||||
fi
|
||||
done
|
||||
elif [ -n "$backup_dir" ]; then
|
||||
if cp -f "$backup_dir/$ifn" "$lib/" &>/dev/null; then
|
||||
logger -t "vnstat" "Restored backup for database $ifn"
|
||||
else
|
||||
logger -t "vnstat" "Restore of backup for database $ifn failed"
|
||||
fi
|
||||
fi
|
||||
|
||||
/usr/bin/vnstat -u -i "$ifn" >/dev/null
|
||||
|
||||
[ -n "$lnk" ] && {
|
||||
mkdir -p "$lnk"
|
||||
[ -L "$lnk/$ifn" ] || ln -s "$lib/$ifn" "$lnk/$ifn"
|
||||
}
|
||||
}
|
||||
|
||||
config_get url "$cfg" remote
|
||||
config_get lnk "$cfg" symlink
|
||||
config_get backup_dir "$cfg" backup_dir
|
||||
config_list_foreach "$cfg" interface init_iface
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
config_load vnstat
|
||||
config_foreach init_ifaces vnstat
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_set_param command /usr/sbin/vnstatd --nodaemon
|
||||
procd_set_param file /etc/vnstat.conf
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
procd_send_signal vnstat
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger vnstat
|
||||
}
|
53
vnstat/files/vnstat.rpcd
Executable file
53
vnstat/files/vnstat.rpcd
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2019 Ycarus (Yannick Chabanois) <ycarus@zugaina.org> for OpenMPTCProuter
|
||||
|
||||
case "$1" in
|
||||
list)
|
||||
echo '{ "speed": { "ifname": "eth0" }, "speedallif": {},"hours": { "ifname": "eth0" },"days": { "ifname": "eth0" },"months": { "ifname": "eth0" },"weeks": { "ifname": "eth0" },"top10": { "ifname": "eth0" } }'
|
||||
;;
|
||||
call)
|
||||
case "$2" in
|
||||
speed)
|
||||
read input;
|
||||
IFNAME=`echo $input | jsonfilter -e '@.ifname'`
|
||||
vnstat -i $IFNAME --json -tr
|
||||
;;
|
||||
speedallif)
|
||||
echo '{'
|
||||
for IFPATH in /var/lib/vnstat/*
|
||||
do
|
||||
IFNAME=$(basename -- "$IFPATH")
|
||||
echo '"'$IFNAME'": '
|
||||
vnstat -i $IFNAME --json -tr
|
||||
echo ','
|
||||
done
|
||||
echo '}'
|
||||
;;
|
||||
hours)
|
||||
read input;
|
||||
IFNAME=`echo $input | jsonfilter -e '@.ifname'`
|
||||
vnstat -i $IFNAME -h --json
|
||||
;;
|
||||
days)
|
||||
read input;
|
||||
IFNAME=`echo $input | jsonfilter -e '@.ifname'`
|
||||
vnstat -i $IFNAME -d --json
|
||||
;;
|
||||
months)
|
||||
read input;
|
||||
IFNAME=`echo $input | jsonfilter -e '@.ifname'`
|
||||
vnstat -i $IFNAME -m --json
|
||||
;;
|
||||
weeks)
|
||||
read input;
|
||||
IFNAME=`echo $input | jsonfilter -e '@.ifname'`
|
||||
vnstat -i $IFNAME -w --json
|
||||
;;
|
||||
top10)
|
||||
read input;
|
||||
IFNAME=`echo $input | jsonfilter -e '@.ifname'`
|
||||
vnstat -i $IFNAME -t --json
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
28
vnstat/patches/990-adjust-configuration-defaults.patch
Normal file
28
vnstat/patches/990-adjust-configuration-defaults.patch
Normal file
|
@ -0,0 +1,28 @@
|
|||
From: Jo-Philipp Wich <jo@mein.io>
|
||||
Date: Thu, 26 Jan 2017 15:30:00 +0100
|
||||
Subject: [PATCH] config: adjust default values
|
||||
|
||||
Adjust the default interval settings to be better suited for slower embedded
|
||||
devices.
|
||||
|
||||
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
||||
|
||||
--- a/cfg/vnstat.conf
|
||||
+++ b/cfg/vnstat.conf
|
||||
@@ -87,13 +87,13 @@ DaemonUser ""
|
||||
DaemonGroup ""
|
||||
|
||||
# how often (in seconds) interface data is updated
|
||||
-UpdateInterval 30
|
||||
+UpdateInterval 60
|
||||
|
||||
# how often (in seconds) interface status changes are checked
|
||||
-PollInterval 5
|
||||
+PollInterval 30
|
||||
|
||||
# how often (in minutes) data is saved to file
|
||||
-SaveInterval 5
|
||||
+SaveInterval 30
|
||||
|
||||
# how often (in minutes) data is saved when all interface are offline
|
||||
OfflineSaveInterval 30
|
Loading…
Reference in a new issue