mirror of
https://github.com/netinvent/npbackup.git
synced 2025-09-16 01:47:54 +08:00
Add exec time to prometheus metrics
This commit is contained in:
parent
172f62a42d
commit
594ce69959
1 changed files with 13 additions and 0 deletions
|
@ -129,6 +129,15 @@ def metric_writer(
|
||||||
)
|
)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
pass
|
pass
|
||||||
|
# Add exec time
|
||||||
|
try:
|
||||||
|
exec_time = os.environ.get("NPBACKUP_EXEC_TIME", None)
|
||||||
|
exec_time = float(exec_time)
|
||||||
|
metrics.append(
|
||||||
|
f'npbackup_exec_time{{{labels},action="{operation}",repo_name="{repo_name}",timestamp="{int(datetime.now(timezone.utc).timestamp())}"}} {exec_time}'
|
||||||
|
)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
logger.warning("Cannot get exec time from environment")
|
||||||
|
|
||||||
logger.debug("Metrics computed:\n{}".format("\n".join(metrics)))
|
logger.debug("Metrics computed:\n{}".format("\n".join(metrics)))
|
||||||
if destination and dry_run:
|
if destination and dry_run:
|
||||||
|
@ -399,6 +408,10 @@ class NPBackupRunner:
|
||||||
self.write_logs(
|
self.write_logs(
|
||||||
f"Runner took {self.exec_time} seconds for {fn.__name__}", level="info"
|
f"Runner took {self.exec_time} seconds for {fn.__name__}", level="info"
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
os.environ['NPBACKUP_EXEC_TIME'] = str(self.exec_time)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
Loading…
Add table
Reference in a new issue