Log metric destination

This commit is contained in:
Orsiris de Jong 2023-05-29 19:33:17 +02:00
parent 60b5776b14
commit 3228f0fad3

View file

@ -99,21 +99,25 @@ def metric_writer(config_dict: dict, restic_result: bool, result_string: str):
) )
if errors or not restic_result: if errors or not restic_result:
logger.error("Restic finished with errors.") logger.error("Restic finished with errors.")
if destination.lower().startswith("file://"): if destination:
destination = destination[len("file://") :] logger.debug("Uploading metrics to {}".format(destination))
with open(destination, "w") as file_handle: if destination.lower().startswith("http"):
for metric in metrics: try:
file_handle.write(metric + "\n") authentication = (
if destination.lower().startswith("http"): config_dict["prometheus"]["http_username"],
try: config_dict["prometheus"]["http_password"],
authentication = ( )
config_dict["prometheus"]["http_username"], except KeyError:
config_dict["prometheus"]["http_password"], logger.info("No metrics authentication present.")
) authentication = None
except KeyError: upload_metrics(destination, authentication, no_cert_verify, metrics)
logger.info("No metrics authentication present.") else:
authentication = None try:
upload_metrics(destination, authentication, no_cert_verify, metrics) with open(destination, "w") as file_handle:
for metric in metrics:
file_handle.write(metric + "\n")
except OSError as exc:
logger.error("Cannot write metrics file {}: {}".format(destination, exc))
except KeyError as exc: except KeyError as exc:
logger.info("Metrics not configured: {}".format(exc)) logger.info("Metrics not configured: {}".format(exc))
except OSError as exc: except OSError as exc: