Skip to content

Commit

Permalink
Log more useful information on parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mbugert committed May 3, 2020
1 parent 090443c commit a5eb078
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions connectbox_exporter/connectbox_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import threading
import time
from typing import Dict
import json

import click
import compal
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit a5eb078

Please sign in to comment.