使用 Docker Compose 设置 Prometheus
Set up Prometheus with Docker Compose
我是 Prometheus 和 Docker Compose 的新手。我有一个带有 docker-compose.yml
文件的项目结构,用于设置 Prometheus 和 Grafana:
/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:docker-compose up -d
,我在 http://localhost:9000/graph
上使用了 Prometheus,但我没有看到我添加到 prometheus.yml
的新配置,在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,它希望它的配置文件正好在这个位置。
因为您已经配置了以下挂载点:
volumes:
- ./prometheus:/etc/prometheus
- prometheus-data:/prometheus
您只需要将配置文件放入 ./prometheus
并将其命名为 prometheus.yml
我是 Prometheus 和 Docker Compose 的新手。我有一个带有 docker-compose.yml
文件的项目结构,用于设置 Prometheus 和 Grafana:
/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:docker-compose up -d
,我在 http://localhost:9000/graph
上使用了 Prometheus,但我没有看到我添加到 prometheus.yml
的新配置,在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,它希望它的配置文件正好在这个位置。
因为您已经配置了以下挂载点:
volumes:
- ./prometheus:/etc/prometheus
- prometheus-data:/prometheus
您只需要将配置文件放入 ./prometheus
并将其命名为 prometheus.yml