Implement Grafana alerting with Prometheus and InfluxDB for comprehensive monitoring

Intermediate 45 min Apr 16, 2026
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up comprehensive Grafana alerting using both Prometheus metrics and InfluxDB time-series data to monitor your infrastructure from multiple data sources. This tutorial covers configuring data sources, creating alert rules, and setting up notification channels for production monitoring.

Prerequisites

  • Grafana server with admin access
  • Prometheus server running on port 9090
  • InfluxDB server with monitoring database
  • SMTP server access for email notifications
  • Basic understanding of time-series monitoring

What this solves

Grafana alerting with multiple data sources provides comprehensive monitoring coverage for your infrastructure. By combining Prometheus metrics with InfluxDB time-series data, you can monitor both application performance and system metrics from a single dashboard with unified alerting rules.

Step-by-step configuration

Install Grafana server

First install Grafana on your system if not already present.

sudo apt update
sudo apt install -y software-properties-common
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install -y grafana
sudo dnf install -y wget
sudo tee /etc/yum.repos.d/grafana.repo <

Configure Grafana service

Enable and start the Grafana service with proper permissions.

sudo systemctl enable --now grafana-server
sudo systemctl status grafana-server

Configure Prometheus data source

Access Grafana at http://your-server:3000 with admin/admin credentials and configure the Prometheus data source.

curl -X POST http://admin:admin@localhost:3000/api/datasources \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Prometheus",
    "type": "prometheus",
    "url": "http://localhost:9090",
    "access": "proxy",
    "isDefault": true
  }'

Configure InfluxDB data source

Add InfluxDB as a secondary data source for time-series monitoring data.

curl -X POST http://admin:admin@localhost:3000/api/datasources \
  -H "Content-Type: application/json" \
  -d '{
    "name": "InfluxDB",
    "type": "influxdb",
    "url": "http://localhost:8086",
    "access": "proxy",
    "database": "monitoring",
    "user": "grafana",
    "password": "secure_password"
  }'

Create InfluxDB authentication

Set up proper authentication for the InfluxDB connection with restricted permissions.

influx -execute "CREATE USER grafana WITH PASSWORD 'secure_password'"
influx -execute "GRANT READ ON monitoring TO grafana"
influx -execute "SHOW USERS"

Configure notification channels

Set up email notifications for alert delivery using SMTP configuration.

[smtp]
enabled = true
host = smtp.example.com:587
user = alerts@example.com
password = smtp_password
skip_verify = false
from_address = alerts@example.com
from_name = Grafana Alerts

[alerting]
enabled = true
execute_alerts = true

Restart Grafana with new configuration

Apply the SMTP configuration changes by restarting the service.

sudo systemctl restart grafana-server
sudo systemctl status grafana-server

Create Slack notification channel

Add Slack integration for real-time alert notifications to your team channels.

curl -X POST http://admin:admin@localhost:3000/api/alert-notifications \
  -H "Content-Type: application/json" \
  -d '{
    "name": "slack-alerts",
    "type": "slack",
    "settings": {
      "url": "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK",
      "channel": "#alerts",
      "title": "Grafana Alert",
      "text": "{{ range .Alerts }}{{ .Annotations.summary }}{{ end }}"
    }
  }'

Create email notification channel

Configure email notifications as a backup delivery method for critical alerts.

curl -X POST http://admin:admin@localhost:3000/api/alert-notifications \
  -H "Content-Type: application/json" \
  -d '{
    "name": "email-alerts",
    "type": "email",
    "settings": {
      "addresses": "ops-team@example.com;sre-team@example.com",
      "subject": "[ALERT] {{ .GroupLabels.alertname }}"
    }
  }'

Create Prometheus CPU alert rule

Set up a CPU usage alert using Prometheus metrics with proper thresholds.

