prometheus几种高可用架构介绍及联邦架构部署

问题背景:单个prometheus性能到达瓶颈问题、多个prometheus-server数据汇总问题等

prometheus监控数据持久化

首先大家都知道prometheus是自带数据存储功能的。
优点是简单易用,基本无需配置
缺点是:1、存在数据无法长久保存(尤其是频繁变更的监控对象,监控对象变化,短时间内监控数据也会随之丢失,如k8s等)
2、基于本地存储的话,Prometheus监控系统扩展比较难
以上缺点可以配置远程存储解决,使用remote_write和remote_read这两个接口,从第三方存储服务中进行监控数据的读写

prometheus集群方案
这里有篇文章介绍了几种prometheus的集群架构,可参考: https://zhuanlan.zhihu.com/p/86763004

方案一:
多个prometheus监控相同的对象。意思就是一台node在被两台或两台以上的prometheus同时监控
缺点:对于被监控端,可能会多出一倍或以上的查询请求
优点:只要有一台prometheus还在运行,就不会影响监控

  方案二:

联邦集群,prometheus数据层层往上汇聚(类似金字塔结构)
优点:数据汇总展示,prometheus-worker压力较小,如合理规划可以分类监控,数据保留更灵活(参考https://zhuanlan.zhihu.com/p/86763004)
缺点:prometheus-primary压力较大,可通过配置文件使不同的prometheus-primary收集不同类的监控数据(参考同上链接)
官网描述: https://prometheus.io/docs/prometheus/latest/federation/

  这里进行方案二+远端存储(influxdb)的集群架构实现

操作:
1、安装prometheus
下载安装包: https://prometheus.io/download/
解压、安装、配置成为系统服务(3台都操作)

  2、安装influxdb(6.127)
yum install即可,因为是做测试,使用默认的配置文件直接启动

create database "prometheus"
create retention policy "prometheus_retention" on "prometheus" duration 4w replication 1 default
show retention policies on prometheus 

创建数据库

  默认数据保留策略为一周,可以新建保留策略

  获取prometheus连接远端存储的一个插件
github地址: https://github.com/prometheus/prometheus/tree/master/documentation/examples/remote_storage/remote_storage_adapter
执行(此插件占用9201端口。注意红框内容,根据自己实际内容进行更改)

nohup ./remote_storage_adapter --influxdb-url=http://127.0.0.1:8086/ --influxdb.database="prometheus" --influxdb.retention-policy=prometheus_retention &

3、修改prometheus-worker的prometheus.yml文件

 

 systemctl直接启动prometheus即可

4、修改prometheus-primary的prometheus.yml文件

联邦集群的核心就在于每一个Prometheus Server都包含一个用于获取当前实例中监控样本的接口/federate,对于prometheus-primary来说,从federate获取数据跟从exporter获取数据没什么区别

math[]:表示你想获取prometheus-worker里哪些job的数据,也可以使用正则匹配
honor_labels:配置true可以确保当采集到的监控指标冲突时,能够自动忽略冲突的监控数据。如果为false时,prometheus会自动将冲突的标签替换为exported_的形式。还可以添加标签以区分不同的监控目标

systemctl启动prometheus
网页输入ip:9090查看

 

 

  5、grafana展示
通过正常的dashboard导入或者自建图表进行数据展示

 参考:https://prometheus.io/docs/prometheus/latest/federation/

原文地址:https://www.cnblogs.com/fat-girl-spring/p/14581694.html