Creating gauges via annotation (like PrometheusTimeMethod)

732 views
Skip to first unread message

bo...@kairat.eu

unread,
Nov 6, 2017, 10:22:16 AM11/6/17
to Prometheus Developers
Hi @all!

I managed to get my Java-Services -> Prometheus -> Grafana stack up and running.
I am using PrometheusTimeMethod on each webservice which generates a nicht summary.

My problem: I would like to know how the min/average/max response time was in the last 1 minute.

I do not want to implement gauges for each of these methods inside the methods.

Is there an annotation that does this already?
Can someone give me a short manual how I could achieve this?

THX!
Boris

Brian Brazil

unread,
Nov 6, 2017, 10:30:42 AM11/6/17
to Boris Kairat, Prometheus Developers
Java annotations alone are not powerful enough to do what is needed, you need to add something to the build pipeline or as a java agent to make it workable - and even then Java annotations aren't expressive enough for the full power of the Prometheus data model with labels.

In the most general cases, instrumenting by hand is the only option.


It's not possible to do min/max generally, you'll need event logging for that rather than a metrics system.

--

bo...@kairat.eu

unread,
Nov 6, 2017, 11:23:13 AM11/6/17
to Prometheus Developers
For me it seems to work if I copy/modify the following class (and the classes around...) https://github.com/prometheus/client_java/blob/master/simpleclient_spring_web/src/main/java/io/prometheus/client/spring/web/MethodTimer.java

I simply added a gauge for the response time and used it in parallel to the "summary".

Is this a correct/working solution?

THX!

Brian Brazil

unread,
Nov 6, 2017, 11:27:17 AM11/6/17
to Boris Kairat, Prometheus Developers
That's a question about a particular framework rather than java in general. I don't see how a gauge helps you here.

--

au...@telenordigital.com

unread,
Dec 22, 2017, 8:12:22 AM12/22/17
to Prometheus Developers
I have created some annotations that we are starting to use in Telenor. I use a proxy for decorating the methods of an interface with metrics.

You could use summary to monitor the response times. Have a look at the Summarize annotation here: https://github.com/auduntorp/client_java/blob/annotations/simpleclient_annotations/src/main/java/io/prometheus/client/annotations/Summarize.java

And the test for it here: https://github.com/auduntorp/client_java/blob/annotations/simpleclient_annotations/src/test/java/io/prometheus/client/annotations/PrometheusMonitorTest.java

Sergio Bilello

unread,
Jul 11, 2018, 3:12:07 PM7/11/18
to Prometheus Developers
Hi!

Did you use this project in production or it was just an experiment?
Didn't you create an exporter?
Did you use a pushgateway?

Thanks,
Sergio
Ddi you check for your annotation

Reply all
Reply to author
Forward
0 new messages