File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed
environments/common/inventory/group_vars/all Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change 11
11
import os .path
12
12
import re
13
13
14
- def prometheus_node_exporter_targets (hosts , env ):
14
+ def prometheus_node_exporter_targets (hosts , hostvars , env_key ):
15
15
result = []
16
16
per_env = defaultdict (list )
17
17
for host in hosts :
18
- per_env [env ].append (host )
18
+ host_env = hostvars [host ].get (env_key , 'ungrouped' )
19
+ per_env [host_env ].append (host )
19
20
for env , hosts in per_env .items ():
20
21
target = {
21
22
"targets" : ["{target}:9100" .format (target = target ) for target in hosts ],
Original file line number Diff line number Diff line change @@ -22,10 +22,9 @@ prometheus_alert_rules_files: "{{ ansible_inventory_sources | product([prometheu
22
22
23
23
prometheus_alert_rules : []
24
24
25
- # Can set a hostvar 'env' to an arbitrary string to group prometheus targets, e.g. rack.
26
- # env: location-1
25
+ # Can set a hostvar 'prometheus_env' to an arbitrary string to group prometheus targets, e.g. by rack.
27
26
prometheus_targets :
28
- node : " {{ groups.get('node_exporter', []) | reject('equalto' , 'localhost') | prometheus_node_exporter_targets(env | default('ungrouped') ) }}"
27
+ node : " {{ groups.get('node_exporter', []) | prometheus_node_exporter_targets(hostvars , 'prometheus_env' ) }}"
29
28
30
29
prometheus_scrape_configs_default :
31
30
- job_name : " prometheus"
@@ -40,7 +39,7 @@ prometheus_scrape_configs_default:
40
39
- job_name : " node"
41
40
file_sd_configs :
42
41
- files :
43
- - " /etc/prometheus/file_sd/node.yml"
42
+ - /etc/prometheus/file_sd/node.yml
44
43
relabel_configs :
45
44
# strip off port
46
45
- source_labels : ['__address__']
You can’t perform that action at this time.
0 commit comments