mirror of
https://github.com/netinvent/npbackup.git
synced 2025-02-24 14:35:36 +08:00
Fix prometheus metrics cannot be empty
This commit is contained in:
parent
4c21b140d9
commit
31caafffe2
1 changed files with 19 additions and 15 deletions
|
@ -35,7 +35,7 @@ def restic_str_output_to_json(
|
||||||
restic_exit_status: Union[bool, int], output: str
|
restic_exit_status: Union[bool, int], output: str
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""
|
"""
|
||||||
Parsse restic output when used without `--json` parameter
|
Parse restic output when used without `--json` parameter
|
||||||
"""
|
"""
|
||||||
if restic_exit_status is False or (
|
if restic_exit_status is False or (
|
||||||
restic_exit_status is not True and restic_exit_status != 0
|
restic_exit_status is not True and restic_exit_status != 0
|
||||||
|
@ -163,7 +163,7 @@ def restic_str_output_to_json(
|
||||||
logger.error("Trace:", exc_info=True)
|
logger.error("Trace:", exc_info=True)
|
||||||
errors = True
|
errors = True
|
||||||
|
|
||||||
metrics["errors"] = errors
|
metrics["errors"] = 1 if errors else 0
|
||||||
return metrics
|
return metrics
|
||||||
|
|
||||||
|
|
||||||
|
@ -207,25 +207,29 @@ def restic_json_to_prometheus(
|
||||||
if key.startswith(starters):
|
if key.startswith(starters):
|
||||||
for enders in ("new", "changed", "unmodified"):
|
for enders in ("new", "changed", "unmodified"):
|
||||||
if key.endswith(enders):
|
if key.endswith(enders):
|
||||||
prom_metrics.append(
|
if value is not None:
|
||||||
f'restic_{starters}{{{labels},state="{enders}",action="backup"}} {value}'
|
prom_metrics.append(
|
||||||
)
|
f'restic_{starters}{{{labels},state="{enders}",action="backup"}} {value}'
|
||||||
skip = True
|
)
|
||||||
|
skip = True
|
||||||
if skip:
|
if skip:
|
||||||
continue
|
continue
|
||||||
if key == "total_files_processed":
|
if key == "total_files_processed":
|
||||||
prom_metrics.append(
|
if value is not None:
|
||||||
f'restic_files{{{labels},state="total",action="backup"}} {value}'
|
prom_metrics.append(
|
||||||
)
|
f'restic_files{{{labels},state="total",action="backup"}} {value}'
|
||||||
continue
|
)
|
||||||
|
continue
|
||||||
if key == "total_bytes_processed":
|
if key == "total_bytes_processed":
|
||||||
prom_metrics.append(
|
if value is not None:
|
||||||
f'restic_snasphot_size_bytes{{{labels},action="backup",type="processed"}} {value}'
|
prom_metrics.append(
|
||||||
)
|
f'restic_snasphot_size_bytes{{{labels},action="backup",type="processed"}} {value}'
|
||||||
continue
|
)
|
||||||
|
continue
|
||||||
if "duration" in key:
|
if "duration" in key:
|
||||||
key += "_seconds"
|
key += "_seconds"
|
||||||
prom_metrics.append(f'restic_{key}{{{labels},action="backup"}} {value}')
|
if value is not None:
|
||||||
|
prom_metrics.append(f'restic_{key}{{{labels},action="backup"}} {value}')
|
||||||
|
|
||||||
backup_too_small = False
|
backup_too_small = False
|
||||||
if minimum_backup_size_error:
|
if minimum_backup_size_error:
|
||||||
|
|
Loading…
Reference in a new issue