curl -X POST http://admin:admin@localhost:3000/api/ruler/grafana/api/v1/rules/alerts \
  -H "Content-Type: application/json" \
  -d '{
    "groups": [
      {
        "name": "cpu-alerts",
        "folder": "alerts",
        "rules": [
          {
            "uid": "cpu-high",
            "title": "High CPU Usage",
            "condition": "A",
            "data": [
              {
                "refId": "A",
                "queryType": "",
                "relativeTimeRange": {
                  "from": 300,
                  "to": 0
                },
                "datasourceUid": "prometheus-uid",
                "model": {
                  "expr": "100 - (avg(irate(node_cpu_seconds_total{mode=\"idle\"}[5m])) * 100)",
                  "interval": "",
                  "refId": "A"
                }
              }
            ],
            "noDataState": "NoData",
            "execErrState": "Alerting",
            "for": "5m",
            "annotations": {
              "summary": "CPU usage is above 80% for 5 minutes"
            },
            "labels": {
              "severity": "warning"
            }
          }
        ]
      }
    ]
  }'

Create InfluxDB memory alert rule

Configure a memory usage alert using InfluxDB data for system monitoring.

curl -X POST http://admin:admin@localhost:3000/api/ruler/grafana/api/v1/rules/alerts \
  -H "Content-Type: application/json" \
  -d '{
    "groups": [
      {
        "name": "memory-alerts",
        "folder": "alerts",
        "rules": [
          {
            "uid": "memory-high",
            "title": "High Memory Usage",
            "condition": "A",
            "data": [
              {
                "refId": "A",
                "queryType": "",
                "relativeTimeRange": {
                  "from": 300,
                  "to": 0
                },
                "datasourceUid": "influxdb-uid",
                "model": {
                  "query": "SELECT mean(\"used_percent\") FROM \"mem\" WHERE time >= now() - 5m GROUP BY time(1m)",
                  "refId": "A"
                }
              }
            ],
            "noDataState": "NoData",
            "execErrState": "Alerting",
            "for": "3m",
            "annotations": {
              "summary": "Memory usage is above 90% for 3 minutes"
            },
            "labels": {
              "severity": "critical"
            }
          }
        ]
      }
    ]
  }'

Create disk space alert with multi-source data

Combine Prometheus and InfluxDB data for comprehensive disk monitoring alerts.

curl -X POST http://admin:admin@localhost:3000/api/ruler/grafana/api/v1/rules/alerts \
  -H "Content-Type: application/json" \
  -d '{
    "groups": [
      {
        "name": "disk-alerts",
        "folder": "alerts",
        "rules": [
          {
            "uid": "disk-space-low",
            "title": "Low Disk Space",
            "condition": "C",
            "data": [
              {
                "refId": "A",
                "queryType": "",
                "relativeTimeRange": {
                  "from": 300,
                  "to": 0
                },
                "datasourceUid": "prometheus-uid",
                "model": {
                  "expr": "100 - ((node_filesystem_avail_bytes{mountpoint=\"/\"} * 100) / node_filesystem_size_bytes{mountpoint=\"/\"})",
                  "refId": "A"
                }
              },
              {
                "refId": "B",
                "queryType": "",
                "relativeTimeRange": {
                  "from": 300,
                  "to": 0
                },
                "datasourceUid": "influxdb-uid",
                "model": {
                  "query": "SELECT mean(\"used_percent\") FROM \"disk\" WHERE \"path\" = '/' AND time >= now() - 5m",
                  "refId": "B"
                }
              },
              {
                "refId": "C",
                "queryType": "",
                "expression": "$A > 85 OR $B > 85",
                "conditions": [
                  {
                    "evaluator": {
                      "params": [85],
                      "type": "gt"
                    },
                    "operator": {
                      "type": "and"
                    },
                    "query": {
                      "params": ["A"]
                    },
                    "reducer": {
                      "type": "last"
                    },
                    "type": "query"
                  }
                ]
              }
            ],
            "noDataState": "NoData",
            "execErrState": "Alerting",
            "for": "2m",
            "annotations": {
              "summary": "Disk space usage is above 85% on root filesystem"
            },
            "labels": {
              "severity": "warning"
            }
          }
        ]
      }
    ]
  }'

Configure alert routing and policies

Set up alert routing based on severity levels and notification preferences.

apiVersion: 1
policies:
  - orgId: 1
    receiver: default-receiver
    group_by:
      - alertname
      - severity
    routes:
      - receiver: slack-critical
        matchers:
          - severity = critical
        group_wait: 30s
        group_interval: 5m
        repeat_interval: 1h
      - receiver: email-warning
        matchers:
          - severity = warning
        group_wait: 1m
        group_interval: 10m
        repeat_interval: 4h
      - receiver: slack-info
        matchers:
          - severity = info
        group_wait: 5m
        group_interval: 30m
        repeat_interval: 12h

Set correct permissions for alerting configuration

Ensure Grafana can read the alerting configuration files with proper ownership.

sudo mkdir -p /etc/grafana/provisioning/alerting
sudo chown -R grafana:grafana /etc/grafana/provisioning
sudo chmod 755 /etc/grafana/provisioning/alerting
sudo chmod 644 /etc/grafana/provisioning/alerting/policies.yaml
Never use chmod 777. It gives every user on the system full access to your files. Instead, use appropriate ownership with chown and minimal permissions like 644 for files and 755 for directories.

Test alert configuration

Validate your alerting setup by testing notification delivery and rule evaluation.

sudo systemctl restart grafana-server
curl -X POST http://admin:admin@localhost:3000/api/ruler/grafana/api/v1/rules/test \
  -H "Content-Type: application/json" \
  -d '{
    "expr": "up == 0",
    "datasourceUid": "prometheus-uid"
  }'

Configure advanced alert features

Set up alert silencing

Configure maintenance windows and alert silencing for planned downtime.

curl -X POST http://admin:admin@localhost:3000/api/alertmanager/grafana/api/v2/silences \
  -H "Content-Type: application/json" \
  -d '{
    "matchers": [
      {
        "name": "instance",
        "value": "203.0.113.10:9100",
        "isRegex": false
      }
    ],
    "startsAt": "2024-01-01T02:00:00.000Z",
    "endsAt": "2024-01-01T06:00:00.000Z",
    "createdBy": "admin",
    "comment": "Maintenance window for server updates"
  }'

Configure alert annotations

Add detailed annotations to alerts for better troubleshooting context.

apiVersion: 1
groups:
  - name: detailed-alerts
    folder: monitoring
    rules:
      - uid: service-down
        title: Service Down Alert
        condition: A
        data:
          - refId: A
            queryType: ''
            relativeTimeRange:
              from: 300
              to: 0
            datasourceUid: prometheus-uid
            model:
              expr: up{job="node-exporter"} == 0
        annotations:
          summary: "Service {{ $labels.instance }} is down"
          description: "The service on {{ $labels.instance }} has been down for more than 5 minutes. Check the service status and logs."
          runbook_url: "https://wiki.example.com/runbooks/service-down"
          dashboard_url: "https://grafana.example.com/d/node-exporter/node-exporter-full"
        labels:
          team: infrastructure
          service: node-exporter

Verify your setup

sudo systemctl status grafana-server
curl -s http://localhost:3000/api/health | jq
curl -s http://admin:admin@localhost:3000/api/datasources | jq '.[].name'
curl -s http://admin:admin@localhost:3000/api/alert-notifications | jq '.[].name'
curl -s http://admin:admin@localhost:3000/api/ruler/grafana/api/v1/rules | jq '.groups[].name'

Check Prometheus metrics collection:

curl -s "http://localhost:9090/api/v1/query?query=up" | jq '.data.result[] | .metric.instance'
curl -s "http://localhost:9090/api/v1/targets" | jq '.data.activeTargets[] | select(.health=="up") | .labels.instance'

Verify InfluxDB connectivity and data:

influx -execute "SHOW DATABASES"
influx -database monitoring -execute "SHOW MEASUREMENTS LIMIT 5"
influx -database monitoring -execute "SELECT * FROM cpu WHERE time > now() - 1h LIMIT 3"

Common issues

Symptom Cause Fix
Data source connection failed Incorrect URL or authentication Verify service URLs and credentials: curl http://localhost:9090/metrics
Alert rules not evaluating Invalid query syntax or missing data Test queries in Explore tab: curl -X POST /api/ruler/grafana/api/v1/rules/test
Notifications not delivered SMTP misconfiguration or wrong webhook URL Check logs: sudo journalctl -u grafana-server -f and test SMTP settings
Permission denied on config files Wrong ownership or permissions Fix ownership: sudo chown -R grafana:grafana /etc/grafana/
High memory usage in Grafana Too many concurrent queries Limit concurrent queries in /etc/grafana/grafana.ini: max_concurrent_queries = 20

Next steps

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.