Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/filipe-oliveiraa/ansible_playbook_grafana_prometheus
This project provides an automated setup for deploying Grafana and Prometheus using an Ansible playbook. It configures monitoring, visualization, and alerting through customizable dashboards and notification channels.
https://github.com/filipe-oliveiraa/ansible_playbook_grafana_prometheus
ansible-playbook docker grafana metrics monitoring prometheus webhook
Last synced: about 11 hours ago
JSON representation
This project provides an automated setup for deploying Grafana and Prometheus using an Ansible playbook. It configures monitoring, visualization, and alerting through customizable dashboards and notification channels.
- Host: GitHub
- URL: https://github.com/filipe-oliveiraa/ansible_playbook_grafana_prometheus
- Owner: filipe-oliveiraa
- Created: 2025-02-02T17:37:09.000Z (3 days ago)
- Default Branch: main
- Last Pushed: 2025-02-02T17:37:21.000Z (3 days ago)
- Last Synced: 2025-02-02T19:18:49.593Z (3 days ago)
- Topics: ansible-playbook, docker, grafana, metrics, monitoring, prometheus, webhook
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Grafana and Prometheus Deployment with Ansible
This project provides an automated setup for deploying Grafana and Prometheus using an Ansible playbook. It configures monitoring, visualization, and alerting through customizable dashboards and notification channels.
---
## **Prerequisites**
- Docker installed on the target machine.
- Ansible installed locally.
- Access to encrypted secrets stored in an Ansible Vault (`secret.yml`).
- Basic understanding of network configurations (e.g., local IP).---
## **Project Overview**
| File | Description |
| ------------------------------- | --------------------------------------------------------------------------------- |
| `deploy_grafana_prometheus.yml` | Main Ansible playbook to deploy Grafana and Prometheus. |
| `alert_rules.yml` | Defines alerts for Prometheus exceeding 1 GB of virtual memory usage. |
| `alert_rules_grafana.yml` | Defines alerts for Grafana exceeding 1 GB of virtual memory usage. |
| `discord_contact_point.yml` | Configures a Discord notification channel for alerts. |
| `email_contact_point.yml` | Configures an email notification channel for alerts. |
| `grafana.ini` | Configuration file for Grafana, including email notifications (requires editing). |
| `grafana_dashboard_config.yml` | Configures the dashboard layout for memory visualization. |
| `grafana_ds.yml` | Adds data sources to Grafana (e.g., Prometheus). |
| `memory_dashboard.json` | Configuration for Grafana’s virtual memory visualization dashboard. |
| `prometheus.yml` | Defines Prometheus scrape targets (Grafana and Prometheus itself). |
| `hosts` | Specifies that the playbook will run on the local machine. |---
## **Setup Instructions**
### **Step 1: Modify Configuration Files**
1. **Grafana Email Notification:**
- Update `grafana.ini` with your email address and credentials.
- Use encrypted credentials (e.g., via Ansible Vault).2. **Alert Rules:**
- Update `alert_rules.yml` and `alert_rules_grafana.yml` with your preferred notification contact points.
3. **Secrets Management:**
- Create a `secret.yml` file containing your desired Grafana admin password.
- Encrypt `secret.yml` using Ansible Vault:
```bash
ansible-vault encrypt secret.yml
```4. **Local IP Configuration:**
- Edit `grafana_ds.yml` to set the correct URL for your local Prometheus instance (e.g., `localhost:9090`).
5. **Notification Channels:**
- Update `email_contact_point.yml` and `discord_contact_point.yml` with appropriate email addresses and Discord webhook URLs.
---
### **Step 2: Run the Deployment**
1. **Stop and Remove Existing Containers:**
```bash
docker stop grafana prometheus
docker rm grafana prometheus
```2. **Execute the Playbook:**
Run the following command to deploy Grafana and Prometheus:```bash
ansible-playbook -i hosts deploy_grafana_prometheus.yml --ask-become-pass --ask-vault-pass
```- `--ask-become-pass`: Prompts for the sudo password on the target machine.
- `--ask-vault-pass`: Prompts for the Ansible Vault password to decrypt `secret.yml`.---
## **Project Components**
### **Alert Rules**
- `alert_rules.yml`: Alerts when Prometheus exceeds 1 GB of virtual memory usage.
- `alert_rules_grafana.yml`: Alerts when Grafana exceeds 1 GB of virtual memory usage.### **Data Sources**
- `grafana_ds.yml`: Configures Prometheus as the data source for Grafana.
### **Dashboards**
- `memory_dashboard.json`: Visualization of virtual memory usage for Grafana and Prometheus.
- `grafana_dashboard_config.yml`: Mounts the dashboard configuration to `/var/lib/grafana/dashboards`.### **Notification Channels**
- `email_contact_point.yml`: Configures email notifications.
- `discord_contact_point.yml`: Configures Discord notifications.---
## **Useful Commands**
- **Stop and Remove Containers:**
```bash
docker stop grafana prometheus
docker rm grafana prometheus
```- **Run Playbook:**
```bash
ansible-playbook -i hosts deploy_grafana_prometheus.yml --ask-become-pass --ask-vault-pass
```- **Encrypt Secrets:**
```bash
ansible-vault encrypt secret.yml
```- **Decrypt Secrets:**
```bash
ansible-vault decrypt secret.yml
```---
## **Monitoring URLs**
- **Prometheus Targets:** [http://localhost:9090/targets](http://localhost:9090/targets)\
Use this URL to verify that Prometheus is monitoring its targets correctly.- **Grafana Login:** [http://localhost:3000/login](http://localhost:3000/login)\
Use this URL to log in to Grafana and access the dashboards.---