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: set_fact:
server_target: "{{ server_target_file['content'] | b64decode | from_json }}" server_target: "{{ server_target_file['content'] | b64decode | from_json }}"
- name: Add the node to the targets - name: Register the node to the prometheus server
block:
- name: Add the node to the targets
set_fact: set_fact:
server_target: "[{{ server_target[0] | combine({'targets': [lan_address]}, list_merge='append_rp') }}]" new_server_target: "[{{ server_target[0] | combine({'targets': [lan_address + '/' + ansible_facts['nodename']]}, list_merge='append_rp') }}]"
when: lan_address not in server_target.0.targets
- name: Put the new target list - name: Put the new target list
copy: copy:
content: "{{ server_target | to_nice_json }}" content: "{{ new_server_target | to_nice_json }}"
dest: /etc/prometheus/node-targets.json dest: /etc/prometheus/node-targets.json
delegate_to: "{{ appointed_prometheus_server }}" 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: - files:
- '/etc/prometheus/node-targets.json' - '/etc/prometheus/node-targets.json'
relabel_configs: relabel_configs:
# Do not put :9100 in instance name, rather here # Use hostnames instead of ip for the instance label
- source_labels: [__address__] - source_labels: [__address__]
target_label: __param_target target_label: __param_target
- source_labels: [__param_target] - source_labels: [__param_target]
target_label: instance target_label: instance
regex: '.*/(.*)'
replacement: '$1'
- source_labels: [__param_target] - source_labels: [__param_target]
target_label: __address__ target_label: __address__
regex: '(.*)/.*'
replacement: '$1:9100' replacement: '$1:9100'
scheme: https scheme: https
tls_config: tls_config: