如何使用alertmanager配置prometheus?

时间:2018-02-01 06:41:29

标签: docker-compose prometheus

搬运工-compose.yml: 这是docker-compose运行prometheus,node-exporter和alert-manager服务。所有服务都运行良好。甚至普罗米修斯目标菜单中的健康状况都显示正常。

version: '2'

services:

    prometheus:
        image: prom/prometheus
        privileged: true
        volumes:
            - ./prometheus.yml:/etc/prometheus/prometheus.yml
            - ./alertmanger/alert.rules:/alert.rules
        command:
            - '--config.file=/etc/prometheus/prometheus.yml'
        ports:
            - '9090:9090'

    node-exporter:
        image: prom/node-exporter
        ports:
            - '9100:9100'

    alertmanager:
        image: prom/alertmanager
        privileged: true
        volumes:
             - ./alertmanager/alertmanager.yml:/alertmanager.yml
        command:
            - '--config.file=/alertmanager.yml'
        ports:
            - '9093:9093'

prometheus.yml

这是带有目标和警报目标集的prometheus配置文件。 alertmanager目标网址工作正常。

global:
  scrape_interval: 5s
  external_labels:
    monitor: 'my-monitor'

# this is where I have simple alert rules
rule_files:
  - ./alertmanager/alert.rules

scrape_configs:
    - job_name: 'prometheus'
      static_configs: 
        - targets: ['localhost:9090']

    - job_name: 'node-exporter'
      static_configs:
        - targets: ['node-exporter:9100']

alerting:
  alertmanagers:
    - static_configs:
      - targets: ['some-ip:9093']

alert.rules: 只需一个简单的警报规则即可在服务停止时显示警报

ALERT service_down
  IF up == 0

alertmanager.yml

这是在发出警报时发送消息。

global:
  slack_api_url: 'https://api.slack.com/apps/A90S3Q753'

    route:
      receiver: 'slack'

    receivers:
      - name: 'slack'
        slack_configs:
          - send_resolved: true
            username: 'tara gurung'
            channel: '#general'
            api_url: 'https://hooks.slack.com/services/T52GRFN3F/B90NMV1U2/QKj1pZu3ZVY0QONyI5sfsdf'

问题: 所有容器都工作正常我无法弄清楚确切的问题。我真的错过了什么。检查prometheus中的警报显示。

警报 没有定义警报规则

enter image description here

1 个答案:

答案 0 :(得分:3)

您的./alertmanager/alert.rules文件未包含在您的docker配置中,因此容器中没有该文件。您需要将它添加到prometheus服务中:

prometheus:
    image: prom/prometheus
    privileged: true
    volumes:
        - ./prometheus.yml:/etc/prometheus/prometheus.yml
        - ./alertmanager/alert.rules:/alertmanager/alert.rules
    command:
        - '--config.file=/etc/prometheus/prometheus.yml'

    ports:
        - '9090:9090'

并且可能在prometheus.yml内提供绝对路径:

rule_files:
- "/alertmanager/alert.rules"

您还需要确保警报规则有效。有关详细信息和示例,请参阅prometheus docs。你alert.rules文件应该是这样的:

groups:
- name: example
  rules:

  # Alert for any instance that is unreachable for >5 minutes.
  - alert: InstanceDown
    expr: up == 0
    for: 5m

一旦有多个文件,最好将整个目录添加为卷而不是单个文件。