[prometheus] Install snmp export

certbot_on_virtu
Alexandre Iooss 2019-05-13 12:36:03 +02:00
parent 78e1e38b7b
commit 844c485bba
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
6 changed files with 58 additions and 2 deletions

View File

@ -27,6 +27,9 @@
job: prometheus job: prometheus
targets: targets:
- localhost:9090 - localhost:9090
prometheus_snmp_targets:
- targets:
- pulsar.adm.crans.org
roles: roles:
- prometheus - prometheus
- prometheus-alertmanager - prometheus-alertmanager

View File

@ -0,0 +1,5 @@
---
- name: Restart prometheus-node-exporter
service:
name: prometheus-node-exporter
state: restarted

View File

@ -7,6 +7,12 @@
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded
- name: Activate prometheus-node-exporter service
systemd:
name: prometheus-node-exporter
enabled: yes
state: started
# Doesn't work on Debian Stretch # Doesn't work on Debian Stretch
- name: Make Prometheus node-exporter listen on adm only - name: Make Prometheus node-exporter listen on adm only
when: when:

View File

@ -3,3 +3,8 @@
service: service:
name: prometheus name: prometheus
state: restarted state: restarted
- name: Restart prometheus-snmp-exporter
service:
name: prometheus-snmp-exporter
state: restarted

View File

@ -2,7 +2,9 @@
- name: Install Prometheus - name: Install Prometheus
apt: apt:
update_cache: true update_cache: true
name: prometheus name:
- prometheus
- prometheus-snmp-exporter
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded
@ -19,8 +21,30 @@
dest: /etc/prometheus/alert.rules.yml dest: /etc/prometheus/alert.rules.yml
notify: Restart Prometheus notify: Restart Prometheus
# Doesn't work on Debian Stretch
- name: Make Prometheus snmp-exporter listen on adm only
when:
- ansible_distribution_release == 'buster'
lineinfile:
path: /etc/default/prometheus-node-exporter
regexp: '^ARGS='
line: "ARGS=\"--web.listen-address={{ ansible_fqdn }}:9116\""
notify: Restart prometheus-snmp-exporter
# We don't need to restart Prometheus when updating nodes # We don't need to restart Prometheus when updating nodes
- name: Configure Prometheus nodes - name: Configure Prometheus nodes
copy: copy:
content: "{{ prometheus_targets | to_nice_json }}" content: "{{ prometheus_targets | to_nice_json }}"
dest: /etc/prometheus/targets.json dest: /etc/prometheus/targets.json
# We don't need to restart Prometheus when updating nodes
- name: Configure Prometheus SNMP devices
copy:
content: "{{ prometheus_snmp_targets | to_nice_json }}"
dest: /etc/prometheus/targets_snmp.json
- name: Activate prometheus service
systemd:
name: prometheus
enabled: yes
state: started

View File

@ -29,4 +29,17 @@ scrape_configs:
file_sd_configs: file_sd_configs:
- files: - files:
- '/etc/prometheus/targets.json' - '/etc/prometheus/targets.json'
- job_name: snmp
file_sd_configs:
- files:
- '/etc/prometheus/targets_snmp.json'
metrics_path: /snmp
params:
module: [if_mib]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9116