Esempio n. 1
0
class MonitorMetric(base.NovaObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    fields = {
        'name': fields.MonitorMetricTypeField(nullable=False),
        'value': fields.IntegerField(nullable=False),
        'timestamp': fields.DateTimeField(nullable=False),
        # This will be the stevedore extension full class name
        # for the plugin from which the metric originates.
        'source': fields.StringField(nullable=False),
    }

    # NOTE(jaypipes): This method exists to convert the object to the
    # format expected by the RPC notifier for metrics events.
    def to_dict(self):
        return {
            'name': self.name,
            'value': self.value,
            # NOTE(jaypipes): This is what jsonutils.dumps() does to
            # datetime.datetime objects, which is what timestamp is in
            # this object as well as the original simple dict metrics
            'timestamp': timeutils.strtime(self.timestamp),
            'source': self.source
        }
Esempio n. 2
0
 def setUp(self):
     super(TestMonitorMetricType, self).setUp()
     self.field = fields.MonitorMetricTypeField()
     self.coerce_good_values = [
         ('cpu.frequency', 'cpu.frequency'),
         ('cpu.user.time', 'cpu.user.time'),
         ('cpu.kernel.time', 'cpu.kernel.time'),
         ('cpu.idle.time', 'cpu.idle.time'),
         ('cpu.iowait.time', 'cpu.iowait.time'),
         ('cpu.user.percent', 'cpu.user.percent'),
         ('cpu.kernel.percent', 'cpu.kernel.percent'),
         ('cpu.idle.percent', 'cpu.idle.percent'),
         ('cpu.iowait.percent', 'cpu.iowait.percent'),
         ('cpu.percent', 'cpu.percent')
     ]
     self.coerce_bad_values = ['cpu.typo']
     self.to_primitive_values = self.coerce_good_values[0:1]
     self.from_primitive_values = self.coerce_good_values[0:1]
Esempio n. 3
0
class MonitorMetric(base.NovaObject):
    # Version 1.0: Initial version
    # Version 1.1: Added NUMA support

    VERSION = '1.1'

    fields = {
        'name': fields.MonitorMetricTypeField(nullable=False),
        'value': fields.IntegerField(nullable=False),
        'numa_membw_values': fields.DictOfIntegersField(nullable=True),
        'timestamp': fields.DateTimeField(nullable=False),
        # This will be the stevedore extension full class name
        # for the plugin from which the metric originates.
        'source': fields.StringField(nullable=False),
    }

    def obj_make_compatible(self, primitive, target_version):
        super(MonitorMetric, self).obj_make_compatible(primitive,
                                                       target_version)
        target_version = utils.convert_version_to_tuple(target_version)
        if target_version < (1, 1) and 'numa_nodes_values' in primitive:
            del primitive['numa_membw_values']

    # NOTE(jaypipes): This method exists to convert the object to the
    # format expected by the RPC notifier for metrics events.
    def to_dict(self):
        dict_to_return = {
            'name': self.name,
            # NOTE(jaypipes): This is what jsonutils.dumps() does to
            # datetime.datetime objects, which is what timestamp is in
            # this object as well as the original simple dict metrics
            'timestamp': timeutils.strtime(self.timestamp),
            'source': self.source,
        }

        if self.obj_attr_is_set('value'):
            if self.name in FIELDS_REQUIRING_CONVERSION:
                dict_to_return['value'] = self.value / 100.0
            else:
                dict_to_return['value'] = self.value
        elif self.obj_attr_is_set('numa_membw_values'):
            dict_to_return['numa_membw_values'] = self.numa_membw_values

        return dict_to_return