backup: write to victoria-metrics
change vpylxllulmokttmopxvkkllotkqvwqwm
commit 48a032bd2af80bf7d81fd4ea42e017587c9d15dc
author Alpha Chen <alpha@kejadlen.dev>
date
parent rooruyww
diff --git a/lotus-land-story/templates/backup.sh b/lotus-land-story/templates/backup.sh
index a6350ce..fbc8cf5 100644
--- a/lotus-land-story/templates/backup.sh
+++ b/lotus-land-story/templates/backup.sh
@@ -5,6 +5,9 @@ set -eu pipefail
 export RESTIC_REPOSITORY=sftp:restic@mountain-of-faith:/mnt/mountain-of-faith/restic
 export RESTIC_PASSWORD={{ restic.password }}
 
+# Capture start time
+start_time=$(date +%s)
+
 restic --verbose backup \
   /mnt/lotus-land-story/ \
   --exclude=/mnt/lotus-land-story/docker
@@ -29,3 +32,21 @@ curl \
   --retry 5 \
   --output /dev/null \
   https://hc-ping.com/{{ healthchecks_io.backup_sh }}
+
+end_time=$(date +%s)
+duration=$((end_time - start_time))
+timestamp=${end_time}000  # milliseconds
+hostname=$(hostname)
+metrics="backup_duration_seconds{job=\"backup\",host=\"${hostname}\"} ${duration} ${timestamp}
+backup_completed_timestamp{job=\"backup\",host=\"${hostname}\"} ${end_time} ${timestamp}"
+
+# TODO Add the root cert to the system so this doesn't need --insecure
+curl \
+  --insecure \
+  --fail \
+  --silent \
+  --show-error \
+  --max-time 10 \
+  --retry 3 \
+  --data-binary "${metrics}" \
+  https://metrics/api/v1/import/prometheus