0

在 Grafana 仪表板中显示了一个自定义指标。该指标是通过 Prometheus 接收的。该指标是通过 Spring Boot Actuator / Micrometer 构建的。

在大约一半的情况下,Prometheus 对指标的查询给出了一个空结果。在其他情况下,该值是有效的。那么,它可能与抓取的阈值有关吗?

分析 Prometheus 使用的查询,会显示一个空结果:

http://valid.url/prometheus/api/v1/query?query=last_seconds_since_startime_seconds&time=1645521095.864

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);
4

1 回答 1

0

解决方案是更新 prometheus.yml 文件中针对 Docker Swarm 中特定组件的抓取超时。

全局设置保留为默认值 10 秒。

对于特定组件:

- job_name: 'my-component'
  metrics_path: /actuator/prometheus
  scrape_interval: 30s
  scrape_timeout: 25s    <== this one
  dns_sd_configs:
    - names:
        - 'tasks.mycomponent'
      type: 'A'
      port: 8080
于 2022-02-22T16:16:59.350 回答