William-Yeh.prometheus
william-yeh.prometheus for Ansible Galaxy
Summary
Role name on Ansible Galaxy: william-yeh.prometheus
This Ansible role provides the following features for Prometheus:
- Installs specific versions of the Prometheus server, Node exporter, and Alertmanager.
- Handles restarting, reloading, and stopping services.
- Basic setup configuration (real configurations should be done using user templates; see Usage section below).
This role installs only three core components: Prometheus server, Node exporter, and Alertmanager. For other Prometheus exporters, use the following roles:
- Consul: william-yeh.consul_exporter
- Elasticsearch: william-yeh.es_cluster_exporter
- MongoDB: williamyeh.mongodb_exporter
Support for Ubuntu 12.04 (Precise) and CentOS 6 has ended since November 2018.
Role Variables
Required variables
Specify the components to install:
# Supported components:
#
# [Server components]
# - "prometheus"
# - "alertmanager"
#
# [Exporter components]
# - "node_exporter"
#
prometheus_components
Optional variables: General settings
User-configurable defaults:
# User and group
prometheus_user: prometheus
prometheus_group: prometheus
# Directory for executable files
prometheus_install_path: /opt/prometheus
# Directory for configuration files
prometheus_config_path: /etc/prometheus
# Directory for logs
prometheus_log_path: /var/log/prometheus
# Directory for PID files
prometheus_pid_path: /var/run/prometheus
# Directory for temporary files
prometheus_download_path: /tmp
# Version of helper utility "gosu"
gosu_version: "1.11"
Optional variables: Systemd or not
If the Linux distribution uses systemd, this role will use it. You can disable this (to use traditional SysV-style init scripts) by setting the following variable to false:
prometheus_use_systemd
Optional variables: Prometheus server
User-configurable defaults:
# Which version?
prometheus_version: 2.5.0
# Directory for rule files
prometheus_rule_path: {{ prometheus_config_path }}/rules
# Directory for file_sd files
prometheus_file_sd_config_path: {{ prometheus_config_path }}/tgroups
# Directory for runtime database
prometheus_db_path: /var/lib/prometheus
User-installable configuration files (see doc for details):
# Main configuration template relative to `playbook_dir`;
# to be installed at "{{ prometheus_config_path }}/prometheus.yml"
prometheus_conf_main
User-installable rule files (see doc for details):
# Rule files to be installed at "{{ prometheus_rule_path }}";
# dict fields:
# - key: memo for this rule
# - value:
# - src: file relative to `playbook_dir`
# - dest: target file relative to `{{ prometheus_rule_path }}`
prometheus_rule_files
Alertmanager to be triggered:
prometheus_alertmanager_hostport
Additional command-line arguments, if any (use prometheus --help for the full list):
prometheus_opts
Optional variables: Node exporter
User-configurable defaults:
# Which version?
prometheus_node_exporter_version: 0.16.0
Additional command-line arguments, if any (use node_exporter --help for the full list):
prometheus_node_exporter_opts
Optional variables: Alertmanager
User-configurable defaults:
# Which version?
prometheus_alertmanager_version: 0.15.3
# Directory for runtime database (currently for `silences.json`)
prometheus_alertmanager_db_path: /var/lib/alertmanager
User-installable Alertmanager configuration file (see doc for details):
# Main configuration template relative to `playbook_dir`;
# to be installed at "{{ prometheus_config_path }}/alertmanager.yml"
prometheus_alertmanager_conf
Additional command-line arguments, if any (use alertmanager --help for the full list):
prometheus_alertmanager_opts
Optional: Building from source
(Credit: Robbie Trencheny)
You can optionally download and compile the latest versions from the master branch of Prometheus repositories by setting the respective version to git.
For example, get the latest code for all components by setting all *_version variables to git:
prometheus_version: git
prometheus_node_exporter_version: git
prometheus_alertmanager_version: git
If you'd like to rebuild each time, enable the following variable (default is false):
prometheus_rebuild: true
Handlers
Prometheus server:
restart prometheusreload prometheusstop prometheus
Node exporter:
restart node_exporterreload node_exporter(which acts likerestart)stop node_exporter
Alertmanager:
restart alertmanagerreload alertmanagerstop alertmanager
Usage
Step 1: Add role
Include the role name william-yeh.prometheus in your playbook file.
Step 2: Add variables
Define variables in your playbook file, if necessary.
Simple example:
---
# file: simple-playbook.yml
- hosts: all
become: True
roles:
- william-yeh.prometheus
vars:
prometheus_components: [ "prometheus", "alertmanager" ]
prometheus_alertmanager_hostport: "localhost:9093"
Step 3: Copy user's configuration files, if necessary
More practical example:
---
# file: complex-playbook.yml
- hosts: all
become: True
roles:
- william-yeh.prometheus
vars:
prometheus_components:
- prometheus
- node_exporter
- alertmanager
prometheus_rule_files:
this_is_rule_1_InstanceDown:
src: some/path/basic.rules
dest: basic.rules
prometheus_alertmanager_conf: some/path/alertmanager.yml.j2
Step 4: Browse the default Prometheus pages
Open the page in your browser:
- Prometheus -
http://HOST:9090orhttp://HOST:9090/consoles/node.html - Alertmanager -
http://HOST:9093
Dependencies
None.
Contributors
- William Yeh
- Robbie Trencheny - contributed an early version of building binaries from Go source code.
- Travis Truman - contributed an early version of the consul_exporter installer; now moved to William-Yeh.consul_exporter.
- Musee Ullah
License
MIT License. See the LICENSE file for more details.
ansible-galaxy install William-Yeh.prometheus