The values reported by a monitor depends on the type of value which will not be uniform for all the monitors. For example, the memory bandwidth monitor will return a dict of ints while the cpu monitor returns a normal int value. The monitor metric objects offer different fields to be set depending on the monitor in question. This patchset allows the monitors to decide what metric field it would like to populate as over a general implementation of creating the monitor metric object inside the base module. This would also help in exchanging versioned objects between the monitors and the compute drivers. Eventually this work will lead up to making the metrics.update notification as versioned. Related to blueprint memory-bw Co-Authored-By: Ahilan Rajadeva <rajadeva@us.ibm.com> Change-Id: Ieaf3d44bbe73e71ad877199bbbc779afa4218b51
78 lines
2.9 KiB
Python
78 lines
2.9 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import abc
|
|
|
|
import six
|
|
|
|
from nova.objects import fields
|
|
|
|
|
|
@six.add_metaclass(abc.ABCMeta)
|
|
class MonitorBase(object):
|
|
"""Base class for all resource monitor plugins.
|
|
|
|
A monitor is responsible for adding a set of related metrics to
|
|
a `nova.objects.MonitorMetricList` object after the monitor has
|
|
performed some sampling or monitoring action.
|
|
"""
|
|
|
|
def __init__(self, compute_manager):
|
|
self.compute_manager = compute_manager
|
|
self.source = None
|
|
|
|
@abc.abstractmethod
|
|
def get_metric_names(self):
|
|
"""Get available metric names.
|
|
|
|
Get available metric names, which are represented by a set of keys
|
|
that can be used to check conflicts and duplications
|
|
|
|
:returns: set containing one or more values from
|
|
:py:attr: nova.objects.fields.MonitorMetricType.ALL
|
|
"""
|
|
raise NotImplementedError('get_metric_names')
|
|
|
|
@abc.abstractmethod
|
|
def populate_metrics(self, metric_list):
|
|
"""Monitors are responsible for populating this metric_list object
|
|
with nova.objects.MonitorMetric objects with values collected via
|
|
the respective compute drivers.
|
|
|
|
Note that if the monitor class is responsible for tracking a *related*
|
|
set of metrics -- e.g. a set of percentages of CPU time allocated to
|
|
user, kernel, and idle -- it is the responsibility of the monitor
|
|
implementation to do a single sampling call to the underlying monitor
|
|
to ensure that related metric values make logical sense.
|
|
|
|
:param metric_list: A mutable reference of the metric list object
|
|
"""
|
|
raise NotImplementedError('populate_metrics')
|
|
|
|
|
|
class CPUMonitorBase(MonitorBase):
|
|
"""Base class for all monitors that return CPU-related metrics."""
|
|
|
|
def get_metric_names(self):
|
|
return set([
|
|
fields.MonitorMetricType.CPU_FREQUENCY,
|
|
fields.MonitorMetricType.CPU_USER_TIME,
|
|
fields.MonitorMetricType.CPU_KERNEL_TIME,
|
|
fields.MonitorMetricType.CPU_IDLE_TIME,
|
|
fields.MonitorMetricType.CPU_IOWAIT_TIME,
|
|
fields.MonitorMetricType.CPU_USER_PERCENT,
|
|
fields.MonitorMetricType.CPU_KERNEL_PERCENT,
|
|
fields.MonitorMetricType.CPU_IDLE_PERCENT,
|
|
fields.MonitorMetricType.CPU_IOWAIT_PERCENT,
|
|
fields.MonitorMetricType.CPU_PERCENT,
|
|
])
|