我配置了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'
并在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);
}
}
然后在web.xml中配置了一个servlet
<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>
目标的状态显示UP,最后一次刮擦发生在几秒钟之前,但该指标未反映在普罗米修斯中。
如何处理prometheus从目标中提取配置的指标?
答案 0 :(得分:2)
当您覆盖doGet
时,您阻止了公开指标的代码运行。按原样使用MetricsServlet,您将看到指标。