Skip to content

Commit e900502

Browse files
Multi-instance PBS exporter support
Co-authored-by: 33Fraise33 <33Fraise33@users.noreply.github.com>
1 parent c5ba989 commit e900502

3 files changed

Lines changed: 67 additions & 15 deletions

File tree

playbooks/host_files/beokpdcovm01/files/prometheus/alerts.d/pbs.rules.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
groups:
33
- name: pbs.rules
44
rules:
5-
- alert: PBS backup failed
5+
- alert: PBSBackupFailed
66
expr: pbs_task_status{task_type="backup",status=~"(?i:failed|error)"} == 1
77
for: 10m
88
labels:
@@ -11,7 +11,7 @@ groups:
1111
summary: "PBS backup failed on {{ $labels.node_name }}"
1212
description: "Backup {{ $labels.task }} for datastore {{ $labels.datastore }} failed."
1313

14-
- alert: PBS verification failed
14+
- alert: PBSVerificationFailed
1515
expr: pbs_task_status{task_type="verify",status=~"(?i:failed|error)"} == 1
1616
for: 10m
1717
labels:
@@ -20,7 +20,7 @@ groups:
2020
summary: "PBS verification failed on {{ $labels.node_name }}"
2121
description: "Verification {{ $labels.task }} for datastore {{ $labels.datastore }} failed."
2222

23-
- alert: PBS sync failed
23+
- alert: PBSSyncFailed
2424
expr: pbs_task_status{task_type="sync",status=~"(?i:failed|error)"} == 1
2525
for: 10m
2626
labels:

playbooks/host_files/beokpdcovm01/templates/prometheus/prometheus.yml.j2

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,17 @@ scrape_configs:
262262
- targets:
263263
- "prometheus-adguard_exporter:9618"
264264

265-
- job_name: 'pbs_exporter'
265+
{% if prometheus.features.pbs_exporter | default(false) %}
266+
{% for pbs_instance in pbs_exporter_instances | default([]) %}
267+
- job_name: 'pbs_exporter_{{ pbs_instance.name }}'
266268
metrics_path: /probe
267269
http_sd_configs:
268270
- <<: *netbox_auth
269271
url: https://netbox.unitix.be/api/plugins/prometheus-sd/virtual-machines/?status=active&tag=pbs
270272
relabel_configs:
273+
- source_labels: [__meta_netbox_name]
274+
regex: '^{{ pbs_instance.netbox_name | regex_escape }}$'
275+
action: keep
271276
- source_labels: [__meta_netbox_primary_ip]
272277
target_label: __param_target
273278
- source_labels: [__param_target]
@@ -281,7 +286,10 @@ scrape_configs:
281286
- source_labels: [__meta_netbox_role_slug]
282287
target_label: device_role
283288
- target_label: __address__
284-
replacement: "prometheus-pbs_exporter:9569"
289+
replacement: "prometheus-pbs-exporter-{{ pbs_instance.name }}:9569"
290+
291+
{% endfor %}
292+
{% endif %}
285293

286294
- job_name: "hass"
287295
metrics_path: /api/prometheus
Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,75 @@
11
---
2-
- name: Validate PBS exporter credentials
2+
- name: Validate PBS exporter instances list
33
ansible.builtin.assert:
44
that:
5-
- pbs_exporter_api_token_id is defined
6-
- pbs_exporter_api_token_id | length > 0
7-
- pbs_exporter_api_token_secret is defined
8-
- pbs_exporter_api_token_secret | length > 0
5+
- pbs_exporter_instances is defined
6+
- pbs_exporter_instances is sequence
7+
- pbs_exporter_instances is not string
8+
- pbs_exporter_instances | length > 0
99
fail_msg: >-
10-
pbs_exporter_api_token_id and pbs_exporter_api_token_secret must be
11-
supplied as inventory variables.
10+
pbs_exporter_instances must be a non-empty inventory list.
1211
no_log: true
1312

14-
- name: Setup Prometheus PBS exporter
13+
- name: Validate PBS exporter instances
14+
ansible.builtin.assert:
15+
that:
16+
- item.name is defined
17+
- item.name is string
18+
- item.name is match('^[a-z0-9][a-z0-9-]*$')
19+
- item.netbox_name is defined
20+
- item.netbox_name is string
21+
- item.netbox_name | length > 0
22+
- item.api_token_id is defined
23+
- item.api_token_id is string
24+
- item.api_token_id | length > 0
25+
- item.api_token_secret is defined
26+
- item.api_token_secret is string
27+
- item.api_token_secret | length > 0
28+
fail_msg: >-
29+
Every PBS exporter instance must define a lowercase name, netbox_name,
30+
api_token_id, and api_token_secret.
31+
loop: "{{ pbs_exporter_instances }}"
32+
loop_control:
33+
label: hidden
34+
no_log: true
35+
36+
- name: Validate unique PBS exporter instance selectors
37+
ansible.builtin.assert:
38+
that:
39+
- >-
40+
pbs_exporter_instances | map(attribute='name') | unique | list | length
41+
== pbs_exporter_instances | length
42+
- >-
43+
pbs_exporter_instances | map(attribute='netbox_name') | unique | list | length
44+
== pbs_exporter_instances | length
45+
fail_msg: PBS exporter instance names and NetBox names must be unique.
46+
no_log: true
47+
48+
- name: Remove legacy Prometheus PBS exporter
1549
community.docker.docker_container:
1650
name: prometheus-pbs_exporter
51+
state: absent
52+
no_log: true
53+
54+
- name: Setup Prometheus PBS exporters
55+
community.docker.docker_container:
56+
name: "prometheus-pbs-exporter-{{ item.name }}"
1757
image: "{{ pbs_exporter_image | default('natrontech/pbs-exporter:latest') }}"
1858
networks:
1959
- name: monitoring
2060
dns_servers: "{{ dns.servers }}"
2161
env:
22-
PBS_TOKEN_ID: "{{ pbs_exporter_api_token_id }}"
23-
PBS_TOKEN_SECRET: "{{ pbs_exporter_api_token_secret }}"
62+
PBS_TOKEN_ID: "{{ item.api_token_id }}"
63+
PBS_TOKEN_SECRET: "{{ item.api_token_secret }}"
2464
PBS_TLS_INSECURE: "true"
2565
restart: true
2666
restart_policy: always
2767
state: started
2868
pull: true
2969
labels:
3070
traefik.enable: "false"
71+
com.unitix.prometheus.pbs-exporter: "true"
72+
loop: "{{ pbs_exporter_instances }}"
73+
loop_control:
74+
label: hidden
3175
no_log: true

0 commit comments

Comments
 (0)