prometheus之docker监控与告警系列(二)

本系列主要介绍prometheus+cadvisor+alertmanager打造docker监控,主要监控指定docker容器是否挂掉

本节主要熟悉prometheus+Alertmanager的部署和基本使用

一、说明

prometheus本身并没有集成告警功能,需要配合Alertmanager使用

二、下载并安装Alertmanager

进入下载页,操作系统选择darwin

https://prometheus.io/download/

往下拉,看到alertmanager

《prometheus之docker监控与告警系列(二)》 alertmanager.png

三、配置Prometheus,使其可以与Alertmanager通信

# Alertmanager配置
alerting:
 alertmanagers:
 - static_configs:
   - targets: ["localhost:9093"] # 设定alertmanager和prometheus交互的接口,即alertmanager监听的ip地址和端口

四、添加prometheus.rules.yml,配置Prometheus规则,实例down掉触发alert

groups:
- name: Instances
  rules:
  - alert: InstanceDown
    expr: up == 0
    for: 5s
    labels:
      severity: page
    # Prometheus templates apply here in the annotation and label fields of the alert.
    annotations:
      description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 s.'
      summary: 'Instance {{ $labels.instance }} down'

为prometheus指定规则文件

rule_files:
  - 'prometheus.rules.yml'

五、编辑alertmanager.yml,配置webhook_config,即告警触发的接口调用

global:
  resolve_timeout: 5m

route:
  group_by: ['alertname']
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 1h
  receiver: 'web.hook'
receivers:
- name: 'web.hook'
  webhook_configs:
  - url: 'http://localhost:5200/auth/instanceDown'

启动Alertmanager

./alertmanager –config.file=alertmanager.yml

启动Prometheus

./prometheus –config.file=prometheus.yml

上一篇起的任意一个进程关闭,比如 http://localhost:8080

http://localhost:9090/alerts 查看告警

欢迎继续阅读:

prometheus之docker监控与告警系列(一)

prometheus之docker监控与告警系列(三)

    原文作者:2远
    原文地址: https://www.jianshu.com/p/2305526bdfdd
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