携带时间戳主动写入数据到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

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

相关推荐
EterNity_TiMe_9 小时前
别让告警变成噪音:用Prometheus和Alertmanager搭一套可远程查看的监控系统
数据库·人工智能·ai·postgresql·prometheus·cpolar
Elastic 中国社区官方博客11 小时前
使用 Elasticsearch 作为 Grafana 的直接替代 Prometheus 后端
大数据·数据库·sql·elasticsearch·搜索引擎·grafana·prometheus
spider_xcxc1 天前
Prometheus + Grafana流程搭建总结
grafana·prometheus·云计算运维
c_zyer2 天前
一站式可观测新选择:OpenObserve 深度对标 ELK / Grafana+Prometheus / Netdata,附Docker一键部署实战
elk·grafana·prometheus·netdata·openobserve
Waay3 天前
面试口述版:个人对 Prometheus 完整理解
运维·学习·云原生·面试·职场和发展·kubernetes·prometheus
qq_349447953 天前
十二、k8s中prometheus配置文件如何热加载
容器·kubernetes·prometheus
孫治AllenSun3 天前
【Prometheus & Grafana】搭建可视化监控平台
grafana·prometheus
chen_ke_hao4 天前
Prometheus + Grafana监控平台-显卡集群监控
grafana·prometheus
SRETalk13 天前
Zabbix、Prometheus、Grafana、Nightingale,四个监控如何选型?
zabbix·grafana·prometheus·nightingale
虚无境21 天前
如何编写一个SpringBoot项目告警推送的Starter
java·prometheus·webhook