prometheus.yml文件在AWS ECS上不会更新



我有一个带有Docker的多容器web服务应用程序。它的设置是为了让prometheus从同一容器上的web服务中读取并抓取它。当我在本地构建映像并导航到http://localhost:9090/config时,prometheus.yml文件与我在AWS ECS上运行时希望的文件相匹配:

version: "3.2"
global:
scrape_interval: 15s
scrape_timeout: 10s
evaluation_interval: 1m
scrape_configs:
- job_name: prometheus
honor_timestamps: true
scrape_interval: 5s
scrape_timeout: 5s
metrics_path: /metrics
scheme: http
follow_redirects: true
enable_http2: true
static_configs:
- targets:
- localhost:9090
- job_name: alienboard-web
honor_timestamps: true
scrape_interval: 10s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
follow_redirects: true
enable_http2: true
static_configs:
- targets:
- localhost:5000

在本地一切都按预期进行,普罗米修斯能够抓取web服务器";alienboard web";(它显示在localhost:9090/targets中(。然而,当我将编译后的映像推送到AWS时,一旦prometheus.yml文件位于ECS容器实例上,它似乎就永远不会更新它。以下是它在http:{aws-ecs-ip}:9090/config:中的样子

global:
scrape_interval: 15s
scrape_timeout: 10s
evaluation_interval: 15s
alerting:
alertmanagers:
- follow_redirects: true
enable_http2: true
scheme: http
timeout: 10s
api_version: v2
static_configs:
- targets: []
scrape_configs:
- job_name: prometheus
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
follow_redirects: true
enable_http2: true
static_configs:
- targets:
- localhost:9090

为什么不更新文件如果有帮助的话,我还会附上我的docker-compose、Dockerfile和prometheus.yml文件。

prometheus.yml:

# my global config
global:
scrape_interval:     15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['host.docker.internal:9090']
- job_name: 'alienboard-web'
scrape_interval: 10s
static_configs:
- targets: ['host.docker.internal:5000']

码头工人组成:

version: "3.2"
volumes:
grafana-data:
driver: local
prometheus-data:
driver: local
services:
area51-tracker:
build: ./
container_name: alienboard-web
restart: always
environment:
- PYTHONBUFFERED=1
ports:
- "80:80"
- "5000:5000"
networks:
- back-end
redis:
image: redis:6.0.8
network_mode: bridge
networks:
- back-end
grafana:
image: grafana/grafana-oss:latest
container_name: grafana
network_mode: bridge
ports:
- "3000:3000"
volumes:
- grafana-data:/var/lib/grafana
restart: unless-stopped
depends_on:
- area51-tracker
prometheus:
image: prom/prometheus:v2.38.0
container_name: prometheus
network_mode: bridge
ports:
- "9090:9090"
volumes:
- ./etc/prometheus:/etc/prometheus
- prometheus-data:/prometheus
restart: unless-stopped
command:
- "--config.file=/etc/prometheus/prometheus.yml"
depends_on:
- area51-tracker
networks:
back-end:
driver: bridge

Dockerfile:

# syntax=docker/dockerfile:1
FROM tiangolo/uwsgi-nginx-flask:python3.8
RUN apt-get update -y && 
apt-get install -y python-pip python-dev && 
pip install --upgrade pip
WORKDIR /area51-tracker
COPY . .
COPY './prometheus.yml' '/etc/prometheus/prometheus.yml'
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT [ "python" ]
CMD [ "application.py" ]

我的项目目录如下:

  • area51跟踪器

    • etc/prometheus
      • 普罗米修斯.yml

    application.py

谢谢!

嘿,对于任何可能偶然发现这个问题的人来说——我最终不得不创建一个以prom/prometheus为基础的单独图像。我在他们自己的目录中创建了一个单独的Dockerfile和prometheus.yml文件:

Dockerfile:

FROM prom/prometheus
ADD prometheus.yml /etc/prometheus/

prometheus.yml文件:

# my global config
global:
scrape_interval:     15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['host.docker.internal:9090']
- job_name: 'alienboard-web'
scrape_interval: 10s
static_configs:
- targets: ['{aws-instance-ip}:5000']

我从这些文件中构建了一个单独的映像,并将其推送到ECR自己的私有目录中。然后,我配置了任务定义,使prometheus容器使用新的映像。

这显然只是一个适合我特定需求的解决方案,所以我仍然很好奇是否有人有一个解决方案不需要重新构建映像来实现配置文件。我仍然不确定为什么构建会在本地加载配置,但不会在AWS上加载。

附录:当我ssh进入容器实例时,我可以看到prometheus.yml文件在那里(bin/etc/prometheus(,但它根本没有被使用。

最新更新