Developing lightweight computation at the DSG edge

Commit 02606962 authored by Pau Escrich's avatar Pau Escrich
Browse files

Introduces new package "munin-mesh", a very simple version of the munin agent...

Introduces new package "munin-mesh", a very simple version of the munin agent with some qMp related functions
Add it in the services list and in the LUCI web interface
parent 1a288f9a
# Copyright (C) 2013 Pau Escrich <p4u@dabax.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# The full GNU General Public License is included in this distribution in
# the file called "COPYING".
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=munin-mesh
PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/munin-mesh
TITLE:=Munin mesh agent for qMp
SECTION:=qMp
CATEGORY:=qMp
URL:=http://qmp.cat
DEPENDS:=netcat
endef
define Package/munin-mesh/description
Munin mesh agent for qMp
endef
define Build/Configure
endef
define Build/Compile
@rm -rf ./build || true
@cp -r ./src ./build
endef
define Package/munin-mesh/install
$(INSTALL_DIR) $(1)/etc/munin-plugins
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/etc/rc.d/
$(CP) ./build/plugins/* $(1)/etc/munin-plugins/
chmod 755 $(1)/etc/munin-plugins/*
$(CP) ./build/munin-node $(1)/usr/sbin/
chmod 755 $(1)/usr/sbin/munin-node
$(CP) ./build/munin $(1)/etc/init.d/
chmod 755 $(1)/etc/init.d/munin
ln -s ../init.d/munin $(1)/etc/rc.d/S99munin
endef
$(eval $(call BuildPackage,munin-mesh))
#!/bin/sh /etc/rc.common
#
# Munin-node init script
# It uses netcat or socat to listen in port 4949
#
# Copyright (C) 2011 Pau Escrich <pau@dabax.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
START=99
MUNIN_BIN="/usr/sbin/munin-node"
PID="/var/run/munin-node"
PORT="4949"
NC_BIN="/usr/bin/netcat"
SOCAT_BIN="/usr/bin/socat"
start()
{
if [ ! -f "$PID" ]; then
if [ -x $SOCAT_BIN ]; then
$SOCAT_BIN TCP4-LISTEN:$PORT,fork,reuseaddr EXEC:$MUNIN_BIN &
echo $! > /var/run/munin-node
elif [ -x $NC_BIN ]; then
mkfifo /tmp/munin.fifo 2>/dev/null
(while [ -e /var/run/munin-node ]; do
$NC_BIN -l -p $PORT -w 30 < /tmp/munin.fifo | $MUNIN_BIN > /tmp/munin.fifo
[ $? -ne 0 ] && break
done) &
echo $! > /var/run/munin-node
else
echo "Cannot found socat nor netcat, exiting.."
exit 0
fi
else
echo "Munin already running"
fi
}
stop()
{
kill -9 $(cat $PID) 2>/dev/null
rm -f $PID
}
restart()
{
stop
start
}
This diff is collapsed.
#!/bin/sh
config() {
echo "graph_title Dhcp leases"
echo "graph_args --base 1000 -l 0 "
echo "graph_vlabel Number of active dhcp leases"
echo "graph_category mesh"
echo "graph_info This graph shows the number active dhcp leases"
echo "leases.label leases"
echo "leases.draw LINE1"
echo "leases.info DHCP leases"
}
print() {
echo "leases.value $(cat /tmp/dhcp.leases | wc -l)"
}
if [ "$1" == "config" ]
then
config
else
print
fi
#!/bin/sh
config() {
echo "graph_title Mesh link quality"
echo "graph_args --base 1000 -l 0 "
echo "graph_vlabel Link quality to neighbours"
echo "graph_category mesh"
echo "graph_info This graph shows the link quality to the neighbours"
i=1
for n in $(qmpinfo links | awk '{print $1}')
do
echo "${i}rx.label $n"
echo "${i}rx.type DERIVE"
#echo "${i}rx.draw LINE$i"
echo "${i}rx.info rx $n"
echo "${i}rx.max 100"
echo "${i}rx.min 0"
echo "${i}tx.label $n"
echo "${i}rx.type DERIVE"
#echo "${i}tx.draw LINE$i"
echo "${i}tx.info tx $n"
echo "${i}tx.max 100"
echo "${i}tx.min 0"
i=$(($i+1))
done
}
print() {
for t in rx tx
do
i=1
for v in $(cat /var/run/bmx6/json/links | sed s/","/"\n"/g | grep "${t}Rate" | cut -d: -f2)
do
echo "$i${t}.value $v"
i=$(($i+1))
done
done
}
if [ "$1" == "config" ]
then
config
else
print
fi
#!/bin/sh
config() {
echo "graph_title Mesh nodes"
echo "graph_args --base 1000 -l 0 "
echo "graph_vlabel Number of mesh nodes"
echo "graph_category mesh"
echo "graph_info This graph shows the number of nodes and the direct neighbours of the mesh network"
echo "nodes.label nodes"
echo "nodes.draw LINE1"
echo "nodes.info Mesh nodes"
echo "links.label links"
echo "links.draw LINE2"
echo "links.info Mesh links (neighbours)"
}
print() {
echo "nodes.value $(qmpinfo nodes | wc -l)"
echo "links.value $(qmpinfo links | wc -l)"
}
if [ "$1" == "config" ]
then
config
else
print
fi
#!/bin/sh
INTERFACE=${0##*net_}
findspeed () {
SPEED=10
echo "up.max $SPEED"
echo "up.info Traffic of the $INTERFACE interface. Maximum speed is $SPEED MiB."
echo "down.max $SPEED"
}
case $1 in
autoconf)
if [ -r /proc/net/dev ]; then
echo yes
exit 0
else
echo "no (/proc/net/dev not found)"
exit 0
fi
;;
suggest)
if [ -r /proc/net/dev ]; then
awk '
/^ *(eth|tap|bond|wlan|ath|ra|sw|vlan|venet|veth|msh)[0-9]+(\.[0-9]+)?:/ {
split($0, a, /: */);
gsub(/^ +/,"",a[1]);
if (($2 > 0) || ($10 > 0)) print a[1]; }' /proc/net/dev
fi
exit 0
;;
config)
echo "graph_order down up"
echo "graph_title $INTERFACE traffic"
echo 'graph_args --base 100'
echo 'graph_vlabel MiB/s in (-) / out (+) per ${graph_period}'
echo 'graph_category network'
echo "graph_info This graph shows the traffic of the $INTERFACE network interface. Please note that the traffic is shown in bits per second, not bytes. IMPORTANT: On 32 bit systems the data source for this plugin uses 32bit counters, which makes the plugin unreliable and unsuitable for most 100Mb (or faster) interfaces, where traffic is expected to exceed 50Mbps over a 5 minute period. This means that this plugin is unsuitable for most 32 bit production environments. To avoid this problem, use the ip_ plugin instead. There should be no problems on 64 bit systems running 64 bit kernels."
echo 'down.label received'
echo 'down.type DERIVE'
echo 'down.graph no'
echo 'down.cdef down,8,*'
echo 'down.min 0'
echo 'up.label MiB/s'
echo 'up.type DERIVE'
echo 'up.negative down'
echo 'up.cdef up,8,*'
echo 'up.min 0'
findspeed
exit 0
;;
esac
# Escape dots in the interface name (eg. vlans) before using it as a regex
awk -v interface="$INTERFACE" \
'BEGIN { gsub(/\./, "\\.", interface) } \
$1 ~ "^" interface ":" {
split($0, a, /: */); $0 = a[2]; \
print "down.value " $1/(1024*1024) "\nup.value " $9/(1024*1024) \
}' \
/proc/net/dev
#!/bin/sh
INTERFACE=${0##*net_}
findspeed () {
SPEED=10
echo "up.max $SPEED"
echo "up.info Traffic of the $INTERFACE interface. Maximum speed is $SPEED MiB."
echo "down.max $SPEED"
}
case $1 in
autoconf)
if [ -r /proc/net/dev ]; then
echo yes
exit 0
else
echo "no (/proc/net/dev not found)"
exit 0
fi
;;
suggest)
if [ -r /proc/net/dev ]; then
awk '
/^ *(eth|tap|bond|wlan|ath|ra|sw|vlan|venet|veth|msh)[0-9]+(\.[0-9]+)?:/ {
split($0, a, /: */);
gsub(/^ +/,"",a[1]);
if (($2 > 0) || ($10 > 0)) print a[1]; }' /proc/net/dev
fi
exit 0
;;
config)
echo "graph_order down up"
echo "graph_title $INTERFACE traffic"
echo 'graph_args --base 100'
echo 'graph_vlabel MiB/s in (-) / out (+) per ${graph_period}'
echo 'graph_category network'
echo "graph_info This graph shows the traffic of the $INTERFACE network interface. Please note that the traffic is shown in bits per second, not bytes. IMPORTANT: On 32 bit systems the data source for this plugin uses 32bit counters, which makes the plugin unreliable and unsuitable for most 100Mb (or faster) interfaces, where traffic is expected to exceed 50Mbps over a 5 minute period. This means that this plugin is unsuitable for most 32 bit production environments. To avoid this problem, use the ip_ plugin instead. There should be no problems on 64 bit systems running 64 bit kernels."
echo 'down.label received'
echo 'down.type DERIVE'
echo 'down.graph no'
echo 'down.cdef down,8,*'
echo 'down.min 0'
echo 'up.label MiB/s'
echo 'up.type DERIVE'
echo 'up.negative down'
echo 'up.cdef up,8,*'
echo 'up.min 0'
findspeed
exit 0
;;
esac
# Escape dots in the interface name (eg. vlans) before using it as a regex
awk -v interface="$INTERFACE" \
'BEGIN { gsub(/\./, "\\.", interface) } \
$1 ~ "^" interface ":" {
split($0, a, /: */); $0 = a[2]; \
print "down.value " $1/(1024*1024) "\nup.value " $9/(1024*1024) \
}' \
/proc/net/dev
#!/bin/sh
IFACES="wlan0"
config() {
echo "graph_title Signal avarage"
echo "graph_args --base 1000 -l 0 "
echo "graph_vlabel Signal avarage in dBm"
echo "graph_category wifi"
echo "graph_info This graph shows the signal average of the connected stations"
n=1
for i in $IFACES
do
echo "$i.label $i"
echo "$i.draw LINE$n"
echo "$i.info Signal of $i"
n=$(($n+1))
done
}
signal_avg() {
signals=$(iw $1 station dump | grep "signal avg" | awk '{print $3}')
total=0
stations=0
for n in $signals; do total=$(($total+$n)); stations=$(($stations+1)); done
[ $stations -gt 0 ] && echo "$(($total/$stations))"
}
print() {
for i in $IFACES
do
echo "$i.value $(signal_avg $i)"
done
}
if [ "$1" == "config" ]
then
config
else
print
fi
#!/bin/sh /etc/rc.common
#
# Munin-node init script
# It uses netcat or socat to listen in port 4949
#
# Copyright (C) 2011 Pau Escrich <pau@dabax.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
START=99
MUNIN_BIN="/usr/sbin/munin-node"
PID="/var/run/munin-node"
PORT="4949"
NC_BIN="/usr/bin/netcat"
SOCAT_BIN="/usr/bin/socat"
start()
{
if [ ! -f "$PID" ]; then
if [ -x $SOCAT_BIN ]; then
$SOCAT_BIN TCP4-LISTEN:$PORT,fork,reuseaddr EXEC:$MUNIN_BIN &
echo $! > /var/run/munin-node
elif [ -x $NC_BIN ]; then
mkfifo /tmp/munin.fifo 2>/dev/null
(while [ -e /var/run/munin-node ]; do
$NC_BIN -l -p $PORT -w 30 < /tmp/munin.fifo | $MUNIN_BIN > /tmp/munin.fifo
[ $? -ne 0 ] && break
done) &
echo $! > /var/run/munin-node
else
echo "Cannot found socat nor netcat, exiting.."
exit 0
fi
else
echo "Munin already running"
fi
}
stop()
{
kill -9 $(cat $PID) 2>/dev/null
rm -f $PID
}
restart()
{
stop
start
}
This diff is collapsed.
#!/bin/sh
config() {
echo "graph_title Dhcp leases"
echo "graph_args --base 1000 -l 0 "
echo "graph_vlabel Number of active dhcp leases"
echo "graph_category mesh"
echo "graph_info This graph shows the number active dhcp leases"
echo "leases.label leases"
echo "leases.draw LINE1"
echo "leases.info DHCP leases"
}
print() {
echo "leases.value $(cat /tmp/dhcp.leases | wc -l)"
}
if [ "$1" == "config" ]
then
config
else
print
fi
#!/bin/sh
config() {
echo "graph_title Mesh link quality"
echo "graph_args --base 1000 -l 0 "
echo "graph_vlabel Link quality to neighbours"
echo "graph_category mesh"
echo "graph_info This graph shows the link quality to the neighbours"
i=1
for n in $(qmpinfo links | awk '{print $1}')
do
echo "${i}rx.label $n"
echo "${i}rx.type DERIVE"
#echo "${i}rx.draw LINE$i"
echo "${i}rx.info rx $n"
echo "${i}rx.max 100"
echo "${i}rx.min 0"
echo "${i}tx.label $n"
echo "${i}rx.type DERIVE"
#echo "${i}tx.draw LINE$i"
echo "${i}tx.info tx $n"
echo "${i}tx.max 100"
echo "${i}tx.min 0"
i=$(($i+1))
done
}
print() {
for t in rx tx
do
i=1
for v in $(cat /var/run/bmx6/json/links | sed s/","/"\n"/g | grep "${t}Rate" | cut -d: -f2)
do
echo "$i${t}.value $v"
i=$(($i+1))
done
done
}
if [ "$1" == "config" ]
then
config
else
print
fi
#!/bin/sh
config() {
echo "graph_title Mesh nodes"
echo "graph_args --base 1000 -l 0 "
echo "graph_vlabel Number of mesh nodes"
echo "graph_category mesh"
echo "graph_info This graph shows the number of nodes and the direct neighbours of the mesh network"
echo "nodes.label nodes"
echo "nodes.draw LINE1"
echo "nodes.info Mesh nodes"
echo "links.label links"
echo "links.draw LINE2"
echo "links.info Mesh links (neighbours)"
}
print() {
echo "nodes.value $(qmpinfo nodes | wc -l)"
echo "links.value $(qmpinfo links | wc -l)"
}
if [ "$1" == "config" ]
then
config
else
print
fi
#!/bin/sh
INTERFACE=${0##*net_}
findspeed () {
SPEED=10
echo "up.max $SPEED"
echo "up.info Traffic of the $INTERFACE interface. Maximum speed is $SPEED MiB."
echo "down.max $SPEED"
}
case $1 in
autoconf)
if [ -r /proc/net/dev ]; then
echo yes
exit 0
else
echo "no (/proc/net/dev not found)"