mirror of
https://github.com/pstadler/metrics.sh.git
synced 2025-11-10 05:59:41 -05:00
fully working config handling. support for multiple metrics of the same type. implement signal trapping
This commit is contained in:
@@ -24,7 +24,6 @@ parse_config () {
|
||||
|
||||
local _group
|
||||
local _name
|
||||
local _alias
|
||||
local _body
|
||||
|
||||
end_section () {
|
||||
@@ -34,20 +33,16 @@ parse_config () {
|
||||
|
||||
local fn_name
|
||||
if [ "$_group" = "reporter" ]; then
|
||||
__CFG_REPORTERS=$(trim "${__CFG_REPORTERS} ${_name}:${_alias}")
|
||||
__CFG_REPORTERS=$(trim "${__CFG_REPORTERS} ${_name}")
|
||||
fn_name="__r_"
|
||||
elif [ "$_group" = "metric" ]; then
|
||||
__CFG_METRICS=$(trim "${__CFG_METRICS} ${_name}:${_alias}")
|
||||
__CFG_METRICS=$(trim "${__CFG_METRICS} ${_name}")
|
||||
fn_name="__m_"
|
||||
else
|
||||
fn_name="global"
|
||||
fn_name="main"
|
||||
fi
|
||||
|
||||
if [ -n "$_alias" ]; then
|
||||
fn_name="${fn_name}${_alias}"
|
||||
elif [ -n "$_name" ]; then
|
||||
fn_name="${fn_name}${_name}"
|
||||
fi
|
||||
fn_name=${fn_name}$(get_alias $_name)
|
||||
|
||||
if [ -z "$_body" ]; then
|
||||
return
|
||||
@@ -68,7 +63,7 @@ parse_config () {
|
||||
local _section=$(echo $line | grep '^\[.*' | sed 's/\[\(.*\)\]/\1/')
|
||||
if [ -n "$_section" ]; then
|
||||
end_section
|
||||
unset _group _name _alias _body
|
||||
unset _group _name _body
|
||||
|
||||
_group=$(echo $_section | awk '{ print $1 }')
|
||||
|
||||
@@ -78,13 +73,11 @@ parse_config () {
|
||||
fi
|
||||
|
||||
if [ "$_group" = "metrics.sh" ]; then
|
||||
_group="global"
|
||||
_group="main"
|
||||
continue
|
||||
fi
|
||||
|
||||
_section=$(echo $_section | awk '{ print $2 }')
|
||||
_name=$(echo $_section | awk 'BEGIN { FS=":" } { print $1 }')
|
||||
_alias=$(echo $_section | awk 'BEGIN { FS=":" } { print $2 }')
|
||||
_name=$(echo $_section | awk '{ print $2 }')
|
||||
continue
|
||||
fi
|
||||
|
||||
|
||||
@@ -16,4 +16,11 @@ in_array () {
|
||||
|
||||
trim () {
|
||||
echo $1 | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*\$//g'
|
||||
}
|
||||
|
||||
unique_id () {
|
||||
RESTORE_LC_ALL=$LC_ALL
|
||||
LC_ALL=C
|
||||
echo __u_$(cat /dev/urandom | tr -dc 'A-Za-z0-9' | head -c 10)
|
||||
LC_ALL=$RESTORE_LC_ALL
|
||||
}
|
||||
Reference in New Issue
Block a user