上下文超时 - Prometheus

44

我有一个Prometheus配置,其中有许多作业,我正在通过HTTP抓取指标。但是我有一个作业需要通过HTTPS抓取指标。

当我访问:

https://ip-address:port/metrics

我可以看到这些指标。 我在prometheus.yml配置中添加的工作是:

- job_name: 'test-jvm-metrics'
    scheme: https
    static_configs:
      - targets: ['ip:port']

当我重新启动Prometheus时,我的目标出现错误:

上下文执行期限已超过

我读到可能是scrape_timeout的问题,但我已经将其设置为50秒,仍然出现相同的问题。

这个问题的原因是什么,如何解决? 谢谢!

11个回答

36

可能默认的scrape_timeout值对您来说太短了

[ scrape_timeout: <duration> | default = 10s ]

将 scrape_timeout 的值增大。

scrape_configs:
  - job_name: 'prometheus'

    scrape_interval: 5m
    scrape_timeout: 1m

请看这里:https://github.com/prometheus/prometheus/issues/1438


太奇怪了!我的目标工作中根本没有scrape_timeout这个参数;所以我添加了它,结果prometheus无法启动,显示错误信息:prometheus.service: 主进程退出,代码=退出,状态=2/无效参数 - undefined
我还尝试将该参数添加到全局部分,但出现了相同的错误。 - undefined

11

我过去也遇到了同样的问题。在我的情况下,问题出在证书方面,我通过添加以下内容来解决它:

 tls_config:
      insecure_skip_verify: true

你可以尝试一下,也许会有效。


5
对我来说不起作用。我尝试了添加 "tls_config" 标签,但问题仍然存在 :( - Danilo Caetano
我的问题恰好相反,insecure_skip_verifyredis 插件中引起了问题。尽管 insecure_skip_verify 是一个高级配置,而不是 tls_config 下的子配置。 - Hamed Nemati

6

我曾遇到类似问题,因此尝试延长scrape_timeout的时间,但没有任何效果——然而使用promtool能够解释问题。

我的有问题的作业看起来像这样:

- job_name: 'slow_fella'
  scrape_interval: 10s
  scrape_timeout: 90s
  static_configs:
  - targets: ['192.168.1.152:9100']
    labels:
      alias: sloooow    

检查位于/etc/prometheus目录下的配置,在终端中输入以下命令:

promtool check config prometheus.yml

结果将解释问题并指出如何解决:

Checking prometheus.yml
  FAILED: parsing YAML file prometheus.yml: scrape timeout greater than scrape interval for scrape config with job name "slow_fella"

请确保 scrape_timeout 足够长,以适应您所需的 scrape_interval


我将其设置为 scrape_interval: 5m scrape_timeout: 1m。但问题仍然存在。在检查 promtool 配置后,它显示 SUCCESS: prometheus.yml 是有效的 prometheus 配置文件语法。但问题是指标的 curl 数据可见。(ip:port/metrics) - Thusitha Sumanadasa

1

我遇到了由于最大连接数达到而导致的问题。我在数据库中增加了max_connections参数并释放了一些连接。 然后Prometheus能够再次抓取指标。


1
prometheus 服务器无法访问抓取端点时,可能会发生这种情况,原因可能是防火墙拒绝规则。只需在浏览器中检查使用 <url>:9100(其中 9100 是运行的 node_exporter 服务端口)的 URL 是否仍然可访问即可。

0
在我的情况下,问题出在IPv6上。我使用ip6tables阻止了IPv6,但也阻止了prometheus流量。正确的IPv6设置为我解决了问题。

1
你能详细说明一下吗?你是如何检查和修复的? - TjS

0
在我的情况下,我不小心在Kubernetes部署清单中放置了错误的端口,与与其关联的服务以及Prometheus目标定义的不同。

0
在AWS上,为我打开SG中的端口(用于Prometheus),可以正常工作。

0
对我来说,问题是我在一个EC2实例内运行导出器,并忘记在安全组中允许监听端口的TCP连接(还要检查子网的路由)。因此,Prometheus容器无法连接到我的导出器机器的监听端口。
在Prometheus容器内部,您可以运行wget exporterIp:listenPort命令,如果没有返回任何内容/无法连接,则可能存在网络问题。

0
当我们重新配置istio-system命名空间及其istio-component时,我们开始遇到类似的问题。我们还通过prometheus-operator在monitoring命名空间中安装了prometheus,并启用了istio-injection。
重启启用了istio-injection的监控(monitoring)命名空间的prometheus组件解决了该问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接