Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Merge branch 'external_label' into 'master'
Browse files Browse the repository at this point in the history
External label



See merge request !3
  • Loading branch information
Paweł Krupa committed May 23, 2017
2 parents e495c2a + de264a5 commit 61e8387
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
57 changes: 44 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Ansible Role: prometheus
An Ansible role that installs Prometheus Monitoring server on Ubuntu-based machines with systemd.
An Ansible role that installs Prometheus Monitoring server with systemd.

## Requirements

Expand All @@ -10,28 +10,47 @@ All needed packages will be installed with this role. Minimal Ansible version -
Available main variables are listed below, along with default values:
```yaml
prometheus_version: 1.5.2
prometheus_gomaxprocs: "{{ ansible_processor_vcpus|default(ansible_processor_count) }}"
prometheus_user: prometheus
prometheus_group: prometheus
prometheus_service_name: prometheus

prometheus_global_scrape_interval: 15s
prometheus_global_evaluation_interval: 15s
prometheus_global_scrape_timeout: 10s
prometheus_self_scrape_interval: "{{ prometheus_global_scrape_interval }}"
prometheus_self_evaluation_interval: "{{ prometheus_global_scrape_interval }}"

prometheus_release_name: "prometheus-{{ prometheus_version }}.linux-amd64"

prometheus_root_dir: /opt/prometheus
prometheus_dist_dir: "{{ prometheus_root_dir }}/dist"
prometheus_bin_dir: "{{ prometheus_root_dir }}/current"
prometheus_rules_dir: "{{ prometheus_config_dir }}/rules"
prometheus_file_sd_config_dir: "{{ prometheus_config_dir }}/tgroups"

prometheus_config_dir: /etc/prometheus
prometheus_pid_path: /var/run/prometheus.pid
prometheus_db_dir: /var/lib/prometheus

prometheus_web_listen_address: ":9090"
prometheus_rules_files: [alert.rules]

prometheus_web_listen_address: "0.0.0.0:9090"
prometheus_web_external_url: 'http://localhost:9090/'
prometheus_alertmanager_url: 'localhost:9093'

prometheus_config_flags:
'config.file': '{{ prometheus_config_dir }}/prometheus.yml'
'storage.local.path': '{{ prometheus_db_dir }}'
'web.listen-address': '{{ prometheus_web_listen_address }}'
'web.external-url': '{{ prometheus_web_external_url }}'
'alertmanager.url': '{{ prometheus_alertmanager_url }}'

prometheus_config_flags_extra: {}
prometheus_pam_domain: "prometheus"
prometheus_pam_nofile_value: "1024"

prometheus_interface: ""
```
All variables you can see [here](defaults/main.yml).
## Dependencies
Expand All @@ -49,25 +68,37 @@ ALERT <alert name>
[ LABELS <label set> ]
[ ANNOTATIONS <label set> ]
```
Example Alertmanager rules files:
```yaml
# Alert for any instance that is unreachable for >5 minutes.
ALERT InstanceDown
IF up == 0
FOR 5m
LABELS { severity = "page" }
ANNOTATIONS {
summary = "Instance {{ $labels.instance }} down",
description = "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.",
}
```

## Example Playbook
```yaml
---
- hosts: all
gather_facts: yes

- hosts: all
become: yes
become_user: root
roles:
- role: ../../prometheus
prometheus_global_labels:
a: b
prometheus_external_labels:
mon: orange

prometheus_target_jobs:
- job_name: 'web-server'
scrape_interval: '50s'
scrape_timeout: '10s'
targets:
- "localhost:9090"
labels:
a: b
- job_name: 'node-exporter.{{ domain }}'
port: 9100
targets_group: all
```
## TODO
3 changes: 0 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

prometheus_version: 1.5.2
prometheus_gomaxprocs: "{{ ansible_processor_vcpus|default(ansible_processor_count) }}"
prometheus_user: prometheus
Expand All @@ -21,12 +20,10 @@ prometheus_rules_dir: "{{ prometheus_config_dir }}/rules"
prometheus_file_sd_config_dir: "{{ prometheus_config_dir }}/tgroups"

# prometheus_rules_src_dir: "{{ playbook_dir }}/../files/rules"
# prometheus_config_parts_src_dir: "{{ playbook_dir }}/../environments/main_server/files"
# prometheus_tgroups_src_dir: "{{ playbook_dir }}/files/tgroups"

prometheus_config_dir: /etc/prometheus
prometheus_db_dir: /var/lib/prometheus
# prometheus_db_dir: /home/soi/prometheus

prometheus_rules_files: [alert.rules]

Expand Down
8 changes: 4 additions & 4 deletions templates/etc/prometheus/prometheus.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ global:
scrape_timeout: {{ prometheus_global_scrape_timeout }}
evaluation_interval: {{ prometheus_global_evaluation_interval }}

{% if prometheus_global_labels and prometheus_global_labels|count > 0 %}
# Attach these extra labels to all timeseries collected by this Prometheus instance.
labels:
{% for k,v in prometheus_global_labels.iteritems() %}
{% if prometheus_external_labels and prometheus_external_labels|count > 0 %}
# Attach these external labels to all timeseries collected by this Prometheus instance.
external_labels:
{% for k,v in prometheus_external_labels.iteritems() %}
{{ k }}: "{{ v }}"
{% endfor %}
{% endif %}
Expand Down
16 changes: 7 additions & 9 deletions tests/playbook/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
become_user: root
roles:
- role: ../../prometheus
prometheus_global_labels:
a: b
prometheus_external_labels:
env: orange

prometheus_target_jobs:
- job_name: 'web-server'
scrape_interval: '50s'
scrape_timeout: '10s'
targets:
- "localhost:9090"
labels:
a: b
- job_name: 'node-exporter.{{ domain }}'
port: 9100
targets_group: all

0 comments on commit 61e8387

Please sign in to comment.