From abd2175a848ecf7f7250233ddc542ef52187f2fa Mon Sep 17 00:00:00 2001 From: Patrick Stadler Date: Sat, 21 Feb 2015 18:49:18 +0100 Subject: [PATCH] clean up function checks --- sysmetricsd.sh | 16 ++++++++++------ utils.sh | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/sysmetricsd.sh b/sysmetricsd.sh index 8648b47..8cc5d96 100755 --- a/sysmetricsd.sh +++ b/sysmetricsd.sh @@ -11,7 +11,7 @@ _METRICS=() # load reporter source ./reporters/${REPORTER}.sh copy_function report _r_${REPORTER}_report -unset -f report +unset -f init report terminate # load metrics 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%.*} copy_function collect _m_${metric}_collect _METRICS+=($metric) - unset -f collect - unset -f init + unset -f init collect terminate done # init metrics for metric in ${_METRICS[@]}; do - [ "`type -t _m_${metric}_init`" != 'function' ] && continue - echo init metric "$metric" + if ! is_function _m_${metric}_init; then + continue + fi + _m_${metric}_init done # collect metrics while true; 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) _r_${REPORTER}_report $metric $result done diff --git a/utils.sh b/utils.sh index 78e8ca4..591793d 100644 --- a/utils.sh +++ b/utils.sh @@ -2,4 +2,8 @@ copy_function () { declare -F $1 > /dev/null || return 1 eval "$(echo "${2}()"; declare -f ${1} | tail -n +2)" +} + +is_function () { + [ "`type -t $1`" == 'function' ] } \ No newline at end of file