英文:
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支持在start
、end
和time
查询参数中指定毫秒时间戳。例如,从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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论