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

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

相关推荐
liuyicenysabel6 小时前
Grafana + Prometheus 分级告警配置设计(P0/P1/P2)
javascript·grafana·prometheus
随遇而安zx6 小时前
SpringCloud---可观测性与监控:Actuator / Micrometer / Prometheus / Grafana 深度解析
spring cloud·grafana·prometheus
qq_452396238 小时前
第四篇:《Prometheus 深度实战:指标设计、Exporter 开发与服务发现》
服务发现·prometheus
刘某的Cloud10 小时前
k8s部署prometheus架构规则
linux·运维·kubernetes·prometheus·监控
LlmCraft|大模型工程实践12 小时前
12. Docker 日志管理与监控:ELK 日志收集 + Prometheus 性能监控
elk·docker·prometheus
DevOps老兵1 天前
AI Infra实战02:GPU监控实战,用DCGM+Prometheus+Grafana看清每一张卡
人工智能·grafana·prometheus·ai infra·gpu监控·dcgm
heimeiyingwang1 天前
【Prometheus·入门篇】数据模型:Metric 类型、标签与时间序列
prometheus
heimeiyingwang1 天前
【Prometheus·部署篇】配置详解:scrape_config、relabeling 与服务发现
prometheus
heimeiyingwang5 天前
【Prometheus·入门篇】Prometheus 是什么:从 Nagios 到云原生监控的演进
prometheus
秋风点枝6 天前
第一篇:认识 Prometheus —— 云原生监控的基础
云原生·prometheus