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

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

相关推荐
KK溜了溜了18 小时前
Prometheus配置监控项和告警规则
linux·grafana·prometheus
Devin~Y20 小时前
大厂Java面试实录:Spring Boot微服务 + Redis/Kafka + Prometheus/Jaeger + RAG/Agent(小Y水货版)
java·spring boot·redis·spring cloud·kafka·prometheus·jaeger
Elastic 中国社区官方博客21 小时前
为 Elasticsearch 带来火力:增加原生 Prometheus API 支持
大数据·数据库·elasticsearch·搜索引擎·信息可视化·prometheus
Dovis(誓平步青云)2 天前
《如何通过prometheus-webhook-dingtalk解决 Alertmanager 原生不支持钉钉 Webhook问题》
人工智能·生成对抗网络·钉钉·运维开发·prometheus
KK溜了溜了3 天前
Prometheus监控主机,Grafana成图
grafana·prometheus
伏加特遇上西柚3 天前
Loki+Alloy+Grafana日志采集部署
java·linux·服务器·spring boot·grafana·prometheus
川石课堂软件测试3 天前
软件测试|常见面试题整理
数据库·python·jmeter·mysql·appium·postman·prometheus
蜀道山老天师3 天前
云原生监控入门:监控基础概念 + SLI/SLO/SLA 详解 + Prometheus 从零安装配置
linux·运维·云原生·prometheus
专业白嫖怪3 天前
监控平台Prometheus+Grafana的部署
运维·grafana·prometheus
Elastic 中国社区官方博客4 天前
从平均值到任意百分位数:Elasticsearch 在 ES|QL 中原生支持指数直方图
大数据·数据库·sql·elasticsearch·搜索引擎·全文检索·prometheus