arrow_backAll Posts·5 Min Read·2024-11-02

Alertmanager

PrometheusAlertmanager

A Prometheus exporter converts application or system metrics into a format that Prometheus can scrape. It acts as an adapter between the monitored service and Prometheus.

Grafana Features

  • Visualization: Grafana provides several visualization options that make metrics easier to understand.
  • Alerting: Grafana can send alerts through email, Slack, Telegram, and other notification channels.
<br>
  • Download the Grafana package and place it under /etc.

    bash
    sudo su
    wget https://dl.grafana.com/oss/release/grafana-11.2.2.linux-amd64.tar.gz
    tar -zxvf grafana-v11.2.2.linux-amd64.tar.gz
    cp grafana-v11.2.2.linux-amd64/etc/grafana
    
  • Configure Prometheus to use Alertmanager in /etc/prometheusconfig.yml.

    yaml
    alerting:
      alertmanagers:
        - static_configs:
            - targets:
              - IP_ALERT_MANAGER:PORT
    
  • Define the rule file that Prometheus will use for alerting in etc/prometheus/config.yml.

    yaml
    rule_files:
    - "FILE_RULES.yml"
    
  • Configure Alertmanager's notification destination. This example sends alerts by email. For the full list of supported integrations, see the Prometheus Alertmanager receiver documentation.

    yaml
    global:
      resolve_timeout: 15s
    
    route:
      receiver: email
    
    receivers:
    - name: email
      email_configs:
      - to: "email@test.id"
        from: "email@test.id"
        smarthost: smtp.gmail.com:587
        auth_username: "email@test.id"
        auth_identity: "email@test.id"
        auth_password: "TOKEN_EMAIL"
        send_resolved: True
    
  • Define the rules that trigger Alertmanager notifications. The following example covers a stopped Apache or Nginx web server.

    yaml
    groups:
    - name: NAME_RULES
      rules:
      - alert: NAME_ALERT
        expr: METRICS_UNTUK_ALERT
        for: 1m
        annotations:
          summary: "SUMMARY FOR ALERT"
          description: "DESCRIPTIONS FOR ALERT."
    
  • Create a systemd service so Alertmanager runs in the background.

    bash
    sudo nano /etc/systemd/system/alert_manager.service
    
    bash
    [Unit]
    Description=Alert Manager
    
    [Service]
    User=root
    ExecStart=/etc/alertmanager/alertmanager \
            --config.file=/etc/alertmanager/config.yml \
            --web.external-url=http://IP_SERVER:9093/ \
            --log.level=debug
    
    [Install]
    WantedBy=default.target
    
  • Reload systemd, then start and enable the Alertmanager service.

    bash
    sudo systemctl daemon-reload
    sudo systemctl start alert_manager.service
    sudo systemctl enable alert_manager.service
    sudo systemctl status alert_manager.service