load multiple instances of the same metrics

This commit is contained in:
Patrick Stadler 2015-03-21 10:55:45 +01:00
parent b20446507c
commit f06e238b85
3 changed files with 34 additions and 10 deletions

View File

@ -20,16 +20,17 @@ main_load () {
__AVAILABLE_REPORTERS=$(trim "$__AVAILABLE_REPORTERS $reporter") __AVAILABLE_REPORTERS=$(trim "$__AVAILABLE_REPORTERS $reporter")
done done
# load metrics # load available metrics
for file in ./metrics/*.sh; do for file in ./metrics/*.sh; do
local filename=$(basename $file) local filename=$(basename $file)
local metric=${filename%.*} local metric=${filename%.*}
load_metric_with_prefix __m_${metric}_ $file
# register metric # register metric
__AVAILABLE_METRICS=$(trim "$__AVAILABLE_METRICS $metric") __AVAILABLE_METRICS=$(trim "$__AVAILABLE_METRICS $metric")
done done
load_metric_with_prefix __m_${metric}_ $file
} }
main_init () { main_init () {
@ -54,6 +55,7 @@ main_init () {
# check if metrics exist # check if metrics exist
for metric in $__METRICS; do for metric in $__METRICS; do
metric=$(get_name $metric)
if ! in_array $metric "$__AVAILABLE_METRICS"; then if ! in_array $metric "$__AVAILABLE_METRICS"; then
echo "Error: metric '$metric' is not available" echo "Error: metric '$metric' is not available"
exit 1 exit 1
@ -67,11 +69,16 @@ main_init () {
# init metrics # init metrics
for metric in $__METRICS; do for metric in $__METRICS; do
if ! is_function __m_${metric}_init; then local metric_name=$(get_name $metric)
local metric_alias=$(get_alias $metric)
load_metric_with_prefix __m_${metric_alias}_ ./metrics/${metric_name}.sh
if ! is_function __m_${metric_alias}_init; then
continue continue
fi fi
__m_${metric}_init __m_${metric_alias}_init
done done
} }
@ -93,14 +100,15 @@ main_collect () {
# collect metrics # collect metrics
for metric in $__METRICS; do for metric in $__METRICS; do
metric=$(get_alias $metric)
if ! is_function __m_${metric}_collect; then if ! is_function __m_${metric}_collect; then
continue continue
fi fi
# fork # fork
(while true; do (while true; do
__m_${metric}_collect __m_${metric}_collect
sleep $INTERVAL sleep $INTERVAL
done) & done) &
done done
@ -111,6 +119,7 @@ main_collect () {
main_terminate () { main_terminate () {
# terminate metrics # terminate metrics
for metric in $__METRICS; do for metric in $__METRICS; do
metric=$(get_alias $metric)
if ! is_function __m_${metric}_terminate; then if ! is_function __m_${metric}_terminate; then
continue continue
fi fi
@ -130,7 +139,10 @@ main_terminate () {
main_docs () { main_docs () {
echo "# Metrics" echo "# Metrics"
for metric in $__AVAILABLE_METRICS; do for metric in $__AVAILABLE_METRICS; do
load_metric_with_prefix __m_${metric}_ ./metrics/${metric}.sh
if ! is_function __m_${metric}_docs; then if ! is_function __m_${metric}_docs; then
continue continue
fi fi

View File

@ -83,8 +83,8 @@ parse_config () {
fi fi
_section=$(echo $_section | awk '{ print $2 }') _section=$(echo $_section | awk '{ print $2 }')
_name=$(echo $_section | awk 'BEGIN { FS=":" } { print $1 } ') _name=$(echo $_section | awk 'BEGIN { FS=":" } { print $1 }')
_alias=$(echo $_section | awk 'BEGIN { FS=":" } { print $2 } ') _alias=$(echo $_section | awk 'BEGIN { FS=":" } { print $2 }')
continue continue
fi fi
@ -94,4 +94,16 @@ parse_config () {
end_section end_section
IFS=$RESTORE_IFS IFS=$RESTORE_IFS
}
get_name () {
echo $1 | awk 'BEGIN { FS=":" } { print $1 }'
}
get_alias () {
local _alias=$(echo $1 | awk 'BEGIN { FS=":" } { print $2 }')
if [ -z "$_alias" ]; then
_alias=$(echo $1 | awk 'BEGIN { FS=":" } { print $1 }')
fi
echo $_alias
} }

View File

@ -120,7 +120,7 @@ if [ -n "$CONFIG_FILE" ]; then
fi fi
fi fi
main_init $METRICS $REPORTER main_init "$METRICS" "$REPORTER"
verbose "Using metrics: $__METRICS" verbose "Using metrics: $__METRICS"
verbose "Using reporter: $__REPORTER" verbose "Using reporter: $__REPORTER"