使用 Prometheus 指标存储时间戳

Store a timestamp with Prometheus metrics

我想制作一个自定义指标以在 Prometheus 指标中存储 datetime.now,有人知道怎么做吗? 我试着用 gauge 来做,但设置的预定义函数似乎只适用于 double.

示例python:

import time
import prometheus_client as prom
g = prom.Gauge("name", "description")
g.set(time.time())
prom.write_to_textfile('metrics.txt', prom.REGISTRY)

'metrics.txt' 将包含此内容:

# HELP name description
# TYPE name gauge
name 1.6287478272555726e+09

指标的值和time.time()都是纪元时间(又名unixtime),就像普罗米修斯time()函数一样。