Home grafana-prometheus-loki-and-ansible
Post
Cancel

grafana-prometheus-loki-and-ansible

Grafana, Promtail, Loki, and Nginx all automated with Ansible

Youtube video: Youtube
Github Link: GitHub

This was only tested for ubuntu on x64 and ARM raspberry Pi’s, if you want more then ubuntu please feel free to contribute to the repo.

My motivation

I wanted to create a monitoring setup where deployment could be automated and easily repeatable.

For my metrics scraping, I’m using Prometheus & for log ingestion I am using Loki. For data visualization I am using Grafana.

To try and keep my logs and metrics private I have enabled HTTPs and basic authentication on all of my endpoints.

The end result is going to look something like this:

Setting the configuration

Clone my repo:

1
git clone https://github.com/aidanhall34/ansiblenodemonitoring.git

After cloning the repo, copy inventrories/production/ubuntu.yml.example to inventrories/production/ubuntu.yml and update the contents.

Update the hosts file in inventories/production/hosts to include all of the machines you want to configuring monitoring on.
Next update the Prometheus config located at monitoring/templates/prometheus/prometheus.yml.j2. Docs on how to configure Prometheus can be found here:
prometheus.io
Now we will update the SNMP config. If you use Mikrotik routers with SNMP v3 you can use the existing config. If not you will need to generate one with this tool: github.com/snmp_exporter/generator.
Place your SNMP config at monitoring/templates/snmp_exporter/snmp.yml.j2.
If you want more overview into your configuration, I’d suggest checking out the monitoring/templates/ and monitoring/files/ directories for other configuration files.

Running the playbooks

Now you are ready to run the playbooks. Ensure you have ansible installed on your machine then run:

1
2
3
4
# Run this on the monitoring server
ansible-playbook playbooks/deploy_monitoring.yml  -i inventories/production/ --tags server --limit 'mon-vm-01.inf.ah34.net'
# Run this on all machines except for the monitoring server
ansible-playbook playbooks/deploy_monitoring.yml  -i inventories/production/ --tags agent --limit 'ubuntu:!mon-vm-01.inf.ah34.net'

You should now be able to reach grafana at the monitoring servers IP address on port 443.

This post is licensed under CC BY 4.0 by the author.