Monitor Java spring boot app without instrumenting the code

35 views
Skip to first unread message

Ketan Talreja

unread,
May 7, 2020, 2:52:39 AM5/7/20
to Prometheus Users
Hi Guys, 

Hope everyone is doing well! 

I have started using Prometheus to collect metrics for my application which is implemented in Java spring boot 2.x framework. I have used "micrometer-registry-prometheus" library but this required some annotation to be done in the code and moreover customize the bean configuration. 

Monitoring use-case for my application - 
1. I have to count the number of time REST API/Endpoint has been invoked
2. I have to also capture REST request Input/response Output generated and scrape it to metrics server i.e. Prometheus and using this metrics I have to calculate i.e. number of time the "value" is returned in the response output and same for request input i.e. number of time the specific "value" is passed as in the input payload. 

Could you please help how can I achieve above two points using Prometheus and its client-libraries? And is there a way to achieve without instrumenting the app code? This will help to decouple the application codebase from instrumentation.

Thanks!!
Ketan

Ketan Talreja

unread,
May 7, 2020, 7:17:28 AM5/7/20
to Prometheus Users
Also, after using @Times annotation at the method level, I am getting metrics consist of  of http_server_requests_seconds_count{exception="None",method="GET",status="200",uri="/students",} 2.0 

While I was hoping this will return tags from Http request and response as per the default implementation inside class DefaultWebMvcTagsProvider

@Override
public Iterable<Tag> getTags(HttpServletRequest request, HttpServletResponse response, Object handler,
Throwable exception) {
Tags tags = Tags.of(WebMvcTags.method(request), WebMvcTags.uri(request, response, this.ignoreTrailingSlash),
WebMvcTags.exception(exception), WebMvcTags.status(response), WebMvcTags.outcome(response));
for (WebMvcTagsContributor contributor : this.contributors) {
tags = tags.and(contributor.getTags(request, response, handler, exception));
}
return tags;
} Any idea what am I missing here? Also, I have added custom class to override the behavior but did not work. @Bean WebMvcTagsProvider webMvcTagsProvider() { return new WebMvcTagsProvider() { @SuppressWarnings("unchecked") @Override public Iterable<Tag> getTags(HttpServletRequest request, HttpServletResponse response, Object handler, Throwable exception) { return ((Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE)) .entrySet() .stream() .map(entry -> new ImmutableTag(entry.getKey(), entry.getValue())) .collect(Collectors.toList()); } @Override public Iterable<Tag> getLongRequestTags(HttpServletRequest request, Object handler) { return new ArrayList<>(); } }; }

Any advise on what I am doing wrong? 

Appreciate your help!

Thanks,
Ketan
Reply all
Reply to author
Forward
0 new messages