Track the longest life across reloads

This commit is contained in:
Nick Chambers 2021-06-30 01:46:10 -05:00
parent 0a83bcda03
commit f8b6195ab3
1 changed files with 73 additions and 0 deletions

73
rowbot
View File

@ -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
}