Skip to content

Instantly share code, notes, and snippets.

@danilochilene
Created May 16, 2015 18:24
Show Gist options
  • Save danilochilene/96a3450402a21ff43fb1 to your computer and use it in GitHub Desktop.
Save danilochilene/96a3450402a21ff43fb1 to your computer and use it in GitHub Desktop.
Get total vms from Vmware and send to InfluxDB
from vpoller.client import VPollerClient
import json
from influxdb.influxdb08 import InfluxDBClient
client = VPollerClient(endpoint='tcp://localhost:10123')
def get_total_vms():
msg = {'method': 'vm.discover', 'hostname': '1.1.1.1'}
r = json.loads(client.run(msg))
data = [
{
'name': 'vmware',
'columns': ['name', 'location', 'value'],
'points': [
['total_vms', 'Central Data Center', len(r['result'])]
]
}
]
return data
def send_to_influx(data):
'''Send data to InfluxDB'''
client = InfluxDBClient(
'localhost', 8086, 'monitor', 'monitor', 'vmware')
client.write_points(data)
send_to_influx(get_total_vms())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment