我在分开的容器中都有prometheus,nginx-vts,php和nginx-vts-exporter,我正试图从导出器获取prometheus的指标,它一直告诉我Get http://127.0.0.1:9913/metrics:拨打tcp 127.0 .0.1:9913:连接:连接被拒绝
当我启动docker-compose文件时,出现此错误
2019/03/01 17:42:55 fetchHTTP失败获取http://localhost/status/format/json:拨打tcp 127.0.0.1:80:getsockopt:连接被拒绝
这是我的nginx.con文件
server
{
listen 80;
server_name localhost.x.com;
root /var/www/html/x.com;
index index.php index.html index.htm;
location /
{
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ \.php$ {
fastcgi_pass test-php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /status {
vhost_traffic_status_display;
vhost_traffic_status_bypass_stats on;
vhost_traffic_status_display_format html;
allow all;
}
}
这是我的docker-compose文件
version: '3'
services:
php:
container_name: php
image: php:fpm
volumes:
- ./code:/var/www/html/x
nginx:
container_name: Nginx
image: arquivei/nginx-vts:latest
volumes:
- ./code:/var/www/html/x.com
- ./site.conf:/etc/nginx/conf.d/x.conf:ro
ports:
- 80:80
links:
- nginx-vts-exporter
prom:
container_name: Prometheus
image: prom/prometheus:latest
volumes:
- ./monitor/prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- 9090:9090
nginx-vts-exporter:
container_name: Exporter
image: sophos/nginx-vts-exporter:latest
ports:
- 9913:9913
这是我的prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: nginx
static_configs:
- targets: ['127.0.0.1:9913']
- job_name: prometheus
static_configs:
- targets: ['127.0.0.1:9090']
答案 0 :(得分:0)
在prometheus.yml文件中,应使用nginx-vts-exporter:9913
而不是127.0.0.1:9913
作为nginx导出程序的目标。与prometheus目标相同。不要使用127.0.0.1,而是使用容器的名称。
此外,您似乎需要配置nginx导出器以刮除nginx:80
而不是localhost来检索状态信息。您可以通过将docker-compose文件中NGINX_HOST
容器的环境变量http://nging/status/format/json
设置为nginx-vts-exporter
来做到这一点,就像这样:
nginx-vts-exporter:
container_name: Exporter
image: sophos/nginx-vts-exporter:latest
environment:
- NGINX_HOST="http://nging/status/format/json"
ports:
- 9913:9913