在 Grafana 仪表板中显示了一个自定义指标。该指标是通过 Prometheus 接收的。该指标是通过 Spring Boot Actuator / Micrometer 构建的。
在大约一半的情况下,Prometheus 对指标的查询给出了一个空结果。在其他情况下,该值是有效的。那么,它可能与抓取的阈值有关吗?
分析 Prometheus 使用的查询,会显示一个空结果:
http://valid.url/prometheus/api/v1/query?query=last_seconds_since_startime_seconds
结果是:
{"status":"success","data":{"resultType":"vector","result":[]}}
使用此查询会显示完整的结果(大约 17 秒后),其中包含实际值:
http://valid.url/stackname/componentname/actuator/prometheus
文中是:
last_seconds_since_startime_seconds 63.0
环境是 Spring Boot、Micrometer、Actuator、Prometheus 和 Grafana。执行器查询是使用 Micrometer 构建的:
Gauge.builder( LAST_SECONDS_SINCE_STARTIME, this,
PrometheusStatistics::secondsSinceStart)
.description("Seconds since last fetch")
.baseUnit("seconds")
.strongReference(true)
.register(meterRegistry);