prometheus+exporter小测试:
1.golang中使用expoter
import (
  "github.com/prometheus/client_golang/prometheus/promhttp"
)
func main(){
  http.Handle("/metrics", promhttp.Handler())
}
2.访问expoter内的数据
curl -G "http://192.168.0.88:8080/metrics" > text.txt
数据的格式如下:
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.14.6"} 1
也可以访问GZIP格式的数据:
curl -G -H "User-Agent: Prometheus/2.28.1" -H "Accept: application/openmetrics-text; version=0.0.1,text/plain;version=0.0.4;q=0.5,*/*;q=0.1" -H "Accept-Encoding: gzip" -H "X-Prometheus-Scrape-Timeout-Seconds: 10" "http://192.168.0.88:8080/metrics" > 1.txt.gz
gzip -d 1.txt.gz
GZIP方式仍然是文本,但是压缩比很大。测试发现GZIP格式的体积只有文本格式的 15% !
3.源码分析
有几个疑问:存在一个很大的expoter——
1.能不能分段拉取数据?
2.能不能使用二进制格式来缩小体积?
3.会不会在拉取的时候,造成内存暴涨?(在exporter的进程中构造好数据后再发送)
3.1 http handle
client_golang/prometheus/promhttp/http.go
- 入口函数
func Handler() http.Handler {
	return InstrumentMetricHandler(
		prometheus.DefaultRegisterer, HandlerFor(prometheus.DefaultGatherer, HandlerOpts{}),
	)
}
- 在HandlerFor函数中提供处理代码
func HandlerFor(reg prometheus.Gatherer, opts HandlerOpts) http.Handler{
  //...
  h := http.HandlerFunc(func(rsp http.ResponseWriter, req *http.Request) {
     //HTTP回调的主要逻辑
  })
}
- 根据请求header来决定输出什么格式:
		var contentType expfmt.Format
		if opts.EnableOpenMetrics {
			contentType = expfmt.NegotiateIncludingOpenMetrics(req.Header)
		} else {
			contentType = expfmt.Negotiate(req.Header)
		}
- 从代码看来,只有三种格式,且都是文本格式(解释了第二个问题)
func Negotiate(h http.Header) Format {
	for _, ac := range goautoneg.ParseAccept(h.Get(hdrAccept)) {
		ver := ac.Params["version"]
		if ac.Type+"/"+ac.SubType == ProtoType && ac.Params["proto"] == ProtoProtocol {
			switch ac.Params["encoding"] {
			case "delimited":
				return FmtProtoDelim
			case "text":
				return FmtProtoText
			case "compact-text":
				return FmtProtoCompact
			}
		}
		if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") {
			return FmtText
		}
	}
	return FmtText
}
- 输出部分的代码
		for _, mf := range mfs {
			if handleError(enc.Encode(mf)) {
				return
			}
		}
是一边读取一边输出的。
- 解释了第三个问题:不会造成内存暴涨
- 解释了第一个问题:逻辑上不支持分段去拉
展望:
1.尽量不要存在很大的expoter
2.可以把proxy配置到一个很大的expoter上,然后每次拉取只返回一部分metric
3.可以基于树来重新实现expoter的逻辑
prometheus+exporter小测试:的更多相关文章
- 编写一个简单的基于jmespath 的prometheus exporter
		目的很简单,因为系统好多监控指标是通过json 暴露的,并不是标准的prometheus metrics 格式,处理方法 实际上很简单,我们可以基于jsonpath 解析json数据,转换为prome ... 
- Cad 二次开发关于SelectCrossingPolygon和SelectFence返回结果Status为error的小测试
		CAD2008的二次开发,有个很奇怪的现象,只要你选择的点集不在当前视图上SelectCrossingPolygon和SelectFence返回结果Status就会为error,所以要获取正确的结果, ... 
- python 程序小测试
		python 程序小测试 对之前写的程序做简单的小测试 ... # -*- encoding:utf-8 -*- ''' 对所写程序做简单的测试 @author: bpf ''' def GameOv ... 
- PHP中使用PDO操作事务的一些小测试
		关于事务的问题,我们就不多解释了,以后在学习 MySQL 的相关内容时再深入的了解.今天我们主要是对 PDO 中操作事务的一些小测试,或许能发现一些比较好玩的内容. 在 MyISAM 上使用事务会怎么 ... 
- Prometheus exporter的Node exporter是可以独立安装,用来测试的
		现在慢慢在把prometheus operator的一些概念组织完整. https://github.com/coreos/prometheus-operator/tree/master/contri ... 
- 实现一个Prometheus exporter
		Prometheus 官方和社区提供了非常多的exporter,涵盖数据库.中间件.OS.存储.硬件设备等,具体可查看exporters.exporterhub.io,通过这些 exporter 基本 ... 
- HTTP性能小测试
		一直说node.js如何如何好,就来测试一下吧~~ 首先接受一个小工具 Apache Bench简称ab 可以用来测试http性能 利用Apache Bench测试Web引擎性能关于此工具的详细介绍参 ... 
- mysql注入小测试
		转自:http://www.jb51.net/article/46163.htm 在开发网站的时候,出于安全考虑,需要过滤从页面传递过来的字符.通常,用户可以通过以下接口调用数据库的内容:URL地址栏 ... 
- SpringMvc拦截器小测试
		前言 俗话说做项目是让人成长最快的方案,最近小编写项目的时候遇到了一个小问题.小编在项目中所负责的后台系统,但是后台系统是通过系统的页面是通过ifame联动的,那么这时候问题就来了,后台所做的所有操作 ... 
随机推荐
- CF1097B Petr and a Combination Lock 题解
			Content 有一个锁,它只有指针再次指到 \(0\) 刻度处才可以开锁(起始状态如图所示,一圈 \(360\) 度). 以下给出 \(n\) 个操作及每次转动度数,如果可以通过逆时针或顺时针再次转 ... 
- CF1581B Diameter of Graph 题解
			Content \(\textsf{CQXYM}\) 想要构造一个包含 \(n\) 个点和 \(m\) 条边的无向连通图,并且他希望这个图满足下列条件: 该图中不存在重边和自环.也就是说,一条边应该连 ... 
- git 生成ssh
- ajax 有终止请求 abort 那 axios 有没有,怎么实现
			见代码 class View extends Component { constructor(props){ super(props); this.state = { cancel:null, can ... 
- Linux(Centos)内存占用过高处理
			查看内存占用最大 ps aux| grep -v "USER" |sort -n -r -k 4 |awk 'NR==1{ print $0}' 命令查看占用内存最大的10个进程 ... 
- 【LeetCode】1137. N-th Tribonacci Number 解题报告(C++)
			作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetc ... 
- 【LeetCode】611. Valid Triangle Number 解题报告(Python)
			作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/valid-tri ... 
- Codeforces Round #358 (Div. 2) C. Alyona and the Tree
			C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ... 
- Codeforces 777B:Game of Credit Cards(贪心)
			After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ... 
- 【C++】指针初始化
			1.Node * p:if(p)//报错 2.Node * p=NULL;if(p)//不报错 注意把指针初始化,否则指针将指向任意位置 
