java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
io.prometheus.metrics.exporter.servlet.javax.PrometheusMetricsServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class PrometheusMetricsServlet extends javax.servlet.http.HttpServlet
This class extends HttpServlet to create a servlet for exporting Prometheus metrics. It uses a PrometheusScrapeHandler to handle HTTP GET requests and export metrics. The servlet can be configured with custom PrometheusProperties and a PrometheusRegistry.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    PrometheusMetricsServlet(io.prometheus.metrics.config.PrometheusProperties config)
    Constructor with custom PrometheusProperties.
    PrometheusMetricsServlet(io.prometheus.metrics.config.PrometheusProperties config, io.prometheus.metrics.model.registry.PrometheusRegistry registry)
    Constructor with custom PrometheusProperties and PrometheusRegistry.
    PrometheusMetricsServlet(io.prometheus.metrics.model.registry.PrometheusRegistry registry)
    Constructor with a custom PrometheusRegistry.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Handles HTTP GET requests.

    Methods inherited from class javax.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service

    Methods inherited from class javax.servlet.GenericServlet

    destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PrometheusMetricsServlet

      public PrometheusMetricsServlet()
      Default constructor. Uses the default PrometheusProperties and PrometheusRegistry.
    • PrometheusMetricsServlet

      public PrometheusMetricsServlet(io.prometheus.metrics.model.registry.PrometheusRegistry registry)
      Constructor with a custom PrometheusRegistry. Uses the default PrometheusProperties.
      Parameters:
      registry - the PrometheusRegistry to use
    • PrometheusMetricsServlet

      public PrometheusMetricsServlet(io.prometheus.metrics.config.PrometheusProperties config)
      Constructor with custom PrometheusProperties. Uses the default PrometheusRegistry.
      Parameters:
      config - the PrometheusProperties to use
    • PrometheusMetricsServlet

      public PrometheusMetricsServlet(io.prometheus.metrics.config.PrometheusProperties config, io.prometheus.metrics.model.registry.PrometheusRegistry registry)
      Constructor with custom PrometheusProperties and PrometheusRegistry.
      Parameters:
      config - the PrometheusProperties to use
      registry - the PrometheusRegistry to use
  • Method Details

    • doGet

      protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
      Handles HTTP GET requests. Exports Prometheus metrics by delegating to the PrometheusScrapeHandler.
      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Parameters:
      request - the HttpServletRequest
      response - the HttpServletResponse
      Throws:
      IOException - if an I/O error occurs