diff --git a/defaults/main.yml b/defaults/main.yml index 5467edb..29318e2 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -31,3 +31,5 @@ prometheus_server_job_name: "prometheus" prometheus_server_scrape_interval: 5 prometheus_server_scrape_timeout: 5 prometheus_server_version: "latest" + +prometheus_blackbox_exporter_host: localhost diff --git a/tasks/asserts.yml b/tasks/asserts.yml index ea35ef0..e5147a0 100644 --- a/tasks/asserts.yml +++ b/tasks/asserts.yml @@ -27,7 +27,7 @@ - name: 'prometheus | assert | check if docker pyhon libraries are installed' assert: that: - - "'python-docker' in ansible_facts.packages" + #- "'python-docker' in ansible_facts.packages" - "'python3-docker' in ansible_facts.packages" when: - prometheus_server_enable is defined diff --git a/tasks/blackbox_exporter.yml b/tasks/blackbox_exporter.yml index 9aef1d4..a90843c 100644 --- a/tasks/blackbox_exporter.yml +++ b/tasks/blackbox_exporter.yml @@ -30,8 +30,8 @@ - name: 'prometheus | blackbox exporter | configuration' template: - src: conf/prometheus-blackbox-exporter.yml.j2 - dest: /etc/prometheus/prometheus-blackbox-exporter.yml + src: conf/prometheus-blackbox-exporter.j2 + dest: /etc/default/prometheus-blackbox-exporter owner: root group: root mode: 0600 @@ -52,3 +52,4 @@ daemon_reload: yes enabled: yes name: prometheus-blackbox-exporter.service + diff --git a/templates/conf/prometheus-blackbox-exporter.yml.j2 b/templates/conf/prometheus-blackbox-exporter.j2 similarity index 100% rename from templates/conf/prometheus-blackbox-exporter.yml.j2 rename to templates/conf/prometheus-blackbox-exporter.j2 diff --git a/templates/conf/prometheus.yml.j2 b/templates/conf/prometheus.yml.j2 index 4697d1e..401e8a9 100644 --- a/templates/conf/prometheus.yml.j2 +++ b/templates/conf/prometheus.yml.j2 @@ -160,46 +160,47 @@ scrape_configs: {% endif %} {% if prometheus_blackbox_exporter is defined %} - # blacbox # + # blackbox # {% if prometheus_blackbox_exporter_http is defined %} -{% for target in prometheus_blackbox_exporter_http.values() %} ## http check ## - - job_name: blackbox - url {{ target.service_name }} + - job_name: blackbox - url scrape_interval: 30s scrape_timeout: 10s - metrics_path: {{ target.metrics_path }} + metrics_path: /probe params: module: [http_2xx] static_configs: - targets: - - {{target.host }} +{% for target in prometheus_blackbox_exporter_http %} + - {{target }} +{% endfor %} relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ - replacement: localhost:9115 -{% endfor %} + replacement: {{ prometheus_blackbox_exporter_host }}:9115 {% endif %} {% if prometheus_blackbox_exporter_ping is defined %} -{% for target in prometheus_blackbox_exporter_ping.values() %} ## ping ## - - job_name: blackbox - ping {{ target.service_name }} + - job_name: blackbox - ping scrape_interval: 30s scrape_timeout: 10s params: module: [icmp] static_configs: - targets: - - {{ target.host }} +{% for target in prometheus_blackbox_exporter_ping %} + - {{ target }} +{% endfor %} relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ - replacement: localhost:9115 -{% endfor %} + replacement: {{ prometheus_blackbox_exporter_host }}:9115 {% endif %} {% endif %} + diff --git a/templates/systemd/prometheus-blackbox-exporter.service.j2 b/templates/systemd/prometheus-blackbox-exporter.service.j2 index 5082b5f..9d73d10 100644 --- a/templates/systemd/prometheus-blackbox-exporter.service.j2 +++ b/templates/systemd/prometheus-blackbox-exporter.service.j2 @@ -4,7 +4,7 @@ After=network.target [Service] Type=simple -ExecStart=/usr/local/bin/prometheus-blackbox-exporter --config.file /etc/prometheus/prometheus-blackbox-exporter.yml +ExecStart=/usr/local/bin/prometheus-blackbox-exporter --config.file /etc/default/prometheus-blackbox-exporter [Install] WantedBy=multi-user.target