prometheus+grafana+alertmanger


prometheus+grafana+alertmanger - 监控方案入门


监控方案涉及的关键问题

  • 采集数据
  • 存储数据
  • 告警、展示数据

那么基于prometheus的监控方案是用什么技术实现?本文基于docker进行部署,目的以简单的demo快速了解prometheus监控方案的涉及的知识点以及流程。


本文介绍的内容

  • prometheus整体架构介绍
  • 安装prometheus
  • 安装grafana
  • 安装alertmanager
  • grafana关联prometheus
  • prometheus关联alertmanager
  • prometheus定义告警规则
  • alertmanager触发告警


prometheus整体架构


prometheus+grafana+alertmanger - 监控方案入门

从prometheus官方给的架构图分析出,基于prometheus的监控方案常用组件:

  • Exporters :暴露metrics,收集监控指标,并以一种规定的数据格式提供给Prometheus-采集监控对象数据
  • Prometheus Server :收集数据和存储数据到时间序列数据库中,收集的数据由Exporters提供-采集/存储数据
  • Alertmanager :告警管理,接收Prometheus的告警,去重/分组/发出告警(邮件、webhook等)- 告警
  • Grafana:监控Dashbord,UI展示,设置Prometheus Server地址即可自定义监控Dashbord- UI展示
  • Push Gateway: 用于短期的jobs,jobs直接向Prometheus server端推送它们的 metrics.用于服务层面的 metrics


部署组件

本文以docker方式部署:prometheus、grafana、alertmanager


install prometheus

<code>docker run --name prometheus -d -p 9090:9090  quay.io/prometheus/prometheus
# 暴露端口:9090
docker run --name prometheus -d -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml quay.io/prometheus/prometheus
# 挂载prometheus.yml文件,便于在主机上直接修改

docker run --name prometheus -d -p 9090:9090 --link=alertmanger:alertmanger -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -v /etc/prometheus/rules:/etc/prometheus/rules quay.io/prometheus/prometheus
# 挂载挂载prometheus.yml文件,创建了rules目录,rules存放告警规则yaml文件,后续会提到/<code>


install grafana

<code>docker run -d -p 3000:3000 --name=grafana grafana/grafana/<code>


install alertmanger

<code>docker run --name alertmanger -d  -p 9093:9093  -v /etc/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml quay.io/prometheus/alertmanager
#挂载告警文件:alertmanager.yml,便于在主机上直接修改文件/<code>


grafana关联prometheus


prometheus+grafana+alertmanger - 监控方案入门

Prometheus界面,采集promhttp_metric_handler_requests_total为demo进行演示,这个metrics是prometheus自己监控自己的http请求数量


prometheus+grafana+alertmanger - 监控方案入门


  • 访问grafana,默认用户名和密码都是:admin
  • 设置-type选择Prometheus-填写Prometheus访问地址,点击Save&Test 测试关联prometheus是否成功


prometheus+grafana+alertmanger - 监控方案入门

  • 新建dashboard,设置Metrics,即可展示数据

  • prometheus关联alertmanager

    prometheus配置文件路径:/etc/prometheus/prometheus.yaml,在如下配置设置告警地址

    <code>global:
    scrape_interval: 15s
    evaluation_interval: 15s
    # Alertmanager configuration
    alerting:

    alertmanagers:
    - static_configs:
    - targets: ['alertmanger:9093']
    # 关联告警服务器alertmanger
    scrape_configs:
    - job_name: 'prometheus'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
    - targets: ['localhost:9090']
    # prometheus 服务监听的端口/<code>


    查看prometheus-Status-configuration,检测配置是否生效


    prometheus+grafana+alertmanger - 监控方案入门


    prometheus定义告警规则-prom_rules.yml

    <code>groups:
    - name: test-rule
    rules:
    - alert: promReqCounts
    expr: promhttp_metric_handler_requests_total > 10
    for: 0s
    labels:
    prom: http
    annotations:
    summary: High prometheus request total is above 1000/<code>
    • 定义request请求总数大于10就发生告警,标签为:prom:http
    • 定义rules考官网例子:https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/


    在prometheus中关联rule文件 - prom_rules.yml

    <code>global:
    scrape_interval: 15s
    evaluation_interval: 15s

    # Alertmanager configuration
    alerting:
    alertmanagers:
    - static_configs:
    - targets: ['alertmanger:9093']
    # 关联告警服务器alertmanger
    rule_files:
    - "rules/prom_rules.yml"
    # 定义告警规则:prom_rules.yml
    scrape_configs:
    - job_name: 'prometheus'
    # metrics_path defaults to '/metrics'

    # scheme defaults to 'http'.
    static_configs:
    - targets: ['localhost:9090']
    # prometheus 服务监听的端口/<code>


    alertmanager触发告警

    配置alertmanager.yml文件

    <code>global:
    resolve_timeout: 5m

    route:
    group_by: ['alertname']
    group_wait: 10s
    group_interval: 10s
    repeat_interval: 1h
    receiver: 'web.test'
    routes:
    - receiver: 'web.hook'
    match:
    prom: http
    receivers:
    - name: 'web.hook'
    webhook_configs:
    - url: 'http://127.0.0.1:8888'
    - name: 'web.test'
    webhook_configs:
    - url: 'http://127.0.0.1:88888'
    inhibit_rules:
    - source_match:
    severity: 'critical'
    target_match:
    severity: 'warning'
    equal: ['alertname', 'dev', 'instance']/<code>
    • 当alertmanger接收到标签为:prom:http的告警就触发 web.hook,当然也可以发邮件等操作
    • 更多告警参考官网例子:https://prometheus.io/docs/alerting/configuration/


    如果发生了告警,alertmaneger界面会有记录


    prometheus+grafana+alertmanger - 监控方案入门


    参考文档

    • prometheus : https://prometheus.io/docs/prometheus/latest/installation/
    • exporter : https://prometheus.io/docs/instrumenting/exporters/#exporters-and-integrations
    • alertmanger: https://prometheus.io/docs/alerting/alertmanager/
    • prometheus rules : https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/
    • grafana:http://docs.grafana.org/


    原文链接:https://mp.weixin.qq.com/s/H91lLCfUic5yPMEjZOGRWQ

    关于睿云智合

    深圳睿云智合科技有限公司成立于2012年,总部位于深圳,并分别在成都、深圳设立了研发中心,北京、上海设立了分支机构,核心骨干人员全部为来自金融、科技行业知名企业资深业务专家、技术专家。早期专注于为中国金融保险等大型企业提供创新技术、电子商务、CRM等领域专业咨询服务。

    自2016年始,在率先将容器技术引进到中国保险行业客户后,公司组建了专业的容器技术产品研发和实施服务团队,旨在帮助中国金融行业客户将容器创新技术应用于企业信息技术支持业务发展的基础能力改善与提升,成为中国金融保险行业容器技术服务领导品牌。

    此外,凭借多年来在呼叫中心领域的业务经验与技术积累,睿云智合率先在业界推出基于开源软交换平台FreeSwitch的微服务架构多媒体数字化业务平台,将语音、视频、webchat、微信、微博等多种客户接触渠道集成,实现客户统一接入、精准识别、智能路由的CRM策略,并以容器化治理来支持平台的全应用生命周期管理,显著提升了数字化业务处理的灵活、高效、弹性、稳定等特性,为帮助传统企业向“以客户为中心”的数字化业务转型提供完美的一站式整体解决方案。


    分享到:


    相關文章: