Use OpenStack API to collect the status of Cinder workers
This change uses the Cinder API to get the status of the Cinder workers instead of querying the MySQL database. Change-Id: If92596b3cee8a4c9f0dcf84454fdff2a2532160f Partial-Bug: #1546188
This commit is contained in:
parent
4e5f35e3a6
commit
e60e187f32
|
@ -364,14 +364,6 @@ if $influxdb_mode != 'disabled' {
|
|||
password => $nova['db_password'],
|
||||
}
|
||||
|
||||
lma_collector::collectd::dbi_services { 'cinder':
|
||||
username => 'cinder',
|
||||
dbname => 'cinder',
|
||||
password => $cinder['db_password'],
|
||||
report_interval => 60,
|
||||
downtime_factor => 2,
|
||||
}
|
||||
|
||||
unless $contrail {
|
||||
lma_collector::collectd::dbi_services { 'neutron':
|
||||
username => 'neutron',
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
#
|
||||
# Collectd plugin for getting statistics from Cinder
|
||||
import collectd
|
||||
from collections import Counter
|
||||
from collections import defaultdict
|
||||
import re
|
||||
|
||||
import base
|
||||
import collectd_openstack as openstack
|
||||
|
@ -26,12 +29,39 @@ INTERVAL = openstack.INTERVAL
|
|||
class CinderStatsPlugin(openstack.CollectdPlugin):
|
||||
""" Class to report the statistics on Cinder service.
|
||||
|
||||
state of agents
|
||||
number of volumes broken down by state
|
||||
total size of volumes usable and in error state
|
||||
"""
|
||||
|
||||
states = {'up': 0, 'down': 1, 'disabled': 2}
|
||||
cinder_re = re.compile('^cinder-')
|
||||
|
||||
@base.read_callback_wrapper
|
||||
def read_callback(self):
|
||||
|
||||
# Get information of the state per service
|
||||
# State can be: 'up', 'down' or 'disabled'
|
||||
aggregated_workers = defaultdict(Counter)
|
||||
|
||||
for worker in self.iter_workers('cinder'):
|
||||
host = worker['host'].split('.')[0]
|
||||
service = self.cinder_re.sub('', worker['service'])
|
||||
state = worker['state']
|
||||
|
||||
aggregated_workers[service][state] += 1
|
||||
self.dispatch_value('cinder_service', '',
|
||||
self.states[state],
|
||||
{'host': host,
|
||||
'service': service,
|
||||
'state': state})
|
||||
|
||||
for service in aggregated_workers:
|
||||
for state in self.states:
|
||||
self.dispatch_value('cinder_services', '',
|
||||
aggregated_workers[service][state],
|
||||
{'state': state, 'service': service})
|
||||
|
||||
volumes_details = self.get_objects_details('cinder', 'volumes')
|
||||
|
||||
def groupby(d):
|
||||
|
@ -63,7 +93,7 @@ class CinderStatsPlugin(openstack.CollectdPlugin):
|
|||
for n, size in sizes.iteritems():
|
||||
self.dispatch_value('snapshots_size', n, size)
|
||||
|
||||
def dispatch_value(self, plugin_instance, name, value):
|
||||
def dispatch_value(self, plugin_instance, name, value, meta=None):
|
||||
v = collectd.Values(
|
||||
plugin=PLUGIN_NAME, # metric source
|
||||
plugin_instance=plugin_instance,
|
||||
|
@ -71,7 +101,7 @@ class CinderStatsPlugin(openstack.CollectdPlugin):
|
|||
type_instance=name,
|
||||
interval=INTERVAL,
|
||||
# w/a for https://github.com/collectd/collectd/issues/716
|
||||
meta={'0': True},
|
||||
meta=meta or {'0': True},
|
||||
values=[value]
|
||||
)
|
||||
v.dispatch()
|
||||
|
|
|
@ -230,9 +230,20 @@ function process_message ()
|
|||
msg['Fields']['state'] = sample['type_instance']
|
||||
end
|
||||
elseif metric_source == 'cinder' then
|
||||
msg['Fields']['name'] = 'openstack' .. sep .. 'cinder' .. sep .. replace_dot_by_sep(sample['plugin_instance'])
|
||||
msg['Fields']['tag_fields'] = { 'state' }
|
||||
msg['Fields']['state'] = sample['type_instance']
|
||||
if sample['plugin_instance'] == 'cinder_services' or
|
||||
sample['plugin_instance'] == 'cinder_service' then
|
||||
msg['Fields']['name'] = 'openstack_' .. sample['plugin_instance']
|
||||
msg['Fields']['tag_fields'] = { 'service', 'state' }
|
||||
msg['Fields']['service'] = sample['meta']['service']
|
||||
msg['Fields']['state'] = sample['meta']['state']
|
||||
if sample['plugin_instance'] == 'cinder_service' then
|
||||
msg['Fields']['hostname'] = sample['meta']['host']
|
||||
end
|
||||
else
|
||||
msg['Fields']['name'] = 'openstack' .. sep .. 'cinder' .. sep .. replace_dot_by_sep(sample['plugin_instance'])
|
||||
msg['Fields']['tag_fields'] = { 'state' }
|
||||
msg['Fields']['state'] = sample['type_instance']
|
||||
end
|
||||
elseif metric_source == 'glance' then
|
||||
-- TODO(pasquier-s): check if the collectd plugin can send state as type_instance
|
||||
local resource, visibility, state = string.match(sample['type_instance'], '^([^.]+)%.([^.]+)%.(.+)$')
|
||||
|
@ -320,17 +331,6 @@ function process_message ()
|
|||
msg['Fields'][additional_tag] = sample['type_instance']
|
||||
end
|
||||
end
|
||||
elseif metric_source == 'dbi' and sample['plugin_instance'] == 'services_cinder' then
|
||||
local service, state, hostname = split_service_and_state_and_hostname(sample['type_instance'])
|
||||
if hostname then
|
||||
msg['Fields']['name'] = 'openstack' .. sep .. 'cinder' .. sep .. 'service'
|
||||
msg['Fields']['hostname'] = hostname
|
||||
else
|
||||
msg['Fields']['name'] = 'openstack' .. sep .. 'cinder' .. sep .. 'services'
|
||||
end
|
||||
msg['Fields']['tag_fields'] = { 'service', 'state' }
|
||||
msg['Fields']['service'] = service
|
||||
msg['Fields']['state'] = state
|
||||
elseif metric_source == 'dbi' and sample['plugin_instance'] == 'agents_neutron' then
|
||||
local service, state, hostname = split_service_and_state_and_hostname(sample['type_instance'])
|
||||
if hostname then
|
||||
|
|
Loading…
Reference in New Issue