A VM power state (vSphere) exporter for Prometheus Pushgateway. It is using vSphere vCenter official API
- Get token (key) from vSphere API using userpass
- API requests to vSphere vCenter to get data about host connection and power state, vm power state
- Parse gathered data
- Push to Prometheus Pushgateway
Download file: vc_host_vm_pw_state_exporter.sh, or just copy its content to the same files
You need to setup vars in the main file:
#!/bin/bash
userpass=""
vc_host=""
prom_pg_host="ip:port"
instance="localhost"
sleep_time=120
... (rest of a code)- userpass - username and password with Basic Authentication
- vc_host - vSphere host
- prom_pg_host - DNS name or ip + port of Prometheus Pushgateway
- instance - who sending metrics, default localhost
- sleep_time - how long (in seconds) to wait before next run, set 0 if you want to run script once, default 120
- Do
chmod +x ./vc_host_vm_pw_state_exporter.sh - Do
./vc_host_vm_pw_state_exporter.shor/bin/bash vc_host_vm_pw_state_exporter.sh
Create systemd service to autorun exporter:
[Unit]
Description=host/vm power state exporter
After=network.target
[Service]
Type=simple
ExecStart=/bin/bash /path/to/file/vc_host_vm_pw_state_exporter.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target