如何在VictoriaMetrics中处理时间单位和步长,以便在摄取或查询时使用?

huangapple go评论57阅读模式
英文:

How to handle time unit and step while ingesting or querying in VictoriaMetrics?

问题

作为一个初学者,我在Docker容器中使用victoria-metrics尝试了官方文档中的示例命令。

在我尝试写入和读取以验证我的操作是否成功时,我发现很奇怪:我只能使用mil-sec时间单位进行写入,而只能使用second时间单位进行查询

我如何可能需要处理不同的时间单位来进行摄取和查询呢?
我是否错过了在合适的方式下使用step的任何细节?

任何帮助都将不胜感激。

我尝试过的命令:

// 尝试1:使用mil-sec进行写入
// 写入
curl -d '{"metric":{"__name__":"zoo2","job":"node_exporter"},"values":[0,1,2],"timestamps":[1686207845001,1686207846002,1686207848003]}' -X POST 'http://localhost:8428/api/v1/import'

// 否
curl "http://localhost:8428/api/v1/query_range?query=zoo2&start=1686207845000&end=1686207850000&step=1"
// 是
curl "http://localhost:8428/api/v1/query_range?query=zoo2&start=1686207845&end=1686207850&step=1"

// 尝试2:使用sec进行写入
curl -d '{"metric":{"__name__":"zoo3","job":"node_exporter"},"values":[0,1,2],"timestamps":[1686207845,1686207846,1686207848]}' -X POST 'http://localhost:8428/api/v1/import'

// 否
curl "http://localhost:8428/api/v1/query_range?query=zoo3&start=1686207845000&end=1686207850000&step=1"
// 也不行
curl "http://localhost:8428/api/v1/query_range?query=zoo3&start=1686207845&end=1686207850&step=1"
英文:

As a beginner, I tried example-like commands on official docs with a victoria-metrics in docker container.

While I try to write and read to verify whether my operation succeeded, I found it curious: I can only write with mil-sec time unit, while I can only query with second time unit.

How could it be possible that I need to handle different time unit for ingest and query ?
DId I miss any detail about using step in a decent way?

Any helo would be sincerely appreciated.

Commands I tried:

// try 1: write with mil-sec
// write
curl -d '{"metric":{"__name__":"zoo2","job":"node_exporter"},"values":[0,1,2],"timestamps":[1686207845001,1686207846002,1686207848003]}' -X POST 'http://localhost:8428/api/v1/import'

// no
curl "http://localhost:8428/api/v1/query_range?query=zoo2&start=1686207845000&end=1686207850000&step=1"
// yes
curl "http://localhost:8428/api/v1/query_range?query=zoo2&start=1686207845&end=1686207850&step=1"


// try 2: write with sec
curl -d '{"metric":{"__name__":"zoo3","job":"node_exporter"},"values":[0,1,2],"timestamps":[1686207845,1686207846,1686207848]}' -X POST 'http://localhost:8428/api/v1/import'

// no
curl "http://localhost:8428/api/v1/query_range?query=zoo3&start=1686207845000&end=1686207850000&step=1"
// no, either
curl "http://localhost:8428/api/v1/query_range?query=zoo3&start=1686207845&end=1686207850&step=1"

答案1

得分: 3

这是指定毫秒格式错误的方式 - 请参阅 https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html#timestamp-formats。请尝试以下操作:

curl "http://localhost:8428/api/v1/query_range?query=zoo2&start=1686207845.000&end=168620785.000&step=1"

我已经添加了PR以在文档中更清晰地表示单位格式 - https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4428/files

更新:从v1.92.0开始,VictoriaMetrics支持在startendtime查询参数中指定毫秒时间戳。例如,从v1.92.0开始,以下查询与上面的查询等效:

curl "http://localhost:8428/api/v1/query_range?query=zoo2&start=1686207845000&end=168620785000&step=1"
英文:

That's the wrong format for specifying milliseconds - see https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html#timestamp-formats. Try the following:

curl "http://localhost:8428/api/v1/query_range?query=zoo2&start=1686207845.000&end=168620785.000&step=1"

I've added PR to make units format more clear in docs - https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4428/files

Update: VictoriaMetrics supports specifying timestamps in milliseconds in start, end and time query args starting from v1.92.0. For example, the following query is equivalent to the query above starting from v1.92.0:

curl "http://localhost:8428/api/v1/query_range?query=zoo2&start=1686207845000&end=168620785000&step=1"

huangapple
  • 本文由 发表于 2023年6月9日 11:49:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76437098.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定