Ansible role for installing Grafana, Prometheus and node_exporter
Tests • Variables • Usage • Use it on Raspberry Pi • Credits • License
The role was tested in the following distributions using docker images.
| Distribution | Tested |
|---|---|
| Debian 9 Stretch | ✅ |
| Ubuntu 16.04 Xenial Xerus | ✅ |
| Ubuntu 18.04 Bionic Beaver | ✅ |
You can run the tests from the root directory using the following command.
distro=<distro> tests/runtests.sh
# <distro> is one of { debian9, ubuntu16 } (debian9 is the default one)| Variable | Default | Description |
|---|---|---|
| components | [] | Services to install. Possible values: { prometheus, node_exporter, grafana } |
Inventory example:
[master]
halcyon1 ansible_connection=local
[workers]
halcyon2
[cluster:children]
master
workersThe last group is important because we need to tell Prometheus from where it should gather the metrics exported by node_exporter.
Then, you can use the provided playbooks in tests to install, start and stop the services.
---
#
# file: tests/monitoring_install.yml
#
- hosts: master
become: True
roles:
- monitoring
vars:
components:
- prometheus
- node_exporter
- grafana
- hosts: workers
become: True
roles:
- monitoring
vars:
components:
- node_exporterAs you can see, one node of the cluster will host Prometheus and Grafana, while the metrics will be gathered from all the nodes in the cluster.
ansible-playbook monitoring_install.ymlKeep in mind that the previous playbook doesn't start the services. This one does:
ansible-playbook monitoring_start.ymlYou should be able to access Grafana and Prometheus using the browser. The installation includes two Grafana dashboards to check the status of the cluster and the individual nodes.
I've successfully used this role in a Raspberry Pi 3 cluster with a few changes in defaults/main.yml.
First, update the variable prometheus_platform_suffix to armv7. Then, update the variables grafana_apt_key and grafana_apt_repo since you need to use an unofficial repository to install the latest Grafana version. You can find the official repos and keys at Installing Grafana.
Just add the following modification to defaults/main.yml.
#grafana_apt_key: https://packagecloud.io/gpg.key
#grafana_apt_repo: deb https://packagecloud.io/grafana/stable/debian/ jessie main
# Use these one instead if you want to install it on Raspberry Pi 3
grafana_apt_key: https://bintray.com/user/downloadSubjectPublicKey?username=bintray
grafana_apt_repo: deb https://dl.bintray.com/fg2it/deb jessie mainI've been inspired by the following open source projects:
This project is licensed under the MIT License - see the LICENSE file for details.

