我正在尝试用旧数据填充 Prometheus。我的输入数据是:
$ cat /etc/prometheus/backfill.txt
# HELP mymetric My metric.
# TYPE mymetric counter
mymetric{code="200",service="user"} 123 1665824331000
mymetric{code="500",service="user"} 456 1665824331000
# EOF
下列的文档然后我运行该命令,该命令没有输出任何错误:
$ promtool tsdb create-blocks-from openmetrics /etc/prometheus/backfill.txt /tmp/backfill_data
BLOCK ULID MIN TIME MAX TIME DURATION NUM SAMPLES NUM CHUNKS NUM SERIES SIZE
01GFNDV65PR5Z6MS5J82C6SAH4 1665824331000000 1665824331000001 1ms 2 2 2 787
然后将创建的文件夹复制到Prometheus的数据文件夹中:
$ cp -r /tmp/backfill_data/* /prometheus/data
但之后什么也没发生:这个指标没有在 Prometheus 中列出。但它似乎被正确存储在 TSDB 中:
$ promtool tsdb analyze /prometheus/data
Block ID: 01GFNDV65PR5Z6MS5J82C6SAH4
Duration: 1ms
Series: 2
Label names: 3
Postings (unique label pairs): 4
Postings entries (total label pairs): 6
Label pairs most involved in churning:
2 service=user
2 __name__=mymetric
1 code=500
1 code=200
Label names most involved in churning:
2 __name__
2 code
2 service
Most common label pairs:
2 __name__=mymetric
2 service=user
1 code=200
1 code=500
Label names with highest cumulative label value length:
8 __name__
6 code
4 service
Highest cardinality labels:
2 code
1 __name__
1 service
Highest cardinality metric names:
2 mymetric
我尝试重新启动我的 Prometheus 容器但没有任何改变。
编辑:我使用命令参数启动 Prometheus--no-scrape.adjust-timestamps --log.level=debug --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.retention.time=2y --web.console.libraries=/usr/share/prometheus/console_libraries --web.console.templates=/usr/share/prometheus/consoles --web.config.file=/etc/prometheus/web.yml
答案1
您正在使用错误的时间格式创建回填文件,它只采用普通的 unix 时间戳,但您的时间戳以毫秒为单位。
因此,将其更改为:
# HELP mymetric My metric.
# TYPE mymetric counter
mymetric{code="200",service="user"} 123 1665824331
mymetric{code="500",service="user"} 456 1665824331
# EOF
它应该可以工作。