目前开源的告警系统不少,选择Prometheus主要因为,它比较轻便、支持复杂的规则运算、规则的动态加载、组件之间的耦合度低(都是通过http协议交互)、而且生态圈完善。

prometheus主要应用于告警业务,常用的组件有prometheus、pushgateway、alertmanager。

  • prometheus组件:用于根据所配置的规则进行规则运算,当存在规则触发时,将告警信息发送给alertmanager。
  • pushgateway组件:数据网关,prometheus的数据源,
  • alertmanager组件:用于发送告警(短信、邮件等)
源码编译及安装

相关程序下载

下载安装Git:yum install -y git

下载GO

版本:go1.6.2.linux-386.tar.gz,根据系统选择版本
下载地址:http://www.golangtc.com/download

下载依赖:
yum install -y gcc mercurial


环境变量设置

prometheus 基于nacos动态发现目标 prometheus源码分析_prometheus


编译启动

mkdir -p GOPATH/src/github.com/prometheus
cd GOPATH/src/github.com/prometheus
git clone https://github.com/prometheus/prometheus.git
cd prometheus
// 开始编译
make build  
// 编译完成启动prometheus 命令
./prometheus -config.file=your_config.yml

说明:alertmanager、pushgateway组件源码的编译与Prometheus类型(make build)


命令行参数说明

prometheus

  1. -version 查看版本信息
  2. -config.file “prometheus.yml” 指定加载的配置文件,默认当前路径下prometheus.yml
  3. -alertmanager.notification-queue-capacity 10000 告警队列大小,默认值为10000
  4. -alertmanager.timeout 10s 通过HTTP接口发送告警到AlertManager的超时时间,默认为10s
  5. -alertmanager.url 指定alertmanager的地址
  6. -query.max-concurrency 20 最大并发查询连接个数,默认为20
  7. -query.timeout 2m0s 查询超时时间,默认2分钟
  8. -query.staleness-delta 5m0s 这个参数很重要,当没有scrape到指标是,使用上次(最近一次)指标值进行补,该值设置距上次指标的时间间隔,默认为5分钟,操作5分针就补空值。
  9. STORAGE命令参数主要用于设置指标存储的方式,目前prometheus支持opentsdb、influxdb、local三种
  10. -web.listen-address “:9090” 指定外部请求的访问地址,默认为本地的9090端口。

性能测试


测试机器数量:1台(非独立)

  • 规则运算不指定维度
  • prometheus 基于nacos动态发现目标 prometheus源码分析_源码_02

  • 规则运算指定维度
  • prometheus 基于nacos动态发现目标 prometheus源码分析_开源_03