【发布时间】:2019-02-07 04:26:50
【问题描述】:
我正在解决 Docker 中 Prometheus 和 python 应用程序之间的网络问题。如何让 Prometheus 能够在 docker 中抓取 python 应用程序生成的指标,并将其显示在 Prometheus 端。
Docker-compose.yml
version: '3'
services:
prometheus:
image: prom/prometheus:v2.0.0
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
links:
- web
web:
image: python:3.5-alpine
build: ./test
ports:
- "5000:8002"
Dockerfile:
FROM python:3.5-alpine
ADD app1.py /
RUN pip install prometheus_client
CMD ["python", "./app1.py"]
EXPOSE 8002
prometheus.yml
# my global config
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['docker.for.mac.host.internal:9090']
- job_name: 'python_app'
metrics_path: /
static_configs:
- targets: ['docker.for.mac.host.internal:8002']
到目前为止,我可以看到 Prometheus 运行良好,其目标的状态显示为 UP 在“docker.for.mac.host.internal:9090”和“docker.for.mac.host.internal:8002”上
python 应用程序也在运行,我可以在端口上看到输出指标
所以现在一切都应该正常了,Prometheus 可以通过指定端口抓取指标。但是那里没有这样的指标。
【问题讨论】:
-
您创建了一个名为“web”的链接,您是否尝试在“static_configs.targets”中使用它?像“网络:8002”之类的东西。 IMO 'docker.for.mac.host.internal' 仍然命中同一个容器 - 带有 prometheus 的容器。
标签: python docker containers prometheus