diff --git a/roles/prometheus/tasks/main.yml b/roles/prometheus/tasks/main.yml index 8ee3667..b296be4 100644 --- a/roles/prometheus/tasks/main.yml +++ b/roles/prometheus/tasks/main.yml @@ -29,7 +29,18 @@ notify: Restart prometheus no_log: true -- name: Setup the arguments for node-exporter +- name: Add node targets file + template: + src: node-targets.json + dest: /etc/prometheus/node-targets.json + owner: prometheus + group: prometheus + mode: '0640' + force: no + notify: Restart prometheus + no_log: true + +- name: Setup the arguments for prometheus template: src: prometheus dest: /etc/default/prometheus diff --git a/roles/prometheus/templates/node-targets.json b/roles/prometheus/templates/node-targets.json new file mode 100644 index 0000000..64d12f6 --- /dev/null +++ b/roles/prometheus/templates/node-targets.json @@ -0,0 +1,6 @@ +[ + { + "targets": [ + ] + } +] diff --git a/roles/prometheus/templates/prometheus.yml b/roles/prometheus/templates/prometheus.yml index 80a1a80..4608f3e 100644 --- a/roles/prometheus/templates/prometheus.yml +++ b/roles/prometheus/templates/prometheus.yml @@ -33,7 +33,15 @@ scrape_configs: - targets: ['{{ lan_address }}:9090'] - job_name: node - # If prometheus-node-exporter is installed, grab stats about the local - # machine by default. - static_configs: - - targets: ['{{ lan_address }}:9100'] + file_sd_configs: + - files: + - '/etc/prometheus/node-targets.json' + relabel_configs: + # Do not put :9100 in instance name, rather here + - source_labels: [__address__] + target_label: __param_target + - source_labels: [__param_target] + target_label: instance + - source_labels: [__param_target] + target_label: __address__ + replacement: '$1:9100'