Servlet
The PrometheusMetricsServlet is a Jakarta Servlet for exposing a metric endpoint.
The old-school way of configuring a servlet is in a web.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
version="5.0">
<servlet>
<servlet-name>prometheus-metrics</servlet-name>
<servlet-class>io.prometheus.metrics.exporter.servlet.jakarta.PrometheusMetricsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>prometheus-metrics</servlet-name>
<url-pattern>/metrics</url-pattern>
</servlet-mapping>
</web-app>
Today, most Servlet applications use an embedded Servlet container and configure Servlets programmatically rather than via web.xml
.
The API for that depends on the Servlet container.
The examples directory has an example of an embedded Tomcat container with the PrometheusMetricsServlet configured.
You can use the PrometheusMetricsServlet in Spring applications. See our Spring doc.