Search code examples
python-3.xprometheus

Prometheus graph is not coming as continuous graph


I'm using this code to expose my metric:

g_in = GaugeMetricFamily("in_utilization", 'this is device utilization info', labels=["ckt_id", "time_val"])
g_in.add_metric([ckt_id,str(val['time'])], val['value'])

I am a newbie in Prometheus. I'm receiving utilization value with time from API call. So this time_val represents the time when utilization has reached to given value.

Graph based on this metric is not continuous. What I am doing wrong?

enter image description here


Solution

  • You graph is not continuous because values of time_val are different. As a result this are considered as different time series, and they are visualized as such.

    I am a newbie in Prometheus. I'm receiving utilization value with time (from API call) So this time_val represents the time when utilization has reached to given value.

    This is a bad idea. You are increasing cardinality of your metric for no good reason. There are couple of ways to avoid it:

    1. Expose your metric with custom timestamp using custom collector.
      In this case while exposing value, you tell Prometheus not to use current time as timestamp for metric, but use timestamp provided by you.
    2. Or drop this timestamp from your data all together: most likely this timestamp will be reasonably close to exposing time anyway.