Skip to content

Commit

Permalink
Add refresh_age metric
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelosthege committed May 21, 2024
1 parent e49f09e commit c47a05a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def run(self):
try:
with generate_metrics_summary.labels(self.ccu_host).time():
self.generate_metrics()
self.refresh_time = time.time()
except OSError as os_error:
logging.info("Failed to generate metrics: {0}".format(os_error))
error_counter.labels(self.ccu_host).inc()
Expand Down Expand Up @@ -183,6 +184,11 @@ def __init__(self, ccu_host, ccu_port, auth, gathering_interval, reload_names_in
self.gathering_interval = int(gathering_interval)
self.reload_names_interval = int(reload_names_interval)
self.devicecount = Gauge('devicecount', 'Number of processed/supported devices', labelnames=['ccu'], namespace=self.METRICS_NAMESPACE)
# Upon request export the seconds since the last successful update.
# This is robust against internal crashes and can be used by the healthcheck.
self.refresh_time = time.time()
self.refresh_age = Gauge("refresh_age_seconds", "Seconds since the last successful refresh.", labelnames=["ccu"], namespace=self.METRICS_NAMESPACE)
self.refresh_age.labels(self.ccu_host).set_function(lambda: time.time() - self.refresh_time)

def generate_metrics(self):
logging.info("Gathering metrics")
Expand Down

0 comments on commit c47a05a

Please sign in to comment.