archive: test the metric functions and the backup output filter, and skip absent summary fields
This commit is contained in:
parent
723ce866f1
commit
b60779093e
1 changed files with 263 additions and 6 deletions
|
|
@ -57,6 +57,14 @@ in
|
|||
root=${lib.escapeShellArg agentRoot}
|
||||
grants=${lib.escapeShellArg (grants hive)}
|
||||
|
||||
# restic's `--json` output on stdin, reduced to its error and summary lines;
|
||||
# lines that are not JSON objects pass through.
|
||||
restic_output_filter() {
|
||||
jq -R -r '. as $line | ((fromjson? | select(type == "object")) // null) as $j
|
||||
| if $j == null or $j.message_type == "error" or $j.message_type == "summary"
|
||||
then $line else empty end'
|
||||
}
|
||||
|
||||
# One agent: a read-only snapshot of its subvolume when it is one, so the
|
||||
# databases are copied at one instant, else its directory in place.
|
||||
backup_agent() {
|
||||
|
|
@ -97,9 +105,7 @@ in
|
|||
${restic}/bin/restic backup --json --host "$agent" --tag archive --exclude-caches \
|
||||
${lib.concatMapStringsSep " " (e: "--exclude ${lib.escapeShellArg e}") excludes} \
|
||||
-- "''${targets[@]}" |
|
||||
jq -R -r '. as $line | ((fromjson? | select(type == "object")) // null) as $j
|
||||
| if $j == null or $j.message_type == "error" or $j.message_type == "summary"
|
||||
then $line else empty end' || rc=$?
|
||||
restic_output_filter || rc=$?
|
||||
fi
|
||||
if [ -n "$snap" ]; then
|
||||
btrfs subvolume delete "$snap" >/dev/null || rc=1
|
||||
|
|
@ -120,9 +126,9 @@ in
|
|||
metrics+=("hyperhive.archive.backup.last_success_timestamp_seconds=$finished")
|
||||
summary="$(printf '%s\n' "$out" | jq -R -r '
|
||||
fromjson? | select(type == "object" and .message_type == "summary")
|
||||
| "hyperhive.archive.backup.data_added_bytes=\(.data_added)",
|
||||
"hyperhive.archive.backup.files_new=\(.files_new)",
|
||||
"hyperhive.archive.backup.files_changed=\(.files_changed)"' 2>/dev/null)" || summary=""
|
||||
| {data_added_bytes: .data_added, files_new: .files_new, files_changed: .files_changed}
|
||||
| to_entries[] | select(.value | type == "number")
|
||||
| "hyperhive.archive.backup.\(.key)=\(.value)"' 2>/dev/null)" || summary=""
|
||||
while IFS= read -r line; do
|
||||
[ -z "$line" ] || metrics+=("$line")
|
||||
done <<<"$summary"
|
||||
|
|
|
|||
Loading…
Reference in a new issue