prometheus 自定义服务发现的几种实现方法

prometheus 具有强大的生态系统,同时也已经内置了好多服务发现的支持(file,consul,k8s,ec2,dns,openstack,....)

自己开发自定义的服务发现机制

官方提供了参考的说明文档,主要的问题是我们需要修改prometheus 的代码,同时自己进行构建,很多时候我们会失去新特性的支持 
很不灵活

与现有内置的服务发现机制做适配

方法就很多了,我们可以通过api 将需要监控的节点信息写入consul,或者基于文件的服务发现模式写好标准的文件,使用prometheus 内置 
的特性,可以灵活的扩展

使用类似vmagent push 模式的工具

vmagent 是一个很不错的prometheus 周边扩展,可以将pull 模式修改为push,这样我就剋一不用修改prometheus 了,需要做的只是调整agent 
pushgateway 也是一个选择的方案,实际我们可以结合实际使用的工具以及场景,选择不同的工具,vmagent是一个不错的选择,但是如果使用了 
vmagent我们就需要使用一个支持prometheus remote 协议的存储系统了

说明

如果需要进行自定义服务发现的开发,还是比较推荐的基于与内置服务发现适配的模式,这样方便系统的升级以及保持与上游的同步

参考资料

https://prometheus.io/blog/2018/07/05/implementing-custom-sd/#custom-sd-implementation 
https://github.com/prometheus/prometheus/blob/master/prompb/remote.proto 
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write 
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_read 
https://prometheus.io/docs/prometheus/latest/storage/ 
https://github.com/VictoriaMetrics/VictoriaMetrics/wiki/vmagent 
https://github.com/prometheus/pushgateway 
https://github.com/prometheus/prometheus/tree/master/documentation/examples/remote_storage/remote_storage_adapter

原文地址:https://www.cnblogs.com/rongfengliang/p/13517122.html