Merge branch 'prometheus_nodes_dynamic' into 'master'

Make node updating dynamic in Prometheus

See merge request nounous/ansible!5
certbot_on_virtu
Alexandre (erdnaxe) 2019-04-20 19:16:52 +00:00
commit f8ed65cb2a
4 changed files with 60 additions and 3 deletions

View File

@ -1,9 +1,23 @@
--- ---
# Playbook for monitoring # Deploy Prometheus
- hosts: prometheus.adm.crans.org - hosts: prometheus.adm.crans.org
vars:
# Prometheus targets.json
prometheus_targets:
- labels:
job: node
targets:
- localhost:9100
- vulcain.adm.crans.org:9100
- odlyd.adm.crans.org:9100
- labels:
job: prometheus
targets:
- localhost:9090
roles: roles:
- prometheus - prometheus
# Monitor all hosts
- hosts: all - hosts: all
roles: roles:
- prometheus-node - prometheus-node

View File

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

View File

@ -1,9 +1,20 @@
--- ---
- name: Install Prometheus
- name: Instal Prometheus
apt: apt:
update_cache: true update_cache: true
name: prometheus name: prometheus
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded
- name: Configure Prometheus
template:
src: prometheus/prometheus.yml.j2
dest: /etc/prometheus/prometheus.yml
notify: Restart Prometheus
# We don't need to restart Prometheus when updating nodes
- name: Configure Prometheus nodes
copy:
content: "{{ prometheus_targets | to_nice_json }}"
dest: /etc/prometheus/targets.json

View File

@ -0,0 +1,27 @@
# {{ ansible_managed }}
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
# scrape_timeout is set to the global default (10s).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'example'
# Load and evaluate rules in this file every 'evaluation_interval' seconds.
rule_files:
# - "first.rules"
# - "second.rules"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
- job_name: dummy
# This reload dynamically the list of targets
# You don't need to restart Prometheus when updating targets.json
file_sd_configs:
- files:
- '/etc/prometheus/targets.json'