Created
May 16, 2015 18:24
-
-
Save danilochilene/96a3450402a21ff43fb1 to your computer and use it in GitHub Desktop.
Get total vms from Vmware and send to InfluxDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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