From 8f178085743a346ccfbcaf8da3fdb2693a9fb750 Mon Sep 17 00:00:00 2001 From: Marcos Essindi Date: Wed, 9 Aug 2023 10:10:25 +0200 Subject: [PATCH] Add health status metrics for label selector types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds support for getting health metrics for load balancers with “label” targets. In load balancers with label selector target types, the API will report the health status of each selected server in a “targets” attribute (load_balancer.targets.targets). --- code/exporter.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/code/exporter.py b/code/exporter.py index 6e5994e..a1976df 100644 --- a/code/exporter.py +++ b/code/exporter.py @@ -203,7 +203,15 @@ def get_metrics(metrics_type, lbid): hetzner_load_balancer_name=lb_name).set(get_metrics('bandwidth',load_balancer_id)["metrics"]["time_series"]["bandwidth.out"]["values"][0][1]) lb_info = get_load_balancer_info(load_balancer_id)['load_balancer'] - for target in [x for x in lb_info['targets'] if x['type'] == 'server']: + + targets = [] + for x in lb_info['targets']: + if x['type'] == 'server': + targets.append(x) + elif x['type'] == 'label_selector': + targets.extend(x['targets']) + + for target in targets: for health_status in target['health_status']: hetzner_service_state.labels(hetzner_load_balancer_id=load_balancer_id, hetzner_load_balancer_name=lb_name,