我正在尝试让普罗米修斯在vm上运行。我有几个要监视的微服务,它们正在vm上运行。我将以下内容添加到docker-compose.yml文件之一:

prometheus:
    image: prom/prometheus:v2.1.0
    volumes:
        - ./prometheus.yml:/etc/prometheus/prometheus.yml
    command:
        - '--config.file=/etc/prometheus/prometheus.yml'
    ports:
        - '9090:9090'

然后将prometheus.yml文件添加到与上述docker-compose相同的文件夹中。
global:
  scrape_interval:     15s
  evaluation_interval: 15s



scrape_configs:

  - job_name: 'prometheus'

    static_configs:
        - targets: ['localhost:9090']

 - job_name: 'radios-service'


   metrics_path: '/prometheus-metrics'
   static_configs:
        - targets: ['radios-service:8080']

 - job_name: 'websocket-service'
   metrics_path: '/prometheus-websocket'
   static_configs:
      - targets: ['websocket-service:8080']

这可以通过我的命令行在docker上成功运行,但是当我尝试在vm上运行它时会抛出此错误:



但是当我在本地运行它不会引发任何问题。虚拟机中的问题可能是什么?

最佳答案

我通过在docker compose中编辑卷行来解决它。我猜在Linux机器上,您需要提供绝对路径。我将prometheus.yml放在/ home /目录中,并将路径更改为如下所示:

prometheus:
image: prom/prometheus:v2.1.0
volumes:
    - /home/prometheus.yml:/etc/prometheus/prometheus.yml
command:
    - '--config.file=/etc/prometheus/prometheus.yml'
ports:
    - '9090:9090'

这似乎有效。

关于docker - Prometheus不是在vm上运行,而是在本地Docker上运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51267889/

10-12 22:59