Skip to content

Prometheus file service discovery for vsphere VMs

License

Notifications You must be signed in to change notification settings

gopaytech/vmware-filesd

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a file discovery implementation utilizing VMware tags for Prometheus discovery

This repository utilizes code from Ansible VMware inventory and has been modified to work for Prometheus. It can be slow in large vmware environments.

An example of how to use it for Promethues operator:

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  labels:
    prometheus: po-prometheus-vmware-filesd
  name: po-prometheus-vmware-filesd
spec:
  containers:
    - name: vmware-filesd
      image: gopaytech/vmware-filesd:latest
      env:
        - name: HOSTNAME
          value: "10.0.0.1"
        - name: USERNAME
          value: "vmware-user"
        - name: PASSWORD
          value: "vmware-password"
        - name: OUTPUT
          value: "/opt/config/vmware-filesd.json"
        - name: FILTER
          value: '{"environment": "staging"}'
      volumeMounts:
        - name: config-out
          mountPath: /opt/config
          readOnly: false
  securityContext:
    fsGroup: 2000
    runAsNonRoot: true
    runAsUser: 1000
  serviceAccountName: po-prometheus-operator-prometheus
  serviceMonitorNamespaceSelector: {}
  serviceMonitorSelector:
    matchLabels:
      release: vmware-filesd
  additionalScrapeConfigs:
    name: additional-scrape-configs
    key: prometheus-additional.yaml

Example output

[
    {
        "targets": [
            "10.0.1.1"
        ],
        "labels": {
            "name": "host1",
            "address": "10.0.1.1",
            "description": "sample host",
            "component": "pg",
            "environment": "staging"
        }
    }
]

Prometheus will read this output as a file discovery. It can be imported and relabled like the following:

- job_name: "vmware/node-exporter"
  file_sd_configs:
    - files:
        - /etc/prometheus/config_out/vmware-filesd.json
  relabel_configs:
    - source_labels: [__address__]
      target_label: instance
    - source_labels: [__address__]
      target_label: __address__
      replacement: "${1}:9100"

- job_name: "vmware/pg-exporter"
  file_sd_configs:
    - files:
        - /etc/prometheus/config_out/vmware-filesd.json
  relabel_configs:
    - source_labels: [__address__]
      target_label: instance
    - source_labels: [component]
      regex: ^(?!(pg|postgres)$).*
      action: drop
    - source_labels: [__address__, component]
      target_label: __address__
      regex: "(.*);(pg)"
      replacement: "${1}:9187"
kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml

It can also be called from the commandline directly: python3 main.py --hostname $HOSTNAME --username $USERNAME --password $PASSWORD --output $OUTPUT --loop --notls --filter "$FILTER"

About

Prometheus file service discovery for vsphere VMs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 95.2%
  • Dockerfile 4.8%