我正在运行多个网站,并在一个使用traefik作为反向代理的系统上使用docker-compose进行监视。每个网站都可以从外部和主机本身访问,但是Prometheus本身无法从同一主机上的网站中获取指标。
因此从我的本地计算机或主机上的命令行进行的telnet连接返回200:
$ telnet api.dev.inowas.com 80
Trying 142.93.175.226...
Connected to api.dev.inowas.com.
...
prometheus容器中的同一命令未连接
$ /prometheus $ telnet api.dev.inowas.com 80
...
与curl,nc等其他工具相同的结果。
我正在为此设置运行三个docker-compose配置。
version: '3.4'
services:
traefik:
image: traefik
restart: always
ports:
- "80:80"
- "443:443"
- "8080:8080"
networks:
- web
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik/acme.json:/acme.json
- ./traefik/traefik.toml:/traefik.toml
- ./traefik/logs:/logs
networks:
web:
external: true
version: '3.1'
services:
prometheus:
image: prom/prometheus:v2.1.0
volumes:
- ./prometheus/:/etc/prometheus/
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
expose:
- "9090"
labels:
- "traefik.docker.network=web"
- "traefik.enable=true"
- "traefik.frontend.rule=Host:prometheus.inowas.com"
- "traefik.port=9090"
- "traefik.protocol=http"
links:
- cadvisor:cadvisor
- alertmanager:alertmanager
depends_on:
- cadvisor
networks:
- web
restart: always
grafana:
image: grafana/grafana
user: "104"
depends_on:
- prometheus
expose:
- "3000"
volumes:
- grafana_data:/var/lib/grafana
- ./grafana/provisioning/:/etc/grafana/provisioning/
env_file:
- ./grafana/config.monitoring
networks:
- web
restart: always
labels:
- "traefik.docker.network=web"
- "traefik.enable=true"
- "traefik.frontend.rule=Host:monitoring.inowas.com"
- "traefik.port=3000"
- "traefik.protocol=http"
volumes:
prometheus_data: {}
grafana_data: {}
networks:
web:
external:
name: web
version: '3.4'
services:
php:
image: ${CONTAINER_REGISTRY_BASE}/php
build:
context: ./api
target: api_platform_php
<<: *cache
depends_on:
- db
# Comment out these volumes in production
volumes:
- ./api:/srv/api:rw,cached
# If you develop on Linux, uncomment the following line to use a bind-mounted host directory instead
# - ./api/var:/srv/api/var:rw
api:
image: ${CONTAINER_REGISTRY_BASE}/nginx
build:
context: ./api
target: api_platform_nginx
<<: *cache
depends_on:
- php
volumes:
- ./api/public:/srv/api/public:ro
labels:
- "traefik.docker.network=web"
- "traefik.enable=true"
- "traefik.basic.frontend.rule=Host:${HOST_URL}"
- "traefik.basic.port=80"
- "traefik.basic.protocol=http"
networks:
- web
- default
db:
image: postgres:10-alpine
environment:
- POSTGRES_DB=api
- POSTGRES_USER=api-platform
- POSTGRES_PASSWORD=${DB_PASSWORD}
volumes:
- ./docker/db/data:/var/lib/postgresql/data:rw
volumes:
db-data: {}
networks:
web:
external: true
我希望检索调用该网址的指标:
https://api.dev.inowas.com/metrics来自prometheus容器,因为我可以从任何其他主机执行此操作。