Page cover
githubEdit

Prometheus alert rules

Set alert rules for prometheus

Steps:

  1. Go to the path:

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
  1. Make a yml file for high memory alerts: alert.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 }}"
  1. Make a yml file for less memory alerts: less.rules.yml

  1. Verify the Configuration

  1. Restart the Prometheus service:

  1. Now check on your prometheusip:9090. (Default port of prometheus is 9090).

  • Check on alerts you can get alerts which alerts rule is firing.

Last updated