cd /etc/prometheus
sudo nano prometheus
global:
scrape_interval: 10s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['0.0.0.0:9090']
rule_files:
- alert.rules.yml
- less.rules.yml
ubuntu@ip-172-31-23-4:/etc/prometheus$ cat alert.rules.yml
groups:
- name: memory_alerts
rules:
- alert: HighMemoryUsage
expr: (process_resident_memory_bytes / process_virtual_memory_max_bytes) * 100 > 70
for: 5m
labels:
severity: critical
annotations:
summary: "High Memory Usage Detected"
description: "Memory usage is over 70%: {{ $value }}"
ubuntu@ip-172-31-23-4:/etc/prometheus$ cat less.rules.yml
groups:
- name: memory_alerts_less
rules:
- alert: LowMemoryUsage
expr: (process_resident_memory_bytes / process_virtual_memory_max_bytes) * 100 < 70
for: 5m
labels:
severity: warning
annotations:
summary: "Low Memory Usage Detected"
description: "Memory usage is less than 70%: {{ $value }}"
ubuntu@ip-172-31-23-4:/etc/prometheus$
promtool check config prometheus.yml
sudo systemctl restart prometheus