improve error handling

This commit is contained in:
Benjamin Wiegand 2024-05-20 00:52:16 -07:00 committed by Benjamin Wiegand
parent 01c44aa2fe
commit ff206c24cb

15
main.py
View File

@ -17,7 +17,6 @@ from targets.memory import *
import targets.power
import argparse
import traceback
NAMESPACE = 'ilo'
@ -41,7 +40,7 @@ if args.quiet and args.verbose:
print('stop it. (--quiet and --verbose do not mix)')
exit(1)
SCAN_FAIL_COUNTER = Counter('exporter', 'Number of times scanning the iLO for SNMP variables has failed.', namespace=NAMESPACE, subsystem='snmp_scan_failures')
SCAN_FAIL_COUNTER = Counter('scrape_failures', 'Number of times scraping the iLO for SNMP variables has failed.', namespace=NAMESPACE, subsystem='exporter')
def noisy(*a, **kwa):
@ -76,14 +75,9 @@ class BulkCollector(Collector):
def collect(self):
cache = {}
if self._scan_on_collect:
try:
if self._scan_on_collect:
self.scan()
except Exception as e:
traceback.print_exception(e)
print('Failed to scan SNMP, aborting collection')
SCAN_FAIL_COUNTER.inc()
return
for documentation, bulk_values, bulk_labels in self._metrics_groups:
metric_name = self._name_template % bulk_values.name
@ -120,6 +114,11 @@ class BulkCollector(Collector):
yield metric
except Exception as e:
print('Failed to scan SNMP, aborting collection')
SCAN_FAIL_COUNTER.inc()
raise e
def get_power_draw() -> float:
verbose('collecting ilo_server_power_draw')