Added service monitoring functionality to tmux-idle.

master
parent 213d73a3be
commit ea9fc70712

@ -22,7 +22,7 @@ This simple script shows the hardware model of a raspberry pi. That is all.
This isn't so much a script as some small quality of life improvements I've made to my WSL Ubuntu 20.04 systems and Ubuntu 20.04 server. Add whichever you like to the end of your .profile and use 'source ~/.profile' to load it immediately. This isn't so much a script as some small quality of life improvements I've made to my WSL Ubuntu 20.04 systems and Ubuntu 20.04 server. Add whichever you like to the end of your .profile and use 'source ~/.profile' to load it immediately.
**tmux-idle** **tmux-idle**
This script just chills in one of my idle tmux windows and shows me the weather. Planning to update it internally to also show the status of my services. This script just chills in one of my idle tmux windows and shows me the weather. Also added functionality to allow a quick glance at any services that I want to monitor. (All user-configurable options at the top of the file)
### AutoHotKey ### AutoHotKey

@ -2,6 +2,8 @@
# Enter your zipcode here for local weather. # Enter your zipcode here for local weather.
zipcode=20001 zipcode=20001
# Add the services you want to monitor here as an array
servicelist=('apache2' 'gitea' 'postfix')
# Colors are nice # Colors are nice
blk=$(tput setaf 0) blk=$(tput setaf 0)
@ -25,7 +27,7 @@ rows=$(tput lines)
trap ctrl_c INT trap ctrl_c INT
function ctrl_c() { function ctrl_c() {
clear #clear
tput cnorm tput cnorm
echo "${rst}${red}CTRL+C Detected, exiting.${rst}" echo "${rst}${red}CTRL+C Detected, exiting.${rst}"
exit exit
@ -54,6 +56,39 @@ function dothething() {
tput cup 0 0 tput cup 0 0
} }
# This be where we check the services
function servicecheck(){
# If we're not monitoring any services, return
[ ${#servicelist[@]} -eq 0 ] && return
# These are the allowed rows
# TODO? determine lines from after weather print?
servicerow=(15 16 17 18 19)
# These are the allowed columns
# TODO? allow column count instead of static assignments?
servicecol=(1 25 50)
# Loop over the number of services that we're monitoring
# https://askubuntu.com/a/1340735
for index in $(seq 0 $((${#servicelist[@]}-1))); do
# Determine the position of the current service
# we go across and then down
# TODO? allow for variable columns?
let echocol="${servicecol[${index}%3]}"
let echorow="${servicerow[${index}/3]}"
# Put our cursor where we can print
tput cup $echorow $echocol
# Clear the variables we use
unset echocol echorow
# Do the actual service check. is-active returns
# active or inactive. Easy peasy
servicestatus=`systemctl is-active ${servicelist[${index}]}`
# Print out the status, green with a dot (\U25CF) if it's online
# and red with a square (\U25A0) if it's stopped
[ "${servicestatus}" == "active" ] && echo -en "${grn}\U25CF ${servicelist[${index}]}${rst}" || echo -en "${red}\U25A0 ${servicelist[${index}]}${rst}"
done
tput cup 0 0
}
# Clear the screen and let's get going # Clear the screen and let's get going
clear clear
# Make the cursor invisible for the terminal # Make the cursor invisible for the terminal
@ -73,6 +108,8 @@ while true; do
dothething dothething
fi fi
fi fi
# I don't think checking every second is a problem... yet...
servicecheck
# Sleep for a second so we're not hammering the system # Sleep for a second so we're not hammering the system
# with date checks. # with date checks.
sleep 1 sleep 1

Loading…
Cancel
Save