[英]Docker-compose: Exposing Prometheus metrics on Openzipkin
[英]Unable to bring up prometheus using docker-compose file. Always throws the error /etc/prometheus/prometheus.yaml: no such file or directory
我一直在嘗試使用 docker-compose 文件啟動 Prometheus 容器。 我研究了網上可用的各種解決方案,但似乎沒有一個有效。 請檢查我的 prometheus.yaml 文件和 docker-compose.yml 文件,讓我知道我的配置錯誤。 我的 prometheus.yaml 文件位於 /root/prometheus/prometheus.yaml
注意:我正在嘗試以代理模式運行 prometheus,並且正在從 /root 路徑運行 docker-compose 文件。
產生的錯誤:
-bash-5.0# docker-compose up
[...]
prometheus | ts=2022-05-12T14:28:25.350Z caller=main.go:447 level=error msg="Error loading config (--config.file=/etc/prometheus/prometheus.yaml)" file=/etc/prometheus/prometheus.yaml err="open /etc/prometheus/prometheus.yaml: no such file or directory"
prometheus exited with code 2
碼頭工人-compose.yml:
version: '3'
volumes:
prometheus_data:
services:
prometheus:
image: prom/prometheus:v2.35.0
container_name: prometheus
volumes:
- ./prometheus:/etc/prometheus
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yaml'
- '--storage.agent.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--web.enable-lifecycle'
- '--enable-feature=agent'
expose:
- 9090
ports:
- "9090:9090"
更新 1:在下面添加目錄樹結構
-bash-5.0# pwd
/root
-bash-5.0# tree
.
|-- cadvisor
|-- docker-compose.yml
|-- docker-compose_1.yml
|-- prometheus
| |-- prometheus.yaml
| |-- prometheus.yml
| |-- prometheus_old.yaml
| `-- prometheus_old.yml
|-- prometheus.yaml
`-- prometheus.yml
1 directory, 9 files
-bash-5.0#
更新2:我做了一些調試,發現目錄正在被掛載,而文件被掛載為目錄。
基本上我所做的是我對 docker-compose.yml 文件進行了如下更改。
version: '3'
services:
prometheus:
image: prom/prometheus:v2.35.0
container_name: prometheus
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus-test/prometheus.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
#- '--storage.agent.path=/prometheus'
- '--web.enable-lifecycle'
#- '--enable-feature=agent'
expose:
- 9090
ports:
- "9090:9090"
volumes:
prometheus_data:
在上面的 docker 文件中,我將我的 prometheus.yml 文件安裝到不同的位置,並讓 prometheus 使用默認配置文件進行配置。 后來我登錄到容器並檢查了掛載的文件,這就是所看到的。
-bash-5.0# docker container exec -it prometheus sh
/prometheus $ cd /etc
/etc $ ls -ltr
total 68
-rw-r--r-- 1 root root 18774 Feb 10 2019 services
-rw-r--r-- 1 root root 494 Aug 16 2019 nsswitch.conf
-rw-r--r-- 1 root root 118 Mar 22 21:07 localtime
-rw-r--r-- 1 root root 340 Apr 11 21:49 passwd
-rw-rw-r-- 1 root root 306 Apr 11 21:49 group
-rw------- 1 root root 136 Apr 13 00:25 shadow
drwxr-xr-x 6 root root 4096 Apr 13 00:25 network
drwxr-xr-x 3 root root 4096 Apr 15 10:54 ssl
lrwxrwxrwx 1 root root 12 May 13 10:54 mtab -> /proc/mounts
-rw-r--r-- 1 root root 174 May 13 10:54 hosts
-rw-r--r-- 1 root root 13 May 13 10:54 hostname
-rw-r--r-- 1 root root 38 May 13 10:54 resolv.conf
drwxr-xr-x 3 root root 4096 May 13 11:00 prometheus-test
drwxr-xr-x 1 nobody nobody 4096 May 13 11:00 prometheus
/etc $
/etc $ cd prometheus-test/
/etc/prometheus-test $ ls
prometheus.yml
/etc/prometheus-test $ ls -ltr
total 8
drwxr-xr-x 2 root root 4096 May 13 10:54 prometheus.yml
/etc/prometheus-test $
從上面我們可以觀察到 prometheus.yml 文件被掛載為目錄而不是文件。 任何人都可以讓我知道這件事。
操作系統:Ubuntu 20.04 這是一個運行在 ESXI 服務器上的 vm 實例
-bash-5.0# docker version
Client: Docker Engine - Community
Version: 19.03.10
API version: 1.40
Go version: go1.13.10
Git commit: 9424aeaee9
Built: Thu May 28 22:16:52 2020
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 633a0ea838f10e000b7c6d6eed1623e6e988b5bb
Built: Sat May 9 16:43:52 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.3.2
GitCommit: ff48f57fc83a8c44cf4ad5d672424a98ba37ded6
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit:
-bash-5.0#
-bash-5.0#
-bash-5.0#
-bash-5.0# docker context ls
NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm
-bash-5.0#
我認為您可能使事情過於復雜。 鑒於此docker-compose.yaml
:
version: '3'
volumes:
prometheus_data:
services:
prometheus:
image: prom/prometheus:v2.35.0
container_name: prometheus
volumes:
- ./prometheus:/etc/prometheus
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.agent.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--web.enable-lifecycle'
- '--enable-feature=agent'
而這個目錄結構:
$ tree .
.
├── docker-compose.yaml
└── prometheus
└── prometheus.yml
它只是工作:
$ docker-compose up
Starting prometheus ... done
Attaching to prometheus
prometheus | ts=2022-05-13T12:12:16.206Z caller=main.go:187 level=info msg="Experimental agent mode enabled."
prometheus | ts=2022-05-13T12:12:16.207Z caller=main.go:525 level=info msg="Starting Prometheus" version="(version=2.35.0, branch=HEAD, revision=6656cd29fe6ac92bab91ecec0fe162ef0f187654)"
prometheus | ts=2022-05-13T12:12:16.207Z caller=main.go:530 level=info build_context="(go=go1.18.1, user=root@cf6852b14d68, date=20220421-09:53:42)"
prometheus | ts=2022-05-13T12:12:16.207Z caller=main.go:531 level=info host_details="(Linux 5.17.5-100.fc34.x86_64 #1 SMP PREEMPT Thu Apr 28 16:02:54 UTC 2022 x86_64 02da15afa8e7 (none))"
prometheus | ts=2022-05-13T12:12:16.207Z caller=main.go:532 level=info fd_limits="(soft=1073741816, hard=1073741816)"
prometheus | ts=2022-05-13T12:12:16.207Z caller=main.go:533 level=info vm_limits="(soft=unlimited, hard=unlimited)"
prometheus | ts=2022-05-13T12:12:16.208Z caller=web.go:541 level=info component=web msg="Start listening for connections" address=0.0.0.0:9090
prometheus | ts=2022-05-13T12:12:16.208Z caller=main.go:1013 level=info msg="Starting WAL storage ..."
prometheus | ts=2022-05-13T12:12:16.212Z caller=db.go:332 level=info msg="replaying WAL, this may take a while" dir=/prometheus/wal
prometheus | ts=2022-05-13T12:12:16.213Z caller=tls_config.go:195 level=info component=web msg="TLS is disabled." http2=false
prometheus | ts=2022-05-13T12:12:16.214Z caller=db.go:383 level=info msg="WAL segment loaded" segment=0 maxSegment=1
prometheus | ts=2022-05-13T12:12:16.214Z caller=db.go:383 level=info msg="WAL segment loaded" segment=1 maxSegment=1
prometheus | ts=2022-05-13T12:12:16.215Z caller=main.go:1034 level=info fs_type=XFS_SUPER_MAGIC
prometheus | ts=2022-05-13T12:12:16.215Z caller=main.go:1037 level=info msg="Agent WAL storage started"
prometheus | ts=2022-05-13T12:12:16.215Z caller=main.go:1162 level=info msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
prometheus | ts=2022-05-13T12:12:16.216Z caller=dedupe.go:112 component=remote level=info remote_name=b4f547 url=http://10.120.23.224:9090/api/v1/write msg="Starting WAL watcher" queue=b4f547
prometheus | ts=2022-05-13T12:12:16.216Z caller=dedupe.go:112 component=remote level=info remote_name=b4f547 url=http://10.120.23.224:9090/api/v1/write msg="Starting scraped metadata watcher"
prometheus | ts=2022-05-13T12:12:16.216Z caller=main.go:1199 level=info msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml totalDuration=809.925µs db_storage=275ns remote_storage=282.833µs web_handler=394ns query_engine=377ns scrape=211.707µs scrape_sd=43.033µs notify=609ns notify_sd=911ns rules=143ns tracing=1.98µs
prometheus | ts=2022-05-13T12:12:16.216Z caller=main.go:930 level=info msg="Server is ready to receive web requests."
prometheus | ts=2022-05-13T12:12:16.216Z caller=dedupe.go:112 component=remote level=info remote_name=b4f547 url=http://10.120.23.224:9090/api/v1/write msg="Replaying WAL" queue=b4f547
prometheus | ts=2022-05-13T12:12:22.558Z caller=dedupe.go:112 component=remote level=info remote_name=b4f547 url=http://10.120.23.224:9090/api/v1/write msg="Done replaying WAL" duration=6.341973747s
如果失敗,第一個診斷步驟可能是從docker-compose.yaml
中刪除command
部分並添加如下entrypoint
點:
version: '3'
volumes:
prometheus_data:
services:
prometheus:
image: prom/prometheus:v2.35.0
container_name: prometheus
volumes:
- ./prometheus:/etc/prometheus
- prometheus_data:/prometheus
entrypoint:
- sleep
- inf
這將出現並運行sleep
,允許您將docker-compose exec
放入容器並探索文件系統。 如果您發現/etc/prometheus
為空,則表明您沒有在與 docker 守護進程相同的系統上運行docker-compose
(因此,當它嘗試引用主機路徑時,例如./prometheus
,它不會找不到它)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.