当我运行此命令时,它会创建 docker 容器,但显示退出状态 我无法启动它
我的目标是能够用自定义的 prometheus.yml 替换 prometheus.yml 文件来监视在 http://localhost:70/nginx_status 运行的 nginx
docker run -it -d --name prometheus3 -p 9090:9090 -v
/opt/docker/prometheus:/etc/prometheus prom/prometheus -
config.file=/etc/prometheus/prometheus.yml
这是我的 prometheus.yml 文件
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
scrape_timeout: 5s
static_configs:
- targets: ['localhost: 9090']
- job_name: 'node'
static_configs:
- targets: ['localhost: 70/nginx_status']
最佳答案
您应该能够通过运行以下命令查看已停止容器的日志:
docker 日志 prometheus3
无论如何,您的配置(至少)存在两个问题:
prometheus.yml 文件无效,prometheus 进程立即退出。
scrape_interval
和scrape_timeout
需要位于global
部分,并且缩进已关闭。请参阅下面的正确格式的 yml 文件示例。2.) 您不能只抓取
/nginx_status
端点,而是需要使用 nginx 导出器来为您提取指标。然后 Prometheus 服务器将抓取 nginx_exporter 以检索指标。您可以找到导出商列表here并选择一个适合您的。
一旦导出器运行,您需要将 Prometheus 指向导出器的地址,以便可以抓取它。
工作中的 prometheus.yml :
global:
scrape_interval: 5s
scrape_timeout: 5s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
static_configs:
- targets: ['<< host name and port of nginx exporter >>']
关于Docker prom/Prometheus 容器退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52160024/