0
votes

I have prometheus , nginx-vts , php and nginx-vts-exporter all in separated containers i'm trying to get metrics to prometheus from the exporter ,, it keeps telling me Get http://127.0.0.1:9913/metrics: dial tcp 127.0.0.1:9913: connect: connection refused

when i start the docker-compose file i get this this error
2019/03/01 17:42:55 fetchHTTP failed Get http://localhost/status/format/json: dial tcp 127.0.0.1:80: getsockopt: connection refused

this is my nginx.con file

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;


    }


}

this is my docker-compose file

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

this is my 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']
1
What's your docker-compose file looking like?Oliver
added the docker compose fileTyr_90
Please also post your prometheus.yml file.Oliver

1 Answers

0
votes

In your prometheus.yml file, you should use nginx-vts-exporter:9913 instead of 127.0.0.1:9913 as the target for the nginx exporter.Same for the prometheus target. Don't use 127.0.0.1 but the name of the container.

In addition, it looks like you need to configure the nginx exporter to scrape nginx:80 and not localhost to retrieve the status information. You can do that by setting the environment variable NGINX_HOST to http://nging/status/format/json for the nginx-vts-exporter container in your docker-compose file, something like this:

  nginx-vts-exporter:
      container_name:  Exporter
      image: sophos/nginx-vts-exporter:latest
      environment:
        - NGINX_HOST="http://nging/status/format/json"       
      ports:        
       - 9913:9913