openstack-ansible-ops/cluster_metrics/templates/telegraf-plugins/kvm_virsh.py
Kevin Carter 229739377d Added kvm_virsh to telegraf plugins
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>
2017-01-10 18:02:49 +00:00

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()