Add execution duration metrics
This commit is contained in:
25
backup.sh
25
backup.sh
@@ -2,16 +2,33 @@
|
|||||||
|
|
||||||
BACKUP_PATH=${BACKUP_PATH:-$1}
|
BACKUP_PATH=${BACKUP_PATH:-$1}
|
||||||
INSTANCE="$(echo ${INSTANCE:-${TAG}} | envsubst)"
|
INSTANCE="$(echo ${INSTANCE:-${TAG}} | envsubst)"
|
||||||
|
KEEP_ARGS=${KEEP_ARGS:-"--keep-hourly 12 --keep-daily 7 --keep-monthly 3"}
|
||||||
export RESTIC_REPOSITORY="$(echo ${RESTIC_REPOSITORY} | envsubst)"
|
export RESTIC_REPOSITORY="$(echo ${RESTIC_REPOSITORY} | envsubst)"
|
||||||
|
|
||||||
|
echo -n > /tmp/metrics
|
||||||
|
ts_start=$(date +%s)
|
||||||
|
|
||||||
|
ts=$(date +%s)
|
||||||
restic cat config >/dev/null || restic init
|
restic cat config >/dev/null || restic init
|
||||||
|
echo "restic_init_duration $(echo "$(date +%s) - $ts" | bc)" >> /tmp/metrics
|
||||||
|
|
||||||
|
ts=$(date +%s)
|
||||||
restic backup --verbose --tag ${TAG} ${BACKUP_PATH}
|
restic backup --verbose --tag ${TAG} ${BACKUP_PATH}
|
||||||
restic forget --prune --tag ${TAG} -g paths,tags --keep-hourly 12 --keep-daily 7 --keep-monthly 3
|
echo "restic_backup_duration $(echo "$(date +%s) - $ts" | bc)" >> /tmp/metrics
|
||||||
|
|
||||||
|
ts=$(date +%s)
|
||||||
|
restic forget --prune --tag ${TAG} -g paths,tags ${KEEP_ARGS}
|
||||||
|
echo "restic_forget_duration $(echo "$(date +%s) - $ts" | bc)" >> /tmp/metrics
|
||||||
|
|
||||||
|
|
||||||
# Metrics
|
# Metrics
|
||||||
|
ts=$(date +%s)
|
||||||
restic stats --json latest > /tmp/stats.json
|
restic stats --json latest > /tmp/stats.json
|
||||||
restic snapshots --json latest > /tmp/snapshots.json
|
restic snapshots --json latest > /tmp/snapshots.json
|
||||||
|
echo "restic_stats_duration $(echo "$(date +%s) - $ts" | bc)" >> /tmp/metrics
|
||||||
|
|
||||||
cat /tmp/stats.json | jq -r '"restic_stats_total_size_bytes \(.total_size)\nrestic_stats_total_file_count \(.total_file_count)"' > /tmp/output
|
echo "restic_total_duration $(echo "$(date +%s) - $ts_start" | bc)" >> /tmp/metrics
|
||||||
cat /tmp/snapshots.json | jq -r 'max_by(.time) | .time | sub(".[0-9]+Z$"; "Z") | fromdate | "restic_stats_last_snapshot_timestamp \(.)"' >> /tmp/output
|
|
||||||
cat /tmp/output | curl --data-binary @- "http://prometheus-pushgateway.monitoring.svc.cluster.local:9091/metrics/job/backup/instance/${INSTANCE}"
|
cat /tmp/stats.json | jq -r '"restic_stats_total_size_bytes \(.total_size)\nrestic_stats_total_file_count \(.total_file_count)"' >> /tmp/metrics
|
||||||
|
cat /tmp/snapshots.json | jq -r 'max_by(.time) | .time | sub(".[0-9]+Z$"; "Z") | fromdate | "restic_stats_last_snapshot_timestamp \(.)"' >> /tmp/metrics
|
||||||
|
cat /tmp/metrics | curl --data-binary @- "http://prometheus-pushgateway.monitoring.svc.cluster.local:9091/metrics/job/backup/instance/${INSTANCE}"
|
||||||
|
|||||||
Reference in New Issue
Block a user