我正在尝试设置prometheus来使用django-prometheus和Docker来监视Django应用程序。我一直在在线上跟踪一些指南,但与我所看到的所有指南不同,我现在想在本地运行Django,所以现在只需运行python manage.py runserver,然后使用docker运行prometheus (然后添加grafana)。我想这样做是为了在本地测试它,稍后我将把它部署到Kubernetes,但是这是另一集。
我的问题是让本地运行的django服务器在与prometheus运行容器相同的网络中进行通信,因为我在prometheus仪表板上的/targets中得到了这个错误:
Get "http://127.0.0.1:5000/metrics": dial tcp 127.0.0.1:5000: connect: connection refused这些是我的坞-撰写文件和prometheus配置:
docker-compose.ymlversion: '3.6'
services:
prometheus:
image: prom/prometheus
volumes:
- ./prometheus/:/etc/prometheus/
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- 9090:9090prometheus.yamlglobal:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: prometheus
static_configs:
- targets:
- localhost:9090
- job_name: django-app
static_configs:
- targets:
- localhost:8000
- 127.0.0.1:8000发布于 2021-10-13 15:40:04
如果您想在(容器和外部) Docker之外运行Django应用程序,那么当运行时,它将绑定到主机的一个端口。
您还需要让Docker prometheus服务绑定到主机的网络。
您应该能够使用network_mode: host在prometheus服务下完成此操作。
然后,prometheus将能够访问它正在使用的主机端口上的Django应用程序,并且prometheus可以作为localhost:9090访问(而不需要ports部分)。
https://stackoverflow.com/questions/69558044
复制相似问题