def periodic_tasks(self, level): """ periodic task to get usage from openstack and check warning """ LOG.debug("looping calling get usage from openstack for level %s...." % level) for usage in self.request_usages(level): metric_list = monitor.convert_usages_to_metric(usage, level) utils.convert_mem_to_gb_for_monitor(metric_list) if CONF.need_alarm: LOG.debug(_("alarm for level %s."), level) eventlet.spawn_n(self.check_alarm, level, usage) eventlet.spawn_n(self.post_monitor, level, metric_list)
def test_convert_usages_to_metric(self): usages = { 'local_gb': { 'platform': [ { 'instance_id': 'uuid1', 'host': 'host1', 'project_id': 'xx1', 'local_gb': 40 }, { 'instance_id': 'uuid2', 'host': 'host2', 'project_id': 'xx2', 'local_gb': 20 } ], 'platform_remainder': 964, 'platform_used': 60, 'platform_capacity': 1024 }, 'servers': { 'platform': [ { 'instance_id': 'uuid1', 'host': 'host1', 'project_id': 'xx1', 'used': 1 }, { 'instance_id': 'uuid2', 'host': 'host2', 'project_id': 'xx2', 'used': 1 } ], 'platform_used': 2 } } result = monitor.convert_usages_to_metric(usages, models.PLATFORM_LEVEL) t = long(time.time() * 1000) expected = [ { 'dimensions': 'Platform=NVSPlatform', 'sampleCount': 1, 'value': 964, 'aggregationDimensions': '', 'createTime': t, 'unit': 'Gigabytes', 'metricName': 'remain_local_gb' }, { 'dimensions': 'Platform=NVSPlatform', 'sampleCount': 1, 'value': 60, 'aggregationDimensions': '', 'createTime': t, 'unit': 'Gigabytes', 'metricName': 'local_gb' }, { 'dimensions': 'Platform=NVSPlatform', 'sampleCount': 1, 'value': 1024, 'aggregationDimensions': '', 'createTime': t, 'unit': 'Gigabytes', 'metricName': 'total_local_gb' }, { 'dimensions': 'Platform=NVSPlatform', 'sampleCount': 1, 'value': 2, 'aggregationDimensions': '', 'createTime': t, 'unit': 'Count', 'metricName': 'servers' } ] self.assertEqual(expected, result)