Refactor processed_bytes metrics code, see #160

This commit is contained in:
deajan 2025-05-13 09:19:09 +02:00
parent 6c28617606
commit aa89cb04d5

View file

@ -236,26 +236,25 @@ def restic_json_to_prometheus(
if value is not None: if value is not None:
prom_metrics.append(f'restic_{key}{{{labels},action="backup"}} {value}') prom_metrics.append(f'restic_{key}{{{labels},action="backup"}} {value}')
try:
processed_bytes = BytesConverter(
str(restic_json["total_bytes_processed"])
).human_iec_bytes
logger.info(f"Processed {processed_bytes} of data")
except Exception as exc:
logger.error(f"Cannot find processed bytes: {exc}")
backup_too_small = False backup_too_small = False
if minimum_backup_size_error: try:
try: if restic_json["total_bytes_processed"]:
if restic_json["total_bytes_processed"] and restic_json[ processed_bytes = BytesConverter(
"total_bytes_processed" str(restic_json["total_bytes_processed"])
] < int( ).human_iec_bytes
BytesConverter(str(minimum_backup_size_error).replace(" ", "")).bytes logger.info(f"Processed {processed_bytes} of data")
): if minimum_backup_size_error:
backup_too_small = True if processed_bytes < int(
except KeyError: BytesConverter(
# Don't care if we cannot determine backup size error str(minimum_backup_size_error).replace(" ", "")
# Other errors should be triggered, see #141 ).bytes
pass ):
backup_too_small = True
except Exception as exc:
logger.warning(f"Cannot determine processed bytes: {exc}")
logger.debug("Trace:", exc_info=True)
# We don't care if this exception happens, as error state still will raise from
# other parts of this code
good_backup = restic_result and not backup_too_small good_backup = restic_result and not backup_too_small
prom_metrics.append( prom_metrics.append(