AEM + Prometheus client_java = servlet endpoint | Community
Skip to main content
Level 2
April 14, 2023

AEM + Prometheus client_java = servlet endpoint

  • April 14, 2023
  • 3 replies
  • 1081 views

Does anyone tried to use Prometheus client_java (GitHub - prometheus/client_java) in AEM sling servlet?


I am trying to create a servlet where prometheus data will be displayed from a custom URL.

This is my simple servlet, but I am experiencing some issues with it.

 

 

import io.prometheus.client.Counter; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.servlets.SlingSafeMethodsServlet; import org.osgi.service.component.annotations.Component; import javax.servlet.Servlet; import javax.servlet.ServletException; import java.io.IOException; @Component(service = Servlet.class, immediate = true, property = { "sling.servlet.methods=GET", "sling.servlet.paths=/services/metrics" }) public class PrometheusServlet extends SlingSafeMethodsServlet { static final Counter counter = Counter.build().name("Total_number_of_sample_counter").help("Total number of counter").register(); void processCounter() { counter.inc(); } @9944223 protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { processCounter(); response.getWriter().println(counter); } }

 

 

 

Error Message:

org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: No use provider could resolve identifier

Any help will be appreciated.


Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

VeenaVikraman
Community Advisor
Community Advisor
April 14, 2023

@justin_nikolaine 

 

    Is this happening because of the missing @Override ?

 

Thanks

Veena ✌

Level 2
April 28, 2023

I pasted the wrong code, but the one I am running on my machine has @9944223

VeenaVikraman
Community Advisor
Community Advisor
April 29, 2023

Is your servlet in active state ? The error makes me think that your servlet is not yet active. Also how are you accessing the servlet ?