Track the longest life across reloads
This commit is contained in:
parent
4ca361a1d5
commit
c9bedba38d
1 changed files with 73 additions and 0 deletions
73
rowbot
73
rowbot
|
@ -18,6 +18,12 @@ fi
|
|||
export LAST_RELOAD
|
||||
printf -v LAST_RELOAD '%(%s)T' -1
|
||||
|
||||
if [[ ! -v LONGEST_LIFE ]]; then
|
||||
export LONGEST_LIFE=0
|
||||
elif (( LONGEST_LIFE < SECONDS )); then
|
||||
export LONGEST_LIFE=$SECONDS
|
||||
fi
|
||||
|
||||
###
|
||||
# switch toggler
|
||||
###
|
||||
|
@ -120,6 +126,58 @@ is-log-level() {
|
|||
return 1
|
||||
}
|
||||
|
||||
seconds() {
|
||||
local days hours minutes seconds time
|
||||
(( days = $1 / 60 / 60 / 24 ))
|
||||
(( hours = $1 / 60 / 60 % 24 ))
|
||||
(( minutes = $1 / 60 % 60 ))
|
||||
(( seconds = $1 % 60 ))
|
||||
|
||||
if (( days )); then
|
||||
if (( days == 1 )); then
|
||||
time="1 day"
|
||||
else
|
||||
time="$days day"
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( hours )); then
|
||||
if [[ $time ]]; then
|
||||
time+=", "
|
||||
fi
|
||||
|
||||
time+="$hours hour"
|
||||
|
||||
if (( hours > 1 )); then
|
||||
time+=s
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( minutes )); then
|
||||
if [[ $time ]]; then
|
||||
time+=", "
|
||||
fi
|
||||
|
||||
time+="$minutes minute"
|
||||
|
||||
if (( minutes > 1 )); then
|
||||
time+=s
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $time ]]; then
|
||||
time+=", "
|
||||
fi
|
||||
|
||||
time="$seconds second"
|
||||
|
||||
if (( seconds > 1 )); then
|
||||
time+=s
|
||||
fi
|
||||
|
||||
printf -- %s "$time"
|
||||
}
|
||||
|
||||
###
|
||||
# argument parser for parsing arguments
|
||||
###
|
||||
|
@ -373,6 +431,10 @@ config-reload() {
|
|||
export "${env_var^^}"="${!env_var}"
|
||||
done
|
||||
|
||||
if (( SECONDS > LONGEST_LIFE )); then
|
||||
export LONGEST_LIFE=$SECONDS
|
||||
fi
|
||||
|
||||
info "reloading rowbot"
|
||||
exec "$0" --reload "${original_args[@]}"
|
||||
}
|
||||
|
@ -950,6 +1012,10 @@ hook_cmd_control_panel() {
|
|||
export "${env_var^^}"="${!env_var}"
|
||||
done
|
||||
|
||||
if (( SECONDS > LONGEST_LIFE )); then
|
||||
export LONGEST_LIFE=$SECONDS
|
||||
fi
|
||||
|
||||
privmsg "$to" "reloading..."
|
||||
exec "$0" --reload "${original_args[@]}"
|
||||
;;
|
||||
|
@ -996,6 +1062,13 @@ hook_cmd_control_panel() {
|
|||
stats)
|
||||
privmsg "$to" "running since $(printf '%(%c)T' "$START_TIME")"
|
||||
privmsg "$to" "last reload at $(printf '%(%c)T' "$LAST_RELOAD")"
|
||||
|
||||
if (( LONGEST_LIFE > SECONDS )); then
|
||||
privmsg "$to" "longest life so far is $(seconds "$LONGEST_LIFE")"
|
||||
else
|
||||
privmsg "$to" "longest life so far is $(seconds "$SECONDS") (this one)"
|
||||
fi
|
||||
|
||||
privmsg "$to" "reloaded $RELOADED times"
|
||||
esac
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue