Prometheus Custom time for X-Axis

1,349 views
Skip to first unread message

amande...@gmail.com

unread,
Jun 25, 2018, 9:12:58 AM6/25/18
to Prometheus Users
Hello,

I am creating custom metrics from Spring Boot application of format:
metric_name{info="info_value",objekt="object_value",time="time of format yyyy-mm-dd hh:mm:ss"} numeric_metric_value

In Grafana I would want to display graph panel using:
X-axis: value from metric label "time"
Y-axis: numeric_metric_value

There is a reason that I cannot use prometheus scrape timestamp for X-Axis in Grafana graph. The custom metrics from Spring Boot App sometimes deliver historical metrics data and has to be displayed in Grafana accordingly.

Please advise!

Thanks

Meier

unread,
Jun 25, 2018, 2:04:11 PM6/25/18
to Prometheus Users
If you want to add a timestamp you have to append it at the end in the format int64 (milliseconds since epoch, i.e. 1970-01-01 00:00:00 UTC, excluding leap seconds) see https://prometheus.io/docs/instrumenting/exposition_formats/
Adding it as label would lead to a new timeseries for each value. 
Also, as i understand it this is discouraged: see https://github.com/prometheus/client_golang/issues/187#issuecomment-168345993

amande...@gmail.com

unread,
Jun 26, 2018, 3:58:39 AM6/26/18
to Prometheus Users
Hi, Thanks for the reply.

In my Java code I have something like this:
private static final Gauge gauge = Gauge.build().name("metric_name")
.labelNames("label_name").help("Info").register();

gauge.labels("label_value").set(metric_value);

How do I set timestamp value using GAUGE object? I am using the library (simpleclient_spring_boot) from Prometheus. I do not seem to finf a way of settingt imestamp value.

If I cannot do it using Prometheus libraries for Spring-Boot, how else can I use exposition-format from my Java Code and create Prometheus metrics?

Brian Brazil

unread,
Jun 26, 2018, 4:07:45 AM6/26/18
to amande...@gmail.com, Prometheus Users
On 26 June 2018 at 08:58, <amande...@gmail.com> wrote:
Hi, Thanks for the reply.

In my Java code I have something like this:
private static final Gauge gauge = Gauge.build().name("metric_name")
.labelNames("label_name").help("Info").register();

gauge.labels("label_value").set(metric_value);

How do I set timestamp value using GAUGE object? I am using the library (simpleclient_spring_boot) from Prometheus. I do not seem to finf a way of settingt imestamp value.

If I cannot do it using Prometheus libraries for Spring-Boot, how else can I use exposition-format from my Java Code and create Prometheus metrics?

This is not something you can do with direct instrumentation in Prometheus, as scrapes are to retrieve information about the here and now. You should try to instrument the data when it's coming in, as Prometheus isn't suitable for ingesting historical data.

Brian
 


On Monday, 25 June 2018 20:04:11 UTC+2, Meier wrote:
If you want to add a timestamp you have to append it at the end in the format int64 (milliseconds since epoch, i.e. 1970-01-01 00:00:00 UTC, excluding leap seconds) see https://prometheus.io/docs/instrumenting/exposition_formats/
Adding it as label would lead to a new timeseries for each value. 
Also, as i understand it this is discouraged: see https://github.com/prometheus/client_golang/issues/187#issuecomment-168345993

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/cbb2ae34-a8e6-4e9c-9a46-3c4914633316%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages