Skip to content

Instantly share code, notes, and snippets.

@simonswine
Created September 10, 2018 08:40
Show Gist options
  • Save simonswine/494e27e9aa38647a7cb735cc3ccc9da0 to your computer and use it in GitHub Desktop.
Save simonswine/494e27e9aa38647a7cb735cc3ccc9da0 to your computer and use it in GitHub Desktop.
Write restic metrics for repo filesystem for node_exporters file collector
#!/bin/sh
set +e
set +x
NAMESPACE=restic
BACKUP_FOLDER=/opt/backup/restic
for dir in $(find "${BACKUP_FOLDER}" -type d -maxdepth 1 -mindepth 1); do
total_size=$(du -s "${dir}" | cut -f 1)
snapshots_raw=$(ls -t --full-time "${dir}/snapshots")
snapshots_count=$(echo "${snapshots_raw}" | wc -l)
latest_snapshot=$(echo "${snapshots_raw}" | head -n 1 | awk '{ print $6 " " $7}')
latest_snapshot_unix=$(date -d "${latest_snapshot}" +"%s")
OUTPUT="${OUTPUT}${NAMESPACE}_repository_size_bytes{repository=\"${dir}\"} ${total_size}\n"
OUTPUT="${OUTPUT}${NAMESPACE}_snapshots_count{repository=\"${dir}\"} ${snapshots_count}\n"
OUTPUT="${OUTPUT}${NAMESPACE}_latest_snapshot_time_seconds{repository=\"${dir}\"} ${latest_snapshot_unix}\n"
done
echo -ne $OUTPUT | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment