2015-02-19 20:15:38 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2015-02-21 18:18:27 +01:00
|
|
|
# config
|
|
|
|
INTERVAL=2
|
|
|
|
REPORTER=stdout
|
|
|
|
|
|
|
|
# init
|
2015-02-21 18:51:23 +01:00
|
|
|
source ./lib/utils.sh
|
2015-02-21 18:18:27 +01:00
|
|
|
_METRICS=()
|
|
|
|
|
|
|
|
# load reporter
|
|
|
|
source ./reporters/${REPORTER}.sh
|
|
|
|
copy_function report _r_${REPORTER}_report
|
2015-02-21 18:49:18 +01:00
|
|
|
unset -f init report terminate
|
2015-02-21 18:18:27 +01:00
|
|
|
|
|
|
|
# load metrics
|
|
|
|
for file in $(find ./metrics -type f -name '*.sh'); do
|
|
|
|
source $file
|
|
|
|
filename=$(basename $file)
|
|
|
|
metric=${filename%.*}
|
|
|
|
copy_function collect _m_${metric}_collect
|
|
|
|
_METRICS+=($metric)
|
2015-02-21 18:49:18 +01:00
|
|
|
unset -f init collect terminate
|
2015-02-21 18:18:27 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# init metrics
|
|
|
|
for metric in ${_METRICS[@]}; do
|
2015-02-21 18:49:18 +01:00
|
|
|
if ! is_function _m_${metric}_init; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2015-02-21 18:18:27 +01:00
|
|
|
_m_${metric}_init
|
|
|
|
done
|
|
|
|
|
|
|
|
# collect metrics
|
|
|
|
while true; do
|
|
|
|
for metric in ${_METRICS[@]}; do
|
2015-02-21 18:49:18 +01:00
|
|
|
if ! is_function _m_${metric}_collect; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2015-02-21 18:18:27 +01:00
|
|
|
result=$(_m_${metric}_collect)
|
|
|
|
_r_${REPORTER}_report $metric $result
|
|
|
|
done
|
|
|
|
|
|
|
|
sleep $INTERVAL
|
2015-02-19 20:15:38 +01:00
|
|
|
done
|