繁体   English   中英

如何使用 dockerized Prometheus(和 Grafana)监控 ASP.Net Core 应用程序?

[英]How can I monitor a ASP.Net Core app with dockerized Prometheus (and Grafana)?

我希望使用 docker-images / docker-for-windows 在我的开发人员机器上运行 Prometheus 和 Grafana。

我有正在开发的系统,ASP.Net 核心,在 localhost:5001 上运行,指标在 https://localhost:5001/metrics 上显示得很好。

下面列出了 Docker-compose.yml 和 prometheus.yml。

  • 如果我在 docker-compose.yml 中包含 network_mode: host,我无法通过 localhost:9090 在我的物理机上访问 Prometheus
  • 如果我排除 network_mode 而使用 ports: ,我可以通过 localhost:9090 在我的物理机上访问 Prometheus,但检查 http://localhost:9090/targets,它显示 https://localhost:5001/metrics 已关闭。

我究竟做错了什么? 欢迎任何意见!

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: {}

普罗米修斯.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']

不要在 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就是容器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM