229739377d
The KVM virsh plugin already existed however the setup was not using the new playbook plugin system. This change moves the kvm vish plugin into that system and updates the plugin to use the influxdb line format instead of the json format which was recently deprecated. Change-Id: Ib23a0a231044389aab5669dc0c467175cd220423 Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
28 lines
796 B
Python
28 lines
796 B
Python
#!/usr/bin/env python
|
|
import libvirt
|
|
import socket
|
|
|
|
return_data = dict()
|
|
conn = libvirt.openReadOnly()
|
|
try:
|
|
domains = conn.listDomainsID()
|
|
return_data['kvm_vms'] = len(domains)
|
|
return_data['kvm_total_vcpus'] = conn.getCPUMap()[0]
|
|
return_data['kvm_scheduled_vcpus'] = 0
|
|
for domain in domains:
|
|
return_data['kvm_scheduled_vcpus'] += conn.lookupByID(
|
|
domain
|
|
).maxVcpus()
|
|
return_data['kvm_host_id'] = abs(hash(socket.getfqdn()))
|
|
except Exception as exp:
|
|
raise SystemExit('Plugin failure -- Reason: "%s"' % exp)
|
|
else:
|
|
line_data = 'kvm '
|
|
for key, value in return_data.items():
|
|
line_data += '%s=%s,' % (key.replace(' ', '_'), value)
|
|
else:
|
|
line_data = line_data.rstrip(',')
|
|
print(line_data)
|
|
finally:
|
|
conn.close()
|