pryorda / vmware_exporter

VMWare vCenter Exporter for Prometheus
BSD 3-Clause "New" or "Revised" License
523 stars 199 forks source link

vmware-exporter docker two instances vsphere #393

Open miavi opened 7 months ago

miavi commented 7 months ago

Hi good day to all.

I currently have 1 docker container (https://hub.docker.com/r/pryorda/vmware_exporter) configured for 2 vsphere instances

The problem I have is that the data is interleaved when the 2 instances are active in the Prometheus job (with only 1 instance this problem does not exist)

this is the configuration

docker-compose.yaml

vmware-exporter
container_name: vmware-exporter
hostname: vmware-exporter
image: pryorda/vmware_exporter:v0.18.4
volumes:
./config.yml:/opt/vmware/config.yml
coomand: ["-c", "config.yml}

config.yml

default:
    vsphere_host: "x.x.x.x."
    vsphere_user: "user"
    vsphere_password: "password"
    ignore_ssl: True
    specs_size: 5000
    fetch_custom_attributes: True
    fetch_tags: True
    fetch_alarms: True
    collect_only:
        vms: True
        vmguests: True
        datastores: True
        hosts: True
        snapshots: True

  cpd2:
    vsphere_host: "y.y.y.y"
    vsphere_user: "user"
    vsphere_password: "password"
    ignore_ssl: True
    specs_size: 5000
    fetch_custom_attributes: True
    fetch_tags: True
    fetch_alarms: True
    collect_only:
        vms: True
        vmguests: True
        datastores: True
        hosts: True
        snapshots: True

prometheus job

- job_name: vmware_export
scrape_timeout: 40s
scrape_interval: 40s    
metrics_path: /metrics
scheme: "https"
tls_config:
       insecure_skip_verify: true
 static_configs:
 - targets:
      - x.x.x.x
      - y.y.y.y
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: DNS_vmware_exporter:port

When I perform a query with Prometheus, for example "vmware_host_hardware_info" it shows me in the x.x.x.x instance the hostname of y.y.y.y and vice versa, it is as if the metrics were mixed

On the other hand, if I set up two independent containers (on a different port), each container pointing to 1 vsphere host and then 2 different jobs in Prometheus, this problem does not occur.

Even when the config.yml only has a "default" section and is not multi-room, it works correctly and does not mix the data

It could be a bug when configuring a .yml file with vsphere multistay

In advanced very thanks

mbrother2 commented 5 months ago

Hi miavi,

You can access second host with URL http://YOUR_IP:9275/metrics?section=cpd2

chinotseng commented 5 months ago

My configuration file is as follows, and it works fine. ( Thank you mbrother2, for pointing out the key point. )

vmware_exporter config.yml

default:
    vsphere_host: "192.168.1.4"
    vsphere_user: "ADMIN@vsphere.local"
    vsphere_password: "PASSWORD"
    ignore_ssl: True
    specs_size: 2000
    fetch_custom_attributes: True
    fetch_tags: True
    fetch_alarms: True
    collect_only:
        vms: True
        vmguests: True
        datastores: True
        hosts: True
        snapshots: True

vc02:
    vsphere_host: "192.168.2.2"
    vsphere_user: "ADMIN@vsphere.local"
    vsphere_password: "PASSWORD"
    ignore_ssl: True
    specs_size: 2000
    fetch_custom_attributes: True
    fetch_tags: True
    fetch_alarms: True
    collect_only:
        vms: True
        vmguests: True
        datastores: True
        hosts: True
        snapshots: True

prometheus.yml

  - job_name: 'vmware_exporter'
    scrape_interval: 1m
    scrape_timeout: 1m
    metrics_path: '/metrics'
    static_configs:
      - targets:
        - '192.168.1.4'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9272

  - job_name: 'vc02'
    static_configs:
      - targets:
        - '127.0.0.1:9272'
    params:
      section: ['vc02']
miavi commented 5 months ago

Thank you both very much for the information, I will try this configuration