• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

武飞扬头像
furfur-jiang
帮助3

使用到的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

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.谷歌.com/document/d/1Kppm7qL9C-BJB1j6yb6-9ObG3AbdZnFUBYPNNWwDBYM/edit

promwrite: expected status 200, got 400: out of bounds
写入时间不在允许范围内,参考乱序写入配置,调整

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfiagia
系列文章
更多 icon
同类精品
更多 icon
继续加载