diff --git a/monitoring/collectd/scripts/wlstats-gather/README.md b/monitoring/collectd/scripts/wlstats-gather/README.md new file mode 100644 index 0000000..f9c93e9 --- /dev/null +++ b/monitoring/collectd/scripts/wlstats-gather/README.md @@ -0,0 +1,10 @@ +Collectd wireless statistics gatherer +===================================== + +What is this +------------ +This is set of scritps/utilities to gather wirelss statitics for openfest 2015 + +Documentation +------------- +[usage](usage.md) diff --git a/monitoring/collectd/scripts/wlstats-gather/collectd-protocols.md b/monitoring/collectd/scripts/wlstats-gather/collectd-protocols.md new file mode 100644 index 0000000..ba72a19 --- /dev/null +++ b/monitoring/collectd/scripts/wlstats-gather/collectd-protocols.md @@ -0,0 +1,24 @@ +collectd plain text protocol +============================ + +Full protocol spec: https://collectd.org/wiki/index.php/Plain_text_protocol + +We are interested in submitting data (either to local or remote collectd) + +PUTVAL \ \[\\] Valuelist + +Identifier +host "/" plugin \["-" plugin instance\] "/" type \["-" type instance\] +https://collectd.org/wiki/index.php/Identifier + + +Option list + interval - interval in seconds + +Value list - comma separated values + +Value - timestamp:val:val (if more) + +Sample: + +PUTVAL "testhost/testplugin/testmetric" 12345678:123:458 diff --git a/monitoring/collectd/scripts/wlstats-gather/usage.md b/monitoring/collectd/scripts/wlstats-gather/usage.md new file mode 100644 index 0000000..211f3c9 --- /dev/null +++ b/monitoring/collectd/scripts/wlstats-gather/usage.md @@ -0,0 +1,99 @@ +How to use this +=============== + +The tools provided here are to be used for monitoring of OpenFest related infrastructure. + +Current Tools +============= +`wlstats-gather.sh` - prototype wireless statistics gatherer for collectd infrastructure + +Tools Usage +=========== + +wlstats-gather.sh +----------------- +This is intended to be used as an exec plugin for collectd. As such collectd and it's exec plugin are mandatory. + +Please note: Although possible to load collectd plugin multiple times it is not advisable. For best results load a plugin only once + +``` +LoadPlugin exec + + Exec "username:groupname" "/path/to/wlstats-gather.sh" + +``` + +Please note: + * if username:groupname combo is ommitted you have no guarantees on the permissions the user that will execute the plugin will have. + +Full example +============ +Central collector (server) +-------------------------- + +``` +Hostname central-collectd +FQDNLookup false + +# how often data will come ... do not change once set +Interval 60 + +# timeouts and load optimization +Timeout 5 +#ReadThreads 5 +#WriteThreads 5 + +# logging +LoadPlugin syslog + + LogLevel info + + +# now start listening on network / UDP (25826) +LoadPlugin network + + Listen "0.0.0.0" + ReportStats true + + +# and let's save the data +LoadPlugin rrdtool + + DataDir /srv/metrics/collectd/rrd + # can lead to some data loss + CreateFilesAsync true + +``` + +AP (client) sending metrics +--------------------------- + +``` +Hostname AP-left-1 +FQDNLookup false + +Interval 60 + +# timeouts and load optimization +Timeout 5 +#ReadThreads 5 +#WriteThreads 5 + +# logging +LoadPlugin syslog + + LogLevel info + + +# Sending to network / UDP (25826) +LoadPlugin network + + Server "central-collectd" + + +# some mtrics to collect ... +LoadPlugin exec + + Exec "nobody" "/mon/wlstats-gather.sh" + +``` diff --git a/monitoring/collectd/scripts/wlstats-gather/wlstats-gather.sh b/monitoring/collectd/scripts/wlstats-gather/wlstats-gather.sh new file mode 100644 index 0000000..9f554e8 --- /dev/null +++ b/monitoring/collectd/scripts/wlstats-gather/wlstats-gather.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# +# Simple wireless statistics gatherer for collectd +# +# Description: Simple wireless statistics gatherer for collectd +# Prereqs: OpenWRT compatible system / wlinfo / wl +# Used via: Collectd exec plugin type +# Author: Vladimir Vitkov +# +# Version: 0.1 +# Date: 2015.05.25 +# +# Changelog: 2015.05.25 - Initial version + +# Variable Definition +_HOSTNAME='testhost' +_PERIOD=60 # in seconds +_PLUGIN='wlstats' + +# Binaries +_iwinfo='iwinfo' +_iw='iw' + +# main loop +while true ; do + _start_time=$(date +%s) + + # do work + for _interface in $(${_iwinfo} | grep 'ESSID' | awk '{print $1}') ; do + #for _interface in wlan0 ; do + # get detailed essid info and prep for send + ${_iwinfo} ${_interface} info > /var/run/${_start_time}_${_interface} + _tx_power=$(grep 'Tx-Power' /var/run/${_start_time}_${_interface} | awk '{print $2}') + _link_quality=$(grep 'Link Quality' /var/run/${_start_time}_${_interface} | awk '{print $6}' | cut -d'/' -f1) + _signal=$(grep 'Signal' /var/run/${_start_time}_${_interface} | awk '{print $2}' | tr -d '-') + _noise=$(grep 'Noise' /var/run/${_start_time}_${_interface} | awk '{print $5}' | tr -d '-') + _bit_rate=$(grep 'Bit Rate' /var/run/${_start_time}_${_interface} | awk '{print $3}') + _clients=$(${_iw} ${_interface} station dump | grep '^Station' | wc -l) + + # start emiting metrics + echo -e "PUTVAL ${_HOSTNAME}/${_PLUGIN}-${_interface}/gauge-tx_power ${_start_time}:${_tx_power}" + echo -e "PUTVAL ${_HOSTNAME}/${_PLUGIN}-${_interface}/gauge-link_quality ${_start_time}:${_link_quality}" + echo -e "PUTVAL ${_HOSTNAME}/${_PLUGIN}-${_interface}/gauge-signal ${_start_time}:${_signal}" + echo -e "PUTVAL ${_HOSTNAME}/${_PLUGIN}-${_interface}/gauge-noise ${_start_time}:${_noise}" + echo -e "PUTVAL ${_HOSTNAME}/${_PLUGIN}-${_interface}/gauge-bit_rate ${_start_time}:${_bit_rate}" + echo -e "PUTVAL ${_HOSTNAME}/${_PLUGIN}-${_interface}/gauge-clients ${_start_time}:${_clients}" + + # now let's pick up the statistics + for _metric in $(ls -1 /sys/kernel/debug/ieee80211/*/netdev:${_interface}/../statistics/) ; do + echo -e "PUTVAL ${_HOSTNAME}/${_PLUGIN}-${_interface}/counter-$(echo ${_metric}) ${_start_time}:$(cat /sys/kernel/debug/ieee80211/*/netdev:${_interface}/../statistics/${_metric})" + done + + # nuke the temp file + rm -f /var/run/${_start_time}_${_interface} + done + + # now calculate sleep time + _end_time=$(date +%s) + sleep $(echo ${_PERIOD} ${_end_time} ${_start_time} | awk '{print $1 - $2 + $3 }') +done