mirror of
https://github.com/pstadler/metrics.sh.git
synced 2025-02-28 13:59:12 -05:00
clean up
This commit is contained in:
parent
449c1b9289
commit
e99763c381
15
lib/main.sh
15
lib/main.sh
@ -54,14 +54,14 @@ main_init () {
|
|||||||
|
|
||||||
main_collect () {
|
main_collect () {
|
||||||
# check if reporter exists
|
# check if reporter exists
|
||||||
if ! in_array $(resolve_reporter $__REPORTER) "$__AVAILABLE_REPORTERS"; then
|
if ! in_array $(get_name_for_reporter $__REPORTER) "$__AVAILABLE_REPORTERS"; then
|
||||||
echo "Error: reporter '$__REPORTER' is not available"
|
echo "Error: reporter '$__REPORTER' is not available"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check if metrics exist
|
# check if metrics exist
|
||||||
for metric in $__METRICS; do
|
for metric in $__METRICS; do
|
||||||
if ! in_array $(resolve_metric $metric) "$__AVAILABLE_METRICS"; then
|
if ! in_array $(get_name_for_metric $metric) "$__AVAILABLE_METRICS"; then
|
||||||
echo "Error: metric '$metric' is not available"
|
echo "Error: metric '$metric' is not available"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -76,9 +76,9 @@ main_collect () {
|
|||||||
' 13 INT TERM EXIT
|
' 13 INT TERM EXIT
|
||||||
|
|
||||||
# init reporter
|
# init reporter
|
||||||
local reporter_alias=$(resolve_reporter $__REPORTER)
|
local reporter_name=$(get_name_for_reporter $__REPORTER)
|
||||||
local reporter_file=$(resolve_reporter $__REPORTER)
|
local reporter_alias=$(get_alias $__REPORTER)
|
||||||
load_reporter_with_prefix __r_${reporter_alias}_ ./reporters/${reporter_file}.sh
|
load_reporter_with_prefix __r_${reporter_alias}_ ./reporters/${reporter_name}.sh
|
||||||
|
|
||||||
if is_function __r_${reporter_alias}_defaults; then
|
if is_function __r_${reporter_alias}_defaults; then
|
||||||
__r_${reporter_alias}_defaults
|
__r_${reporter_alias}_defaults
|
||||||
@ -94,12 +94,11 @@ main_collect () {
|
|||||||
for metric in $__METRICS; do
|
for metric in $__METRICS; do
|
||||||
# run in subshell to isolate scope
|
# run in subshell to isolate scope
|
||||||
(
|
(
|
||||||
local metric_name=$(get_name $metric)
|
local metric_name=$(get_name_for_metric $metric)
|
||||||
local metric_alias=$(get_alias $metric)
|
local metric_alias=$(get_alias $metric)
|
||||||
local metric_file=$(resolve_metric $metric)
|
|
||||||
|
|
||||||
# init metric
|
# init metric
|
||||||
load_metric_with_prefix __m_${metric_alias}_ ./metrics/${metric_file}.sh
|
load_metric_with_prefix __m_${metric_alias}_ ./metrics/${metric_name}.sh
|
||||||
|
|
||||||
if is_function __m_${metric_alias}_defaults; then
|
if is_function __m_${metric_alias}_defaults; then
|
||||||
__m_${metric_alias}_defaults
|
__m_${metric_alias}_defaults
|
||||||
|
@ -94,10 +94,6 @@ parse_config () {
|
|||||||
IFS=$RESTORE_IFS
|
IFS=$RESTORE_IFS
|
||||||
}
|
}
|
||||||
|
|
||||||
get_name () {
|
|
||||||
echo $1 | awk 'BEGIN { FS=":" } { print $1 }'
|
|
||||||
}
|
|
||||||
|
|
||||||
get_alias () {
|
get_alias () {
|
||||||
local _alias=$(echo $1 | awk 'BEGIN { FS=":" } { print $2 }')
|
local _alias=$(echo $1 | awk 'BEGIN { FS=":" } { print $2 }')
|
||||||
if [ -z "$_alias" ]; then
|
if [ -z "$_alias" ]; then
|
||||||
@ -106,7 +102,11 @@ get_alias () {
|
|||||||
echo $_alias
|
echo $_alias
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve_reporter () {
|
get_name () {
|
||||||
|
echo $1 | awk 'BEGIN { FS=":" } { print $1 }'
|
||||||
|
}
|
||||||
|
|
||||||
|
get_name_for_reporter () {
|
||||||
local _alias=$(get_alias $1)
|
local _alias=$(get_alias $1)
|
||||||
for reporter in $__CFG_REPORTERS; do
|
for reporter in $__CFG_REPORTERS; do
|
||||||
local __alias=$(get_alias $reporter)
|
local __alias=$(get_alias $reporter)
|
||||||
@ -118,7 +118,7 @@ resolve_reporter () {
|
|||||||
echo $_alias
|
echo $_alias
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve_metric () {
|
get_name_for_metric () {
|
||||||
local _alias=$(get_alias $1)
|
local _alias=$(get_alias $1)
|
||||||
for metric in $__CFG_METRICS; do
|
for metric in $__CFG_METRICS; do
|
||||||
local __alias=$(get_alias $metric)
|
local __alias=$(get_alias $metric)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user