Deploy Prometheus monitoring system using ansible.
- Ansible > 2.2
- go-lang installed on deployer machine (same one where ansible is installed)
- jmespath on deployer machine
All variables which can be overridden are stored in defaults/main.yml file as well as in table below.
Name | Default Value | Description |
---|---|---|
prometheus_version |
2.0.0 | Prometheus package version |
prometheus_config_dir |
/etc/prometheus | Path to directory with prometheus configuration |
prometheus_db_dir |
/var/lib/prometheus | Path to directory with prometheus database |
prometheus_root_dir |
/opt/prometheus | Path to directory with prometheus and promtool binaries |
prometheus_web_listen_address |
"0.0.0.0:9090" | Address on which prometheus will be listening |
prometheus_web_external_url |
"" | External address on which prometheus is available. Useful when behind reverse proxy. Ex. example.org/prometheus |
prometheus_storage_retention |
"30d" | Data retention period |
prometheus_config_flags_extra |
{} | Additional configuration flags passed to prometheus binary at startup |
prometheus_alertmanager_config |
[] | Configuration responsible for pointing where alertmanagers are. This should be specified as list in yaml format. It is compatible with official <alertmanager_config> |
prometheus_global |
{ scrape_interval: 60s, scrape_timeout: 15s, evaluation_interval: 15s } | Prometheus global config. Compatible with official configuration |
prometheus_external_labels |
environment: "{{ ansible_fqdn | default(ansible_host) | default(inventory_hostname) }}" | Provide map of additional labels which will be added to any time series or alerts when communicating with external systems |
prometheus_targets |
{} | Targets which will be scraped. Better example is provided in our demo site |
prometheus_scrape_configs |
defaults/main.yml#L58 | Prometheus scrape jobs provided in same format as in official docs |
prometheus_config_file |
"prometheus.yml.j2" | Variable used to provide custom prometheus configuration file in form of ansible template |
prometheus_alert_rules |
defaults/main.yml#L58 | Full list of alerting rules which will be copied to {{ prometheus_config_dir }}/rules/basic.rules . Alerting rules can be also provided by other files located in {{ prometheus_config_dir }}/rules/ which have *.rules extension |
---
- hosts: all
become: yes
roles:
- cloudalchemy.prometheus
vars:
prometheus_targets:
node:
- targets:
- localhost:9100
- demo.cloudalchemy.org:9100
labels:
env: demosite
We provide demo site for full monitoring solution based on prometheus and grafana. Repository with code and links to running instances is available on github and site is hosted on DigitalOcean.
Alerting rules are defined in prometheus_alert_rules
variable. Format is almost identical to one defined in Prometheus 2.0 documentation.
Due to similarities in templating engines, every templates should be wrapped in {% raw %}
and {% endraw %}
statements. Example is provided in defaults/main.yml file.
The preferred way of locally testing the role is to use Docker and molecule (v1.25). You will have to install Docker on your system. See Get started for a Docker package suitable to for your system. All packages you need to can be specified in one line:
pip install ansible ansible-lint>=3.4.15 molecule==1.25.0 docker testinfra>=1.7.0 jmespath
This should be similiar to one listed in .travis.yml
file in install
section.
After installing test suit you can run test by running
molecule test
For more information about molecule go to their docs.
This project is licensed under MIT License. See LICENSE for more details.