Browse Source

use hostname for instance label instead of ip

monitoring
histausse 1 year ago
parent
commit
d0cd731b81
Signed by: histausse
GPG Key ID: 67486F107F62E9E9
  1. 24
      roles/prometheus-node-exporter/tasks/main.yml
  2. 5
      roles/prometheus/templates/prometheus.yml

24
roles/prometheus-node-exporter/tasks/main.yml

@ -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: Put the new target list
copy:
content: "{{ server_target | to_nice_json }}"
dest: /etc/prometheus/node-targets.json
delegate_to: "{{ appointed_prometheus_server }}"
- 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: "{{ 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

5
roles/prometheus/templates/prometheus.yml

@ -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:

Loading…
Cancel
Save