携带时间戳主动写入数据到prometheus service(可乱序、go)

使用到的github公开项目

https://github.com/castai/promwrite

Prometheus版本2.45.0

拉下来装依赖,然后使用

client_test.go

t.Run("write with custom options", func(t *testing.T)

这个测试用例里面,删掉srv初始化的部分,这个是模拟一个客户端,直接写入自己的普罗米修斯测试的客户端路径,/api/v1/write普罗米修斯是写入的路径,普罗米修斯启动参数要加 --web.enable-remote-write-receiver

go 复制代码
client := promwrite.NewClient(
			//srv.URL,
			"http://localhost:9090/api/v1/write",
			promwrite.HttpClient(&http.Client{
				Timeout: 1 * time.Second,
				Transport: &customTestHttpClientTransport{
					reqChan: sentRequest,
					next:    http.DefaultTransport,
				},
			}),
		)

效果


注意:

普罗米修斯对写操作有限制,所以要按时间顺序写入(可以开启乱序写入,新版才有功能)

expected status 200, got 400: out of order sample

这个错误通常是由于 Prometheus 写入数据时样本的时间戳顺序不正确导致的。Prometheus 要求样本的时间戳必须按照递增的顺序进行写入

参考下面这个处理方式进行乱序写入配置

expected status 200, got 500: too old sample

配置的可以乱序写时间不够长导致

处理方式:

对应关系

storage:

tsdb:

out_of_order_time_window: 86400s

配置一天,可以往前一天写入,以此类推,影响性能

https://docs.google.com/document/d/1Kppm7qL9C-BJB1j6yb6-9ObG3AbdZnFUBYPNNWwDBYM/edit

promwrite: expected status 200, got 400: out of bounds

写入时间不在允许范围内,参考乱序写入配置,调整

相关推荐
运维成长记4 天前
云原生监控系统 Prometheus大总结 20250909
云原生·prometheus
_何同学4 天前
Spring Boot 监控实战:集成 Prometheus 与 Grafana,打造全方位监控体系
spring boot·grafana·prometheus
g66x6 天前
自建prometheus监控腾讯云k8s集群
kubernetes·腾讯云·prometheus
苦逼IT运维7 天前
Jenkins 监控方案:Prometheus + Grafana 实践
jenkins·grafana·prometheus
迦蓝叶8 天前
JAiRouter 配置文件重构纪实 ——基于单一职责原则的模块化拆分与内聚性提升
java·网关·ai·重构·openai·prometheus·单一职责原则
会飞的小蛮猪9 天前
Jenkins运维之路(权限分配&忘记admin密码)
java·运维·经验分享·jenkins·prometheus
川石课堂软件测试9 天前
Oracle 数据库:视图与索引
数据库·网络协议·nginx·http·oracle·grafana·prometheus
川石课堂软件测试10 天前
Oracle 数据库如何查询列
linux·数据库·sql·功能测试·oracle·grafana·prometheus
川石课堂软件测试10 天前
Oracle 数据库使用事务确保数据的安全
数据库·python·功能测试·docker·oracle·单元测试·prometheus
文人sec13 天前
性能测试-jmeter7-元件提取器
python·jmeter·prometheus·模块测试