我正在构建一个docker-compose.yml,并希望使用VictoriaMetrics自己的scraper (vmagent)来抓取SonarQube通过/api/prometheus/metrics上的一个插件公开的指标。
如果docker正在运行,我可以访问localhost:9000/api/prometheus/metrics并查看我的所有指标。然而,vmagent每隔60秒抛出以下错误(这意味着至少我的prometheus.yml配置被正确使用):
vmagent | 2021-02-03T12:02:51.617Z error VictoriaMetrics/lib/promscrape/scrapework.go:235
error when scraping "http://localhost:9000/api/prometheus/metrics" from job "sonarqube" with labels {instance="localhost:9000",job="sonarqube",monitor="codelab-monitor"}:
error when scraping "http://localhost:9000/api/prometheus/metrics": dial tcp4 127.0.0.1:9000: connect: connection refused; try -enableTCP6 command-line flag if you scrape ipv6 addresses我不是想抓IPv6。
我的docker-compose.yml看起来像这样:
services:
sonarqube:
image: sonarqube:8.2-community
depends_on:
- postgresdb
ports:
- "9000:9000"
networks:
- sonarnet
environment:
[...]
volumes:
[...]
postgresdb:
[...]
victoriametrics:
container_name: victoriametrics
image: victoriametrics/victoria-metrics
ports:
- 8428:8428
- 8089:8089
- 8089:8089/udp
- 2003:2003
- 2003:2003/udp
- 4242:4242
volumes:
[...]
command:
- '--storageDataPath=/storage'
- '--graphiteListenAddr=:2003'
- '--opentsdbListenAddr=:4242'
- '--httpListenAddr=:8428'
- '--influxListenAddr=:8089'
networks:
- sonarnet
restart: always
vmagent:
container_name: vmagent
image: victoriametrics/vmagent
depends_on:
- "victoriametrics"
ports:
- 8429:8429
volumes:
- vmagentdata:/vmagentdata
- ./prometheus:/etc/prometheus
command:
- '--promscrape.config=/etc/prometheus/prometheus.yml'
- '--remoteWrite.url=http://victoriametrics:8428/api/v1/write'
networks:
- sonarnet
restart: always
vmalert:
[...]
alertmanager:
[...]
grafana:
[...]
networks:
sonarnet:
driver: bridge
volumes:
[...]和我的prometheus.yml (基于非默认的60秒抓取间隔,我假设它被vmagent正确读取):
global:
scrape_interval: 60s
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
- job_name: 'sonarqube'
metrics_path: '/api/prometheus/metrics'
static_configs:
- targets: ['localhost:9000']我怀疑我的docker networks配置有问题,但我不知道为什么http://localhost:9000/api/prometheus/metrics不能访问docker。
发布于 2021-02-03 22:20:14
在vmagent容器中,localhost意味着vmagent本身。尝试使用服务名称sonarqube:9000而不是localhost:9000进行引用。
https://stackoverflow.com/questions/66027500
复制相似问题