Skip to content

Commit

Permalink
Add health status metrics for label selector types
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
dunkelbraun committed Aug 9, 2023
1 parent 2681ef0 commit 8f17808
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion code/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8f17808

Please sign in to comment.