簡體   English   中英

用 Docker Compose 設置 Prometheus

[英]Set up Prometheus with Docker Compose

我是 Prometheus 和 Docker Compose 的新手。 我有一個項目結構,其中包含設置 Prometheus 和 Grafana 的docker-compose.yml文件: /prometheus-grafana/prometheus/docker-compose.yml

version: '3'

services:
prometheus:
image: prom/prometheus:v2.21.0
ports:
- 9000:9090
volumes:
- ./prometheus:/etc/prometheus
- prometheus-data:/prometheus
command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml

grafana:
image: grafana/grafana:$GRAFANA_VERSION
environment:
GF_SECURITY_ADMIN_USER: $GRAFANA_ADMIN_USER
GF_SECURITY_ADMIN_PASSWORD: $GRAFANA_ADMIN_PASSWORD
ports:
- 3000:3000
volumes:
- grafana-storage:/var/lib/grafana
depends_on:
- prometheus
networks:
- internal

networks:
internal:

volumes:
prometheus-data:
grafana-storage:

我只是像這樣在/prometheus-grafana/prometheus/prometheus/prometheus.yml添加了更多配置,我添加的部分是最后 3 行:

global:
scrape_interval: 30s
scrape_timeout: 10s

rule_files:
- alert.yml

scrape_configs:
- job_name: services
metrics_path: /metrics
static_configs:
- targets:
- 'prometheus:9090'
- 'idonotexists:564'
- job_name: myapp
scrape_interval: 10s
static_configs:
- targets:
- localhost:2112

我通過運行: prometheus.yml docker-compose up -d啟動Prometheus,我可以在http://localhost:9000/graph上使用Prometheus,但我沒有添加了新的docker-compose.yml 。線:

command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml

我是否也應該更改它是指我的項目中另一個/prometheus-grafana/prometheus/prometheus/prometheus.yml的路徑,而不是/etc/prometheus/prometheus.yml的路徑,因為實際上,這個文件不存在/etc/prometheus/prometheus.yml

先感謝您。

如果您使用--config.file=/etc/prometheus/prometheus.yml配置了 prometheus,它希望其配置文件與此 position 完全相同。

由於您已經配置了以下掛載點:

volumes:
- ./prometheus:/etc/prometheus
- prometheus-data:/prometheus

您只需將配置文件放入./prometheus並將其命名為prometheus.yml

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM