prometheus - 使用 Prometheus 指标存储时间戳
问题描述
我想制作一个自定义指标来将datetime.now存储在 Prometheus 指标中,有人知道怎么做吗?我试图用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),就像 Prometheustime()
函数一样。
推荐阅读
- python - python - 如何将列设置为DataFrame中的索引
- node.js - 如何在信使欢迎屏幕上添加按钮?
- django - Django websockets 身份验证
- android - 为什么我对一个包中的代码所做的更改没有反映在实际的应用程序中?
- java - 什么java数据结构适合像kafka这样的基于偏移量的单分区日志?
- c++ - 将类中声明的函数作为参数传递会导致编译错误
- apache-spark - 将带有纳秒的字符串转换为时间戳
- html - 带有 xsl 的 xpath:测试时
- c# - 使 8 x 8 网格具有正确的 FEN 表示法。像棋盘
- c++ - 在循环初始化中使用带有静态的 constexpr?