简体   繁体   English

Prometheus不是在vm上运行,而是在本地Docker上运行

[英]Prometheus not running on the vm but runs on Docker locally

I'm trying to get prometheus running on the vm. 我正在尝试在虚拟机上运行prometheus。 I have several microservices which I wish to monitor and are running on the vm. 我有几个要监视的微服务,它们正在vm上运行。 I added the below to one of the docker-compose.yml files : 我将以下内容添加到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'

And I added my prometheus.yml file in the same folder as the above docker-compose. 然后将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']

This runs successfully on docker through my command line.However, it throws this error when i try to run it on the vm: 这可以通过我的命令行在docker上成功运行,但是当我尝试在vm上运行它时会抛出此错误:

ERROR: for prometheus Cannot start service prometheus: b'OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \\"rootfs_linux.go:58: mounting \\\\"/usr/local/bin/prometheus.yml\\\\" to rootfs \\\\"/var/lib/docker/overlay2/f4b34c5866b191683d4e8c08e59fb14f56127cbcd67a603225954dd59c0a6a50/merged\\\\" at \\\\"/var/lib/docker/overlay2/f4b34c5866b191683d4e8c08e59fb14f56127cbcd67a603225954dd59c0a6a50/merged/etc/prometheus/prometheus.yml\\\\" caused \\\\"not a directory\\\\"\\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? 错误:对于prometheus无法启动服务prometheus:b'OCI运行时创建失败:container_linux.go:348:启动容器进程引起了“ process_linux.go:402:容器初始化引起了\\” rootfs_linux.go:58:安装\\\\“ / usr /local/bin/prometheus.yml \\\\“转换为rootfs \\\\” / var / lib / docker / overlay2 / f4b34c5866b191683d4e8c08e59fb14f56127cbcd67a603225954dd59c0a6a50 / merged \\\\“在\\\\” / var / lib / docker / overlay2 / f4b674e56a56e56a56e56a56a56e5a4e4a4e5c4e3e3c3e4c3e3e prometheus / prometheus.yml \\\\“导致\\\\”不是目录\\\\“ \\”“:未知:您是否正在尝试将目录挂载到文件上(反之亦然)? Check if the specified host path exists and is the expected type' ERROR: Encountered errors while bringing up the project. 检查指定的主机路径是否存在以及是否为预期的类型'错误:启动项目时遇到错误。

But it does not throw any issue when i run it locally. 但是当我在本地运行它不会引发任何问题。 What could the issue in the vm be? 虚拟机中的问题可能是什么?

I solved it by editing the volumes line in the docker compose. 我通过在docker compose中编辑卷行来解决它。 I guess in a linux machine you need to provide the absolute path. 我猜在Linux机器上,您需要提供绝对路径。 I placed my prometheus.yml in a /home/ directory and changed the path to that as below: 我将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'

That seems to work. 这似乎有效。

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

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