#!/usr/bin/env bash # exit if a command fails set -o errexit # exit if required variables are not set set -o nounset # subshells and functions inherit ERR traps set -E # commands required for script execution required_commands="/home/sinc/bin/grafana-snapshots.sh" missing_counter=0 for command in ${required_commands}; do if ! hash "${command}" >/dev/null 2>&1; then printf "Command not found in PATH: %s\n" "${command}" >&2 ((missing_counter++)) fi done if ((missing_counter > 0)); then printf "%d or more commands are missing from PATH. Exiting.\n" "${missing_counter}" >&2 exit 1 fi # set output path if [ "$(hostname)" == "crimson" ]; then output_path="/var/www/html/snapshots.grafana.seedno.de" elif [ "$(hostname)" == "casa" ]; then output_path="/home/sinc/media/html/snapshots.grafana.home.seedno.de" else echo "Unknown grafana host." exit 1 fi # create temporary directory for generating montages temp_dir="$(mktemp -d)" # run on exit function cleanup { # remove temp directory rm -rf "${temp_dir}" } trap cleanup EXIT # generate renders for network receiving echo "Rendering images for network receiving..." /home/sinc/bin/grafana-snapshots.sh "${output_path}/network-receiving-last-1h.png" "6" "now-1h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/network-receiving-last-3h.png" "6" "now-3h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/network-receiving-last-6h.png" "6" "now-6h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/network-receiving-last-12h.png" "6" "now-12h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/network-receiving-last-24h.png" "6" "now-24h" "now" # generate renders for network sending echo "Rendering images for network sending..." /home/sinc/bin/grafana-snapshots.sh "${output_path}/network-sending-last-1h.png" "8" "now-1h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/network-sending-last-3h.png" "8" "now-3h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/network-sending-last-6h.png" "8" "now-6h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/network-sending-last-12h.png" "8" "now-12h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/network-sending-last-24h.png" "8" "now-24h" "now" # generate renders for country receiving echo "Rendering images for country receiving..." /home/sinc/bin/grafana-snapshots.sh "${output_path}/country-receiving-last-1h.png" "4" "now-1h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/country-receiving-last-3h.png" "4" "now-3h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/country-receiving-last-6h.png" "4" "now-6h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/country-receiving-last-12h.png" "4" "now-12h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/country-receiving-last-24h.png" "4" "now-24h" "now" # generate renders for country sending echo "Rendering images for country sending..." /home/sinc/bin/grafana-snapshots.sh "${output_path}/country-sending-last-1h.png" "2" "now-1h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/country-sending-last-3h.png" "2" "now-3h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/country-sending-last-6h.png" "2" "now-6h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/country-sending-last-12h.png" "2" "now-12h" "now" /home/sinc/bin/grafana-snapshots.sh "${output_path}/country-sending-last-24h.png" "2" "now-24h" "now" # create combined images times=(1h 3h 6h 12h 24h) for time in "${times[@]}"; do echo "Compositing images for last ${time}..." convert +append "${output_path}/network-sending-last-${time}.png" "${output_path}/network-receiving-last-${time}.png" "${temp_dir}/network.png" convert +append "${output_path}/country-sending-last-${time}.png" "${output_path}/country-receiving-last-${time}.png" "${temp_dir}/country.png" convert -append "${temp_dir}/network.png" "${temp_dir}/country.png" "${output_path}/combined-last-${time}.png" done