mirror of
https://github.com/pstadler/metrics.sh.git
synced 2025-02-28 13:59:12 -05:00
clean up function checks
This commit is contained in:
parent
5d3a3fcdb1
commit
abd2175a84
@ -11,7 +11,7 @@ _METRICS=()
|
|||||||
# load reporter
|
# load reporter
|
||||||
source ./reporters/${REPORTER}.sh
|
source ./reporters/${REPORTER}.sh
|
||||||
copy_function report _r_${REPORTER}_report
|
copy_function report _r_${REPORTER}_report
|
||||||
unset -f report
|
unset -f init report terminate
|
||||||
|
|
||||||
# load metrics
|
# load metrics
|
||||||
for file in $(find ./metrics -type f -name '*.sh'); do
|
for file in $(find ./metrics -type f -name '*.sh'); do
|
||||||
@ -20,21 +20,25 @@ for file in $(find ./metrics -type f -name '*.sh'); do
|
|||||||
metric=${filename%.*}
|
metric=${filename%.*}
|
||||||
copy_function collect _m_${metric}_collect
|
copy_function collect _m_${metric}_collect
|
||||||
_METRICS+=($metric)
|
_METRICS+=($metric)
|
||||||
unset -f collect
|
unset -f init collect terminate
|
||||||
unset -f init
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# init metrics
|
# init metrics
|
||||||
for metric in ${_METRICS[@]}; do
|
for metric in ${_METRICS[@]}; do
|
||||||
[ "`type -t _m_${metric}_init`" != 'function' ] && continue
|
if ! is_function _m_${metric}_init; then
|
||||||
echo init metric "$metric"
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
_m_${metric}_init
|
_m_${metric}_init
|
||||||
done
|
done
|
||||||
|
|
||||||
# collect metrics
|
# collect metrics
|
||||||
while true; do
|
while true; do
|
||||||
for metric in ${_METRICS[@]}; do
|
for metric in ${_METRICS[@]}; do
|
||||||
[ "`type -t _m_${metric}_collect`" != 'function' ] && continue
|
if ! is_function _m_${metric}_collect; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
result=$(_m_${metric}_collect)
|
result=$(_m_${metric}_collect)
|
||||||
_r_${REPORTER}_report $metric $result
|
_r_${REPORTER}_report $metric $result
|
||||||
done
|
done
|
||||||
|
4
utils.sh
4
utils.sh
@ -2,4 +2,8 @@
|
|||||||
copy_function () {
|
copy_function () {
|
||||||
declare -F $1 > /dev/null || return 1
|
declare -F $1 > /dev/null || return 1
|
||||||
eval "$(echo "${2}()"; declare -f ${1} | tail -n +2)"
|
eval "$(echo "${2}()"; declare -f ${1} | tail -n +2)"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_function () {
|
||||||
|
[ "`type -t $1`" == 'function' ]
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user