🚀 Grafana Alerting Setup with SMTP (Google) 📩
1️⃣ Configure SMTP for Email Notifications 📧
To enable email alerts in Grafana, we need to configure SMTP settings using Gmail.
🔹 Step 1: Generate App Password
- Go to Google App Passwords.
- Create a new app password with the name: Grafana SMTP.
- Copy the generated password (Example:
tnlh tvbp chmh bfcl
).
🔹 Step 2: Update Grafana Configuration
Edit the Grafana configuration file:
sudo vi /etc/grafana/grafana.ini
Modify the SMTP section:
[smtp]
enabled = true
host = smtp.gmail.com:587
user = [email protected]
password = tnlh tvbp chmh bfcl
from_address = [email protected]
from_name = Grafana Alerts
skip_verify = false
Save and restart Grafana:
sudo systemctl restart grafana-server
2️⃣ Create Contact Points 📨
- Navigate to Menu → Contact Points.
- Click Create New Contact Point.
- Add Gmail addresses (comma-separated):
- Save the contact points.
3️⃣ Set Up Alert Rules 🚨
🔥 CPU Usage Alert 🚀
Expression:
100 - (avg by (instance) (rate(node_cpu_seconds_total{instance="Prod: Portfolio", mode="idle"}[1m])) * 100)
Threshold:
IS ABOVE: 60%
Folder:
📂 Portfolio
Evaluation Behavior:
- Name:
EC2_CPU_Usage_Evaluation
- Evaluation Interval:
5 min
- Pending Period:
1 min
Notification Message:
📌 Summary: High CPU usage on Prod: Portfolio
📝 Description: CPU usage is above 60% for more than 1 minute.
💾 Disk Usage Alert ⚠️
Expression:
100 * (1 - (node_filesystem_avail_bytes{instance="Prod: Portfolio", mountpoint="/"} / node_filesystem_size_bytes{instance="Prod: Portfolio", mountpoint="/"}))
Threshold:
IS ABOVE: 70%
Folder:
📂 Portfolio
Evaluation Behavior:
- Name:
EC2_Disk_Usage_Evaluation
- Evaluation Interval:
1 min
- Pending Period:
1 min
Notification Message:
📌 Summary: High disk usage on Prod: Portfolio
📝 Description: Disk usage is above 70% on Portfolio EC2.
🧠 Memory Usage Alert ⚡
Expression:
(avg by (instance) ((node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes{instance="Prod: Portfolio"}) / node_memory_MemTotal_bytes) * 100)
Threshold:
IS ABOVE: 60%
Folder:
📂 Portfolio
Evaluation Behavior:
- Name:
EC2_Memory_Usage_Evaluation
- Evaluation Interval:
1 min
Notification Message:
📌 Summary: High memory usage on Prod: Portfolio
📝 Description: Memory usage is above 60%.
🎉 Now your Grafana alerts are set up and ready to notify you in case of high CPU, Disk, or Memory usage! 🚀