我正在通过docker部署一个spring引导应用程序和prometheus容器,并成功地公开了spring /actuator/prometheus端点。但是,当我启用prometheus调试日志时,我可以看到它无法刮取度量标准:
ts=2022-02-02T03:54:46.210Z
caller=scrape.go:1292
level=debug
component="scrape manager"
scrape_pool=spring-actuator
target=https://127.0.0.1:8443/actuator/prometheus/
msg="Scrape failed"
err="Get \"https://127.0.0.1:8443/actuator/prometheus/\": dial tcp 127.0.0.1:8443: connect: connection refused"我在想,这与我如何设置我的春季启动HTTPS有关。在构建spring-boot应用程序期间,我将使用以下命令生成一个自签名证书:
keytool
-genkey
-alias <alias>
-dname <dname>
-keyalg RSA
-keysize 4096
-storetype PKCS12
-keystore <path_to_keystore>
-validity 3650
-storepass <keystore_pass>然后,我将证书导出到一个.pem文件,并解压.crt和.key:
openssl pkcs12 -in cert.p12 -out cert.pem -nodes -passin pass:<pass>这是通过共享卷安装到我的prometheus容器中的,它有一个--web.config.file,其中包含:
tls_server_config:
cert_file: /path/to/cert.crt
key_file: /path/to/cert.key为了更好地衡量,我将insecure_skip_verify: true添加到prometheus.yml配置中:
- job_name: 'spring-actuator'
metrics_path: '/actuator/prometheus/'
scrape_interval: 60s
scheme: https
static_configs:
- targets: [ '127.0.0.1:8443' ]
tls_config:
insecure_skip_verify: true发布于 2022-02-07 22:37:25
好吧,我想我发现了我的问题。我做了两个改变:
首先,我将web.config.file的内容移到了prometheus.yml文件中的‘Spring-驱动器’之下。然后,我将目标更改为对后端容器使用主机名,而不是127.0.0.1。
最终的结果是一个prometheus.yml文件:
- job_name: 'spring-actuator'
metrics_path: '/actuator/prometheus/'
scrape_interval: 60s
scheme: https
static_configs:
- targets: [ 'backend:8443' ]
tls_config:
cert_file: /path/to/cert.crt
key_file: /path/to/cert.key
insecure_skip_verify: true所以,只是一些愚蠢的错误,不是由我所能看到的证书造成的。:)
发布于 2022-02-11 19:34:08
下面是调试该问题的关键部分
target=https://127.0.0.1:8443/actuator/prometheus/
msg="Scrape failed"
err="Get \"https://127.0.0.1:8443/actuator/prometheus/\": dial tcp 127.0.0.1:8443: connect: connection refused"它指出,scrape失败了,因为它无法将connect发送到target服务器。作为目标服务器127.0.0.1:8443,预期它将位于Prometheus运行的同一主机上。
Prometheus检索作业(也称为scraper )从目标服务中提取数据,聚合数据,并将其传递给数据库。Prometheus从基于Prometheus的配置文件中出现的名为static_configs的静态列表(或文件)中获取一个刮取targets (IP地址和端口)的列表。更复杂的dynamic环境(在任何时候都可能出现新的实例)使用service discovery mechanisms,它提供了一个机器列表来监视和显示如何组织这些机器的信息。
当Prometheus擦伤一个目标时,它会将一些标签自动附加到被刮掉的时间序列上,从而识别被刮过的目标。
up{job="<job-name>", instance="<instance-id>"}: 1 if the instance is healthy, i.e. reachable, or 0 if the scrape failed.作业:目标所属的已配置作业名称
实例:被刮过的目标URL的一部分。
配置Prometheus实例
当普罗米修斯在本地主机或同一主机上运行时,
scrape_configs:
- job_name: node
static_configs:
- targets: ['localhost:9100']时
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ["localhost:9090"]
- job_name: eventservice
static_configs:
- targets: ["events:9090"]
- job_name: bookingservice
static_configs:
- targets: ["bookings:9090"] 使用IP在多个端口中运行时的
static_configs:
- targets: ['192.168.1.117:':8080', '192.168.1.117:8081']TLS Config
TLS用于在Prometheus实例和刮取目标之间建立安全的私有传输。默认情况下,Prometheus实例试图根据其信任存储验证scrape targets公开的certificate,以确定刮伤目标的真实性。
scrape_configs:
- job_name: 'node'
scheme: https
tls_config:
# Prometheus will check that the node_exporter presents a certificate
# signed by this ca.
ca_file: 'ca.crt'
# The cert and key are presented to node_exporter to authenticate
# Prometheus as a client.
cert_file: 'client.crt'
key_file: 'client.key'
static_configs:
- targets: ['myserver.net:443']https://stackoverflow.com/questions/70950420
复制相似问题