我想让Prometheus和Grafana在我的开发者机器上运行,使用docker/。
我有正在开发的系统,ASP.Net核心,运行在本地主机上:5001,https://localhost:5001/metrics上的指标显示得很好。
Docker-compose.yml和prometheus.yml列出如下。
如果我在localhost:9090
我做错了什么?欢迎任何评论!
docker-compose.yml:
version: '3.8'
services:
prometheus:
image: prom/prometheus
container_name: gradle_docker-prometheus
#network_mode: host
ports:
- 9090:9090
volumes:
- prometheus-storage:/var/lib/prometheus
- /c/Data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
grafana:
image: grafana/grafana
container_name: gradle_docker-grafana
ports:
- "3000:3000"
volumes:
- grafana-storage:/opt/grafana/data
depends_on:
- prometheus
volumes:
prometheus-storage: {}
grafana-storage: {}prometheus.yml:
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
monitor: 'my-project'
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 10s
scheme: http
static_configs:
- targets: ['localhost:9090','cadvisor:8080','node-exporter:9100', 'nginx-exporter:9113']
- job_name: '.Net'
scrape_interval: 10s
scheme: https
static_configs:
- targets: ['localhost:5001']发布于 2021-03-22 11:35:26
不要在Windows上使用主机网络模式,它只支持Linux。您需要的是更改目标地址:
- job_name: '.Net'
scrape_interval: 10s
scheme: https # You may have to change this to 'http'
# or you'd have to create a certificate
# with `host.docker.internal`
static_configs:
- targets: ['host.docker.internal:5001']host.docker.internal是连接到Docker的一个特殊地址,因为容器中的localhost只是容器本身。
总结一下注释中的内容:在将目标更改为host.docker.internal之后,确保应用程序允许与该主机连接。跑
curl http://localhost:5001/ -H "Host: host.docker.internal"查查答案。如果您有一个包含如下内容的错误:
请求主机名无效。
然后,您必须找出主机过滤器在哪里(它可能是一个包含localhost的数组),并在其中添加新主机(host.docker.internal)。
https://stackoverflow.com/questions/66719960
复制相似问题