Reputation: 33
I would like to make a custom metric to store datetime.now in Prometheus metrics, someone know how do it? I tried to do it with gauge but the set predefined function seem to work only with double.
Upvotes: 0
Views: 6290
Reputation: 20196
Example with 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' will contain this:
# HELP name description
# TYPE name gauge
name 1.6287478272555726e+09
The value of the metric and time.time()
both are epoch time (aka unixtime), just as Prometheus time()
function.
Upvotes: 2