J'ai configuré le fichier prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds.
Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is
every 1 minute.
# scrape_timeout is set to the global default (10s).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
- job_name: 'example-random'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:8090']
labels:
group: 'dummy'
et a enregistré une métrique avec prometheus
public class PrometheusMetricsServlet extends MetricsServlet {
private static final Gauge emailCount = Gauge.build().name("email_count")
.help("Number of emails sent by the user")
.register();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setStatus(200);
emailCount.set(54);
}
}
puis configuré une servlet dans le fichier web.xml
<servlet>
<servlet-name>PrometheusServlet</servlet-name>
<servlet-class>prometheusSpike.PrometheusMetricsServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>PrometheusServlet</servlet-name>
<url-pattern>/metrics</url-pattern>
</servlet-mapping>
Le statut de la cible est UP et le dernier scrape a eu lieu quelques secondes auparavant, mais la métrique n'est pas reflétée dans prometheus.
Que faire pour que prometheus tire les métriques configurées des cibles ?