From a5eb078e577d765cb4e2580163212e92728cd3f9 Mon Sep 17 00:00:00 2001 From: Michael Bugert Date: Sun, 3 May 2020 21:12:07 +0200 Subject: [PATCH] Log more useful information on parsing errors --- connectbox_exporter/connectbox_exporter.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/connectbox_exporter/connectbox_exporter.py b/connectbox_exporter/connectbox_exporter.py index 33b71ac..a7a4db6 100755 --- a/connectbox_exporter/connectbox_exporter.py +++ b/connectbox_exporter/connectbox_exporter.py @@ -2,6 +2,7 @@ import threading import time from typing import Dict +import json import click import compal @@ -63,11 +64,11 @@ def collect(self): # skip extracting further metrics if login failed if connectbox is not None: for extractor in self.metric_extractors: + raw_xmls = {} try: pre_scrape_time = time.time() # obtain all raw XML responses for an extractor, then extract metrics - raw_xmls = {} for fun in extractor.functions: self.logger.debug(f"Querying fun={fun}...") raw_xml = connectbox.xml_getter(fun, {}).content @@ -82,8 +83,9 @@ def collect(self): scrape_success[extractor.name] = True except (XMLSyntaxError, AttributeError) as e: # in case of a less serious error, log and continue scraping the next extractor - # TODO make this more useful: log in which extractor the error happened and print the xml at fault - self.logger.error(repr(e)) + jsonized = json.dumps(raw_xmls) + message = f"Failed to extract '{extractor.name}'. Please open an issue on Github and include the following:\n{repr(e)}\n{jsonized}" + self.logger.error(message) except (ConnectionError, Timeout) as e: # in case of serious connection issues, abort and do not try the next extractor self.logger.error(repr(e))