use hostname for instance label instead of ip

This commit is contained in:
histausse 2021-09-23 17:57:01 +02:00
parent bf386501d0
commit d0cd731b81
Signed by: histausse
GPG key ID: 67486F107F62E9E9
2 changed files with 17 additions and 12 deletions

View file

@ -96,14 +96,16 @@
set_fact:
server_target: "{{ server_target_file['content'] | b64decode | from_json }}"
- name: Add the node to the targets
set_fact:
server_target: "[{{ server_target[0] | combine({'targets': [lan_address]}, list_merge='append_rp') }}]"
when: lan_address not in server_target.0.targets
- name: Register the node to the prometheus server
block:
- name: Add the node to the targets
set_fact:
new_server_target: "[{{ server_target[0] | combine({'targets': [lan_address + '/' + ansible_facts['nodename']]}, list_merge='append_rp') }}]"
- name: Put the new target list
copy:
content: "{{ server_target | to_nice_json }}"
dest: /etc/prometheus/node-targets.json
delegate_to: "{{ appointed_prometheus_server }}"
- name: Put the new target list
copy:
content: "{{ new_server_target | to_nice_json }}"
dest: /etc/prometheus/node-targets.json
delegate_to: "{{ appointed_prometheus_server }}"
when: (lan_address + '/' + ansible_facts['nodename']) not in server_target.0.targets

View file

@ -37,13 +37,16 @@ scrape_configs:
- files:
- '/etc/prometheus/node-targets.json'
relabel_configs:
# Do not put :9100 in instance name, rather here
# Use hostnames instead of ip for the instance label
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
regex: '.*/(.*)'
replacement: '$1'
- source_labels: [__param_target]
target_label: __address__
regex: '(.*)/.*'
replacement: '$1:9100'
scheme: https
tls_config: