{\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf600 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} {\*\expandedcolortbl;;} \margl1440\margr1440\vieww25400\viewh19580\viewkind0 \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0 \f0\fs24 \cf0 import collectd\ from novaclient import client as NovaClient\ from novaclient import exceptions\ import traceback\ \ #== Our Own Functions go here: ==#\ def configer(ObjConfiguration):\ collectd.debug('Configuring Stuff') \ \ def initer():\ collectd.debug('initing stuff')\ \ def reader(input_data=None):\ metric = collectd.Values();\ metric.plugin = 'nova_plugin'\ metric.type = 'hypervisor_hostname_list'\ \ client = NovaClient.Client('2', \'91myuser\'92, \'91mypassword\'92, 'services', 'https://svl-fab7-lab1.cisco.com:5\ 000/v2.0')\ hypervisor_hostname_list = client.hypervisors.list()\ total_count = len(hypervisor_hostname_list)\ metric.values = [len(hypervisor_hostname_list)]\ metric.host = 'OverwritenHostname'\ metric.dispatch()\ for i in range(0, total_count): \ metric.type = 'hypervisor_hostname_current_workload'\ metric.values = [hypervisor_hostname_list[i].current_workload]\ metric.dispatch()\ metric.type = 'hypervisor_hostname_vcpus'\ metric.values = [hypervisor_hostname_list[i].vcpus]\ metric.dispatch()\ metric.type = 'hypervisor_hostname_version'\ metric.values = [hypervisor_hostname_list[i].hypervisor_version]\ metric.dispatch()\ metric.type = 'hypervisor_hostname_vcpus_used'\ metric.values = [hypervisor_hostname_list[i].vcpus_used]\ metric.dispatch()\ \ \ def write(val, data=None):\ '''Prepare value before writing '''\ client = NovaClient.Client('2', \'91myuser\'92, \'91mypassword\'92, 'services', 'https://svl-fab7-lab1.cisco.com:5\ 000/v2.0')\ hypervisor_hostname_list = client.hypervisors.list()\ for data in hypervisor_hostname_list[:]:\ hypervisor_hostname_current_workload = data.current_workload\ hypervisor_hostname_free_disk_gb = data.free_disk_gb\ hypervisor_hostname_free_RAM_mb = data.free_ram_mb\ hypervisor_hostname_version = data.hypervisor_version\ hypervisor_hostname_memory_mb = data.memory_mb\ hypervisor_hostname_memory_used_mb = data.memory_mb_used\ hypervisor_hostname_vcpus = data.vcpus\ hypervisor_hostname_vcpus_used = data.vcpus_used\ collectd.info('skher: writing data (val=%r, data=%r)' % (val, data))\ for v in val.values:\ collectd.info("skher: writing %s (%s): %f" % (val.plugin, val.type, v))\ \ #== Hook Callbacks, Order is important! ==#\ collectd.register_config(configer)\ collectd.register_init(initer)\ collectd.register_read(reader)\ collectd.register_write(write)\ }