2015-02-19 20:15:38 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2015-02-21 18:18:27 +01:00
|
|
|
# config
|
|
|
|
INTERVAL=2
|
|
|
|
REPORTER=stdout
|
|
|
|
|
2015-02-22 20:45:57 +01:00
|
|
|
#init
|
|
|
|
__METRICS=()
|
|
|
|
|
|
|
|
# load utils
|
|
|
|
for util in ./lib/utils/*.sh; do source $util; done
|
2015-02-21 18:18:27 +01:00
|
|
|
|
|
|
|
# load reporter
|
|
|
|
source ./reporters/${REPORTER}.sh
|
2015-02-22 20:45:57 +01:00
|
|
|
copy_function init __r_${REPORTER}_init
|
|
|
|
copy_function report __r_${REPORTER}_report
|
|
|
|
copy_function terminate __r_${REPORTER}_terminate
|
|
|
|
copy_function docs __r_${REPORTER}_docs
|
|
|
|
unset -f init report terminate docs
|
2015-02-21 18:18:27 +01:00
|
|
|
|
|
|
|
# load metrics
|
2015-02-22 20:45:57 +01:00
|
|
|
for file in ./metrics/*.sh; do
|
2015-02-21 18:18:27 +01:00
|
|
|
filename=$(basename $file)
|
|
|
|
metric=${filename%.*}
|
2015-02-22 20:45:57 +01:00
|
|
|
|
|
|
|
# soruce file and copy functions
|
|
|
|
source $file
|
|
|
|
copy_function init __m_${metric}_init
|
|
|
|
copy_function collect __m_${metric}_collect
|
|
|
|
copy_function terminate __m_${metric}_terminate
|
|
|
|
copy_function docs __m_${metric}_docs
|
|
|
|
unset -f init collect terminate docs
|
|
|
|
|
|
|
|
# register metric
|
|
|
|
__METRICS+=($metric)
|
2015-02-21 18:18:27 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# init metrics
|
2015-02-22 20:45:57 +01:00
|
|
|
for metric in ${__METRICS[@]}; do
|
|
|
|
if ! is_function __m_${metric}_init; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
__m_${metric}_init
|
|
|
|
done
|
|
|
|
|
|
|
|
# print docs for metrics
|
|
|
|
echo "Available metrics:"
|
|
|
|
for metric in ${__METRICS[@]}; do
|
|
|
|
if ! is_function __m_${metric}_docs; then
|
2015-02-21 18:49:18 +01:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2015-02-22 20:45:57 +01:00
|
|
|
echo "[$metric]"
|
|
|
|
__m_${metric}_docs
|
|
|
|
echo
|
2015-02-21 18:18:27 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# collect metrics
|
|
|
|
while true; do
|
2015-02-22 20:45:57 +01:00
|
|
|
for metric in ${__METRICS[@]}; do
|
|
|
|
if ! is_function __m_${metric}_collect; then
|
2015-02-21 18:49:18 +01:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2015-02-22 20:45:57 +01:00
|
|
|
result=$(__m_${metric}_collect)
|
|
|
|
__r_${REPORTER}_report $metric $result
|
2015-02-21 18:18:27 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
sleep $INTERVAL
|
2015-02-19 20:15:38 +01:00
|
|
|
done
|