Add metrics for Nova aggregates

Change-Id: I6647600d73991bfbfc7b7c199a7f9b90b9294f68
This commit is contained in:
Olivier Bourdon 2017-01-16 06:06:19 +01:00
parent 73817fba86
commit da8188d8cb
4 changed files with 85 additions and 3 deletions

View File

@ -5,6 +5,8 @@ lma_collector:
collected_on: aggregator
openstack_nova_total_free_ram:
collected_on: aggregator
openstack_nova_aggregate_free_ram_percent:
collected_on: aggregator
http_check:
collected_on: aggregator
openstack_check_api:

View File

@ -55,6 +55,22 @@ class HypervisorStatsPlugin(openstack.CollectdPlugin):
v.dispatch()
def collect(self):
nova_aggregates = {}
r = self.get('nova', 'os-aggregates')
if not r:
self.logger.warning("Could not get nova aggregates")
else:
aggregates_list = r.json().get('aggregates', [])
for agg in aggregates_list:
nova_aggregates[agg['name']] = {
'id': agg['id'],
'hosts': agg['hosts'],
'metrics': {'free_vcpus': 0},
}
nova_aggregates[agg['name']]['metrics'].update(
{v: 0 for v in self.VALUE_MAP.values()}
)
r = self.get('nova', 'os-hypervisors/detail')
if not r:
self.logger.warning("Could not get hypervisor statistics")
@ -67,14 +83,48 @@ class HypervisorStatsPlugin(openstack.CollectdPlugin):
# remove domain name and keep only the hostname portion
host = stats['hypervisor_hostname'].split('.')[0]
for k, v in self.VALUE_MAP.iteritems():
self.dispatch_value(v, stats.get(k, 0), {'host': host})
total_stats[v] += stats.get(k, 0)
m_val = stats.get(k, 0)
self.dispatch_value(v, m_val, {'host': host})
total_stats[v] += m_val
for agg in nova_aggregates.keys():
agg_hosts = nova_aggregates[agg]['hosts']
if stats['hypervisor_hostname'] in agg_hosts:
nova_aggregates[agg]['metrics'][v] += m_val
if 'cpu_ratio' in self.extra_config:
m_vcpus = stats.get('vcpus', 0)
m_vcpus_used = stats.get('vcpus_used', 0)
free = (int(self.extra_config['cpu_ratio'] *
stats.get('vcpus', 0))) - stats.get('vcpus_used', 0)
m_vcpus)) - m_vcpus_used
self.dispatch_value('free_vcpus', free, {'host': host})
total_stats['free_vcpus'] += free
for agg in nova_aggregates.keys():
agg_hosts = nova_aggregates[agg]['hosts']
if stats['hypervisor_hostname'] in agg_hosts:
free = ((int(self.extra_config['cpu_ratio'] *
m_vcpus)) -
m_vcpus_used)
nova_aggregates[agg]['metrics']['free_vcpus'] += free
# Dispatch the aggregate metrics
for agg in nova_aggregates.keys():
agg_id = nova_aggregates[agg]['id']
agg_total_free_ram = (
nova_aggregates[agg]['metrics']['free_ram_MB'] +
nova_aggregates[agg]['metrics']['used_ram_MB']
)
# Only emit metric when value is > 0
# If this is not the case, (for instance when no host
# in aggregate), this requires the corresponding alarms to
# have a 'skip' no_data_policy, so as not to be triggered
if agg_total_free_ram > 0:
nova_aggregates[agg]['metrics']['free_ram_percent'] = round(
(100.0 * nova_aggregates[agg]['metrics']['free_ram_MB']) /
agg_total_free_ram,
2)
for k, v in nova_aggregates[agg]['metrics'].iteritems():
self.dispatch_value('aggregate_{}'.format(k), v,
{'aggregate': agg,
'aggregate_id': agg_id})
# Dispatch the global metrics
for k, v in total_stats.iteritems():
self.dispatch_value('total_{}'.format(k), v)

View File

@ -227,6 +227,14 @@ function process_message ()
if sample['meta'] and sample['meta']['host'] then
msg['Fields']['hostname'] = sample['meta']['host']
end
if sample['meta'] and sample['meta']['aggregate'] then
msg['Fields']['aggregate'] = sample['meta']['aggregate']
table.insert(msg['Fields']['tag_fields'], 'aggregate')
end
if sample['meta'] and sample['meta']['aggregate_id'] then
msg['Fields']['aggregate_id'] = sample['meta']['aggregate_id']
table.insert(msg['Fields']['tag_fields'], 'aggregate_id')
end
elseif metric_source == 'rabbitmq_info' then
msg['Fields']['name'] = 'rabbitmq' .. sep .. sample['type_instance']
if sample['meta'] and sample['meta']['queue'] then

View File

@ -52,6 +52,28 @@ The following metrics are emitted per compute node:
* ``openstack_nova_used_vcpus``, the number of virtual CPU used by the
instances.
If Nova aggregates are defined then the following metrics are emitted per
aggregate. These metrics contain a ``aggregate``
field containing the aggregate name and a ``aggregate_id`` field containing the
ID (integer) of the aggregate.
* ``openstack_nova_aggregate_free_disk``, the total amount of disk space in GB
available in given aggregate for new instances.
* ``openstack_nova_aggregate_free_ram``, the total amount of memory in MB available
in given aggregate for new instances.
* ``openstack_nova_aggregate_free_vcpus``, the total number of virtual CPU
available in given aggregate for new instances.
* ``openstack_nova_aggregate_running_instances``, the total number of running
instances in given aggregate.
* ``openstack_nova_aggregate_running_tasks``, the total number of tasks currently
executed in given aggregate.
* ``openstack_nova_aggregate_used_disk``, the total amount of disk space in GB
used by the instances in given aggregate.
* ``openstack_nova_aggregate_used_ram``, the total amount of memory in MB used by
the instances in given aggregate.
* ``openstack_nova_aggregate_used_vcpus``, the total number of virtual CPU used by
the instances in given aggregate.
The following metrics are retrieved from the Nova API and represent the
aggregated values across all compute nodes.