From 9dd9c2ec2e0e0f34db95d9650ea253c147f8c7d3 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 11 Jan 2022 00:19:35 +0100 Subject: zfs/syncoid: add duration of job to prometheus metrics --- roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 | 15 +++++++++++++-- roles/storage/zfs/syncoid/templates/syncoid_pull.j2 | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 b/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 index 5ddc691b..3869e975 100644 --- a/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 +++ b/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 @@ -3,7 +3,7 @@ echo "running sanoid --prune to cleanup old snapshots" sleep 5 -echo systemctl start --wait sanoid-prune.service +systemctl start --wait sanoid-prune.service echo "wait 30s (autosuspend cooldown period)" sleep 30 @@ -27,8 +27,19 @@ for line in $(cat "$RUNTIME_DIRECTORY/exit_codes"); do fi done +now=$(date +"%s") +starttime=$(cat "$RUNTIME_DIRECTORY/start") +duration=0 +if [[ $starttime =~ [^[:digit:]] ]]; then + ret=-1 + echo "invalid starttime from pull script: $starttime" +else + duration=$(( now - starttime )) +fi + cat <> "$RUNTIME_DIRECTORY/metrics" -syncoid_pull_last_run{backup_server="{{ inventory_hostname }}"} $(date +"%s") +syncoid_pull_run{backup_server="{{ inventory_hostname }}"} $now +syncoid_pull_duration_seconds{backup_server="{{ inventory_hostname }}"} $duration EOF diff --git a/roles/storage/zfs/syncoid/templates/syncoid_pull.j2 b/roles/storage/zfs/syncoid/templates/syncoid_pull.j2 index ab6c3116..d54683c5 100644 --- a/roles/storage/zfs/syncoid/templates/syncoid_pull.j2 +++ b/roles/storage/zfs/syncoid/templates/syncoid_pull.j2 @@ -16,6 +16,12 @@ if [ -n "$1" ]; then shift fi +if [ -n "$RUNTIME_DIRECTORY" ]; then + if [ ! -e "$RUNTIME_DIRECTORY/start" ]; then + date +"%s" > "$RUNTIME_DIRECTORY/start" + fi +fi + /usr/sbin/syncoid --sshoption "UserKnownHostsFile=/var/lib/syncoid/ssh.knownhosts" --sshoption "HashKnownHosts=no" --sshkey "/var/lib/syncoid/id_ssh_ed25519" --no-sync-snap --compress zstd-fast "$@" "$src_host:$src_path" "$dest_path" ret=$? -- cgit v1.2.3