From 7cca730ce45da1d820d3bd697a0f423f38da60cd Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Thu, 16 Jan 2014 23:46:54 +0100 Subject: [PATCH 1/2] alfred: Add --no-sleep option to send immediately --- gluon/gluon-alfred/files/lib/gluon/alfred/announce.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gluon/gluon-alfred/files/lib/gluon/alfred/announce.sh b/gluon/gluon-alfred/files/lib/gluon/alfred/announce.sh index c24c1b2..de0c918 100755 --- a/gluon/gluon-alfred/files/lib/gluon/alfred/announce.sh +++ b/gluon/gluon-alfred/files/lib/gluon/alfred/announce.sh @@ -23,8 +23,10 @@ set -e # simultaneously, wait for a random time between 0 and 300 seconds, but fixed # for each device to maintain 5 minutes between updates. # Calculated using first 3 hex digits of the primary MAC address' MD5 hash -DELAY=$((0x$(sysconfig primary_mac | md5sum | head -c3) * $MAX_WAIT / (16**3))) -sleep $DELAY +if [ "$1" != "--no-sleep" ]; then + DELAY=$((0x$(sysconfig primary_mac | md5sum | head -c3) * $MAX_WAIT / (16**3))) + sleep $DELAY +fi json_init json_add_string "hostname" "$(uci get 'system.@system[0].hostname')" From 7197eb09dc4e0cd2b0715b581f003c1c498bb507 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Thu, 16 Jan 2014 23:47:41 +0100 Subject: [PATCH 2/2] alfred: add more traffic statistics + mgmt and forward counters + packet in addition to byte counters for everything --- gluon/gluon-alfred/Makefile | 2 +- .../gluon-alfred/files/lib/gluon/alfred/announce.sh | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gluon/gluon-alfred/Makefile b/gluon/gluon-alfred/Makefile index 8290ad8..176ba9b 100644 --- a/gluon/gluon-alfred/Makefile +++ b/gluon/gluon-alfred/Makefile @@ -11,7 +11,7 @@ include $(INCLUDE_DIR)/package.mk define Package/gluon-alfred SECTION:=gluon CATEGORY:=Gluon - DEPENDS:=+gluon-core +gluon-location +gluon-cron +alfred + DEPENDS:=+gluon-core +gluon-location +gluon-cron +alfred +ethtool TITLE:=Configure alfred endef diff --git a/gluon/gluon-alfred/files/lib/gluon/alfred/announce.sh b/gluon/gluon-alfred/files/lib/gluon/alfred/announce.sh index de0c918..d4533d3 100755 --- a/gluon/gluon-alfred/files/lib/gluon/alfred/announce.sh +++ b/gluon/gluon-alfred/files/lib/gluon/alfred/announce.sh @@ -75,8 +75,16 @@ json_close_object # network json_add_object "statistics" json_add_int "uptime" "$(cut -d' ' -f1 /proc/uptime)" json_add_object "traffic" - json_add_double "rx" "$(cat /sys/class/net/bat0/statistics/rx_bytes)" - json_add_double "tx" "$(cat /sys/class/net/bat0/statistics/tx_bytes)" + TRAFFIC="$(ethtool -S bat0 | sed -e 's/^ *//')" + for class in rx tx forward mgmt_rx mgmt_tx; do + json_add_object "$class" + json_add_int "bytes" "$(echo "$TRAFFIC" | awk -F': ' "/^${class}_bytes:/ { print \$2 }")" + json_add_int "packets" "$(echo "$TRAFFIC" | awk -F': ' "/^${class}:/ { print \$2 }")" + if [ "$class" = "tx" ]; then + json_add_int "dropped" "$(echo "$TRAFFIC" | awk -F': ' "/^${class}_dropped:/ { print \$2 }")" + fi + json_close_object # $class + done json_close_object # traffic json_close_object # statistics