Add ability to publish nova host aggregate info for libvirt metrics
This change will enable operators to view overall vm utilization data by nova host aggregate if they choose to. By specifying a regular expression matching host aggregate names in the new config file setting of 'host_aggregate_re', matching hypervisors will have the dimension of 'host_aggregate' published on operations metrics. Change-Id: Ifa298efc7362b123f5f4db97fd37cc0edc9a1686
This commit is contained in:
parent
6f3e984ca0
commit
38e9d102da
@ -73,14 +73,14 @@ If the owner of the VM is in a different tenant the Agent Cross-Tenant Metric Su
|
||||
|
||||
`vm_disks_check_enable` enables collecting of VM Disk metrics (Default True). Please see "Mapping Metrics to Configuration Parameters" section below for what metrics are controlled by this flag.
|
||||
|
||||
|
||||
`vm_network_check_enable` enables collecting of VM Network metrics (Default True). Please see "Mapping Metrics to Configuration Parameters" section below for what metrics are controlled by this flag.
|
||||
|
||||
|
||||
`vm_ping_check_enable` enable host alive ping check (Default True). Please see "Mapping Metrics to Configuration Parameters" section below for what metrics are controlled by this flag.
|
||||
|
||||
`vm_extended_disks_check_enable` enable collecting of extended Disk metrics (Default True). Please see "Mapping Metrics to Configuration Parameters" section below for what metrics are controlled by this flag.
|
||||
|
||||
`host_aggregate_re` can be used to specify a regular expression with which to match nova host aggregate names. If this hypervisor is a member of a host aggregate matching this regular expression, an additional dimension of `host_aggregate` will be published for the operations metrics (with a value of the host aggregate name).
|
||||
|
||||
Example config:
|
||||
```
|
||||
init_config:
|
||||
@ -100,6 +100,7 @@ init_config:
|
||||
/bin/ping -n -c1 -w1 -q
|
||||
alive_only: false
|
||||
network_use_bits: false
|
||||
host_aggregate_re: M[34]
|
||||
instances:
|
||||
- {}
|
||||
```
|
||||
@ -420,18 +421,19 @@ Please see table below for metrics in libvirt that are always enabled.
|
||||
## VM Dimensions
|
||||
All metrics include `resource_id` and `zone` (availability zone) dimensions. Because there is a separate set of metrics for the two target audiences (VM customers and Operations), other dimensions may differ.
|
||||
|
||||
| Dimension Name | Customer Value | Operations Value |
|
||||
| -------------- | ------------------------- | -------------------------------------------------------------- |
|
||||
| hostname | name of VM as provisioned | hypervisor's hostname |
|
||||
| zone | availability zone | availability zone |
|
||||
| resource_id | resource ID of VM | resource ID of VM |
|
||||
| service | "compute" | "compute" |
|
||||
| component | "vm" | "vm" |
|
||||
| device | name of net or disk dev | name of net or disk dev |
|
||||
| port_id | port ID of the VM port | port ID of the VM port |
|
||||
| tenant_id | (N/A) | owner of VM |
|
||||
| tenant_name | (N/A) | name of the project owner of the VM (if configured to publish) |
|
||||
| vm_name | (N/A) | name of the VM (if configured to publish) |
|
||||
| Dimension Name | Customer Value | Operations Value |
|
||||
| -------------- | ------------------------- | ----------------------------------------------------------------- |
|
||||
| hostname | name of VM as provisioned | hypervisor's hostname |
|
||||
| zone | availability zone | availability zone |
|
||||
| resource_id | resource ID of VM | resource ID of VM |
|
||||
| service | "compute" | "compute" |
|
||||
| component | "vm" | "vm" |
|
||||
| device | name of net or disk dev | name of net or disk dev |
|
||||
| port_id | port ID of the VM port | port ID of the VM port |
|
||||
| tenant_id | (N/A) | owner of VM |
|
||||
| tenant_name | (N/A) | name of the project owner of the VM (if configured to publish) |
|
||||
| vm_name | (N/A) | name of the VM (if configured to publish) |
|
||||
| host_aggregate | (N/A) | host aggregate name of this hypervisor (if configured to publish) |
|
||||
|
||||
## Aggregate Metrics
|
||||
|
||||
|
@ -20,6 +20,7 @@ import libvirt
|
||||
import math
|
||||
import monasca_agent.collector.checks.utils as utils
|
||||
import os
|
||||
import re
|
||||
import stat
|
||||
import subprocess
|
||||
import time
|
||||
@ -63,6 +64,7 @@ class LibvirtCheck(AgentCheck):
|
||||
self.use_bits = self.init_config.get('network_use_bits')
|
||||
|
||||
self._collect_intervals = {}
|
||||
self._host_aggregate = None
|
||||
|
||||
self._set_collection_intervals('disk', 'disk_collection_period')
|
||||
self._set_collection_intervals('vnic', 'vnic_collection_period')
|
||||
@ -138,6 +140,8 @@ class LibvirtCheck(AgentCheck):
|
||||
region_name=self.init_config.get('region_name'))
|
||||
instances = nova_client.servers.list(search_opts={'all_tenants': 1,
|
||||
'host': self.hostname})
|
||||
self._get_this_host_aggregate(nova_client)
|
||||
|
||||
# Lay the groundwork for fetching VM IPs and network namespaces
|
||||
if self.init_config.get('ping_check'):
|
||||
from neutronclient.v2_0 import client
|
||||
@ -703,6 +707,13 @@ class LibvirtCheck(AgentCheck):
|
||||
dims_customer[metadata] = metadata_value
|
||||
# Remove customer 'hostname' dimension, this will be replaced by the VM name
|
||||
del(dims_customer['hostname'])
|
||||
#
|
||||
# Add this hypervisor's host aggregate as a dimension if
|
||||
# configured to do so and we had a match on the regex for
|
||||
# this host.
|
||||
#
|
||||
if self._host_aggregate:
|
||||
dims_operations['host_aggregate'] = self._host_aggregate
|
||||
except TypeError:
|
||||
# Nova can potentially get into a state where it can't see an
|
||||
# instance, but libvirt can. This would cause TypeErrors as
|
||||
@ -812,3 +823,24 @@ class LibvirtCheck(AgentCheck):
|
||||
if metadata_value:
|
||||
dims[metadata] = metadata_value
|
||||
return dims
|
||||
|
||||
def _get_this_host_aggregate(self, nova_client):
|
||||
"""Determine the host aggregate for this hypervisor."""
|
||||
host_agg_cfg_re = self.init_config.get('host_aggregate_re', None)
|
||||
if not host_agg_cfg_re:
|
||||
return
|
||||
|
||||
try:
|
||||
agg_re = re.compile(host_agg_cfg_re)
|
||||
aggs = nova_client.aggregates.list()
|
||||
for idx, agg in enumerate(aggs):
|
||||
if re.match(agg_re, aggs[idx].name) and self.hostname in aggs[idx].hosts:
|
||||
self._host_aggregate = str(aggs[idx].name)
|
||||
#
|
||||
# Not expecting multiple matches, if we've got a match we're done.
|
||||
#
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
msg = "Failed to list host aggregates, won't publish aggregate dimension: '{0}'"
|
||||
self.log.error(msg.format(e))
|
||||
|
Loading…
x
Reference in New Issue
Block a user