Hatarashi Hako now provides Prometheus metrics; old updates
This commit is contained in:
@@ -21,7 +21,7 @@ flag_error()
|
||||
|
||||
help()
|
||||
{
|
||||
echo "$arg0 - show how long a process has been running"
|
||||
echo "$arg0 - Smartly update container stack"
|
||||
echo " {-s|--stack} [name] -- Run update process just for specified stack (ex: vikunja)"
|
||||
echo " {-v|--verbose|verbose} -- Print debug messages"
|
||||
echo " {-h|--help} -- Print this help message and exit"
|
||||
@@ -69,9 +69,11 @@ declare -a CONTAINER_PATHS
|
||||
declare -a OUTDATED_CONTAINERS
|
||||
declare -a FAILED_CONTAINERS
|
||||
declare -a UPDATED_CONTAINERS
|
||||
|
||||
PROM_FILE="/var/Red-Vol/Media/Containers/prometheus/data/hatarashi-hako.prom"
|
||||
#Remove log from last runs, if present
|
||||
if [[ -f /tmp/docker-updated ]]; then
|
||||
rm /tmp/docker-updated
|
||||
if [[ -f $PROM_FILE ]]; then
|
||||
rm $PROM_FILE
|
||||
fi
|
||||
#Start counting how many containers fail; appears in final mail subject.
|
||||
OUTDATED_COUNT="0"
|
||||
@@ -112,7 +114,7 @@ for container_path in ${CONTAINER_PATHS[@]}; do
|
||||
if [[ -z $local_image ]]; then
|
||||
error "Error fetching local image checksum for container $container_name!"
|
||||
#The script will complain about failed containers later on
|
||||
FAILED_CONTAINERS+=("(local) $container_name")
|
||||
echo "container_updated{name=\"$container_name\"} -1" >> $PROM_FILE
|
||||
continue 2
|
||||
else
|
||||
debug "Local SHA256 for $container_image is" "$local_image"
|
||||
@@ -127,7 +129,7 @@ for container_path in ${CONTAINER_PATHS[@]}; do
|
||||
#Now, if you still don't have an image after the second try, something's fuckey.
|
||||
if [[ -z $remote_image ]]; then
|
||||
error "Error fetching remote image checksum for container" "$container_name!"
|
||||
FAILED_CONTAINERS+=("(remote) $container_name")
|
||||
echo "container_updated{name=\"$container_name\"} -1" >> $PROM_FILE
|
||||
continue 2
|
||||
else
|
||||
debug "Remote SHA256 for $container_image is" "$remote_image"
|
||||
@@ -141,24 +143,18 @@ for container_path in ${CONTAINER_PATHS[@]}; do
|
||||
service=$(cat "$container_path/docker-compose.yml" | grep -B1 "image: $container_image" | head -1 | sed -e 's/^[ \t]*//' -e 's/://g' | grep -v 'container_name')
|
||||
# get container service name (1 line above image) ^ print service name^ ^ omit tabs and : and ^omit container_name
|
||||
info "Attempting to update service" "$service"
|
||||
if docker-compose pull $service; then
|
||||
if docker compose pull $service; then
|
||||
info "Pulled latest image for" "$container_name"
|
||||
if docker-compose up -d --remove-orphans; then
|
||||
if docker compose up -d --remove-orphans; then
|
||||
ok "$container_stack" "has been updated sucessfully!"
|
||||
UPDATED_CONTAINERS+=("($container_stack) $container_name")
|
||||
echo "container_updated{name=\"$container_name\"} 1" >> $PROM_FILE
|
||||
else
|
||||
error "Failed to update" "$container_name!"
|
||||
FAILED_CONTAINERS+=("($container_stack|update) $container_name")
|
||||
#Add to array for mail report
|
||||
OUTDATED_CONTAINERS+=("($container_stack) $container_name")
|
||||
export OUTDATED_COUNT=$(($OUTDATED_COUNT+1))
|
||||
echo "container_updated{name=\"$container_name\"} 0" >> $PROM_FILE
|
||||
fi
|
||||
else
|
||||
error "Failed to pull image for" "$container_name!"
|
||||
FAILED_CONTAINERS+=("($container_stack|pull) $container_name")
|
||||
#Add to array for mail report
|
||||
OUTDATED_CONTAINERS+=("($container_stack) $container_name")
|
||||
export OUTDATED_COUNT=$(($OUTDATED_COUNT+1))
|
||||
echo "container_updated{name=\"$container_name\"} 0" >> $PROM_FILE
|
||||
fi
|
||||
fi
|
||||
#If you found an image tag, reset it before moving on to another container
|
||||
@@ -167,20 +163,3 @@ for container_path in ${CONTAINER_PATHS[@]}; do
|
||||
cd $LOCAL_DIR
|
||||
done
|
||||
echo "All done!"
|
||||
#Iterate over the arrays and output results to a file; if needed, it will be neatly mailed.
|
||||
if [[ ${#OUTDATED_CONTAINERS[@]} != 0 ]] || [[ ${#FAILED_CONTAINERS[@]} != 0 ]] || [[ ${#UPDATED_CONTAINERS[@]} != 0 ]]; then
|
||||
if [[ ${#UPDATED_CONTAINERS[@]} != 0 ]]; then
|
||||
printf "The following containers have updated succefully:\n" > /tmp/docker-updated
|
||||
printf "%s\n" "${UPDATED_CONTAINERS[@]}" >> /tmp/docker-updated
|
||||
fi
|
||||
if [[ ${#OUTDATED_CONTAINERS[@]} != 0 ]]; then
|
||||
printf "The following containers are out of date:\n" >> /tmp/docker-updated
|
||||
printf "%s\n" "${OUTDATED_CONTAINERS[@]}" >> /tmp/docker-updated
|
||||
fi
|
||||
if [[ ${#FAILED_CONTAINERS[@]} != 0 ]]; then
|
||||
printf "The following containers failed the update process:\n" >> /tmp/docker-updated
|
||||
printf "%s\n" "${FAILED_CONTAINERS[@]}" >> /tmp/docker-updated
|
||||
fi
|
||||
cat /tmp/docker-updated | mail -s "Docker containers update report - `date +"%B %d %Y"`" -r "Takahe@pukeko.xyz" matanhorovitz@protonmail.com
|
||||
rm /tmp/docker-updated
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user