def test_null_data_source(self): """ By default, the NFVI metrics plugin mock installs a 'null' implementation that simply returns empty NFVI structures. """ status, metrics = self.plugin.nfvi_metrics(self.account, self.vim_id) self.assertEqual(status, RwTypes.RwStatus.SUCCESS) self.assertEqual(metrics, RwmonYang.NfviMetrics()) status, metrics = self.plugin.nfvi_vcpu_metrics(self.account, self.vim_id) self.assertEqual(status, RwTypes.RwStatus.SUCCESS) self.assertEqual(metrics, RwmonYang.NfviMetrics_Vcpu()) status, metrics = self.plugin.nfvi_memory_metrics(self.account, self.vim_id) self.assertEqual(status, RwTypes.RwStatus.SUCCESS) self.assertEqual(metrics, RwmonYang.NfviMetrics_Memory()) status, metrics = self.plugin.nfvi_storage_metrics(self.account, self.vim_id) self.assertEqual(status, RwTypes.RwStatus.SUCCESS) self.assertEqual(metrics, RwmonYang.NfviMetrics_Storage()) status, result = self.plugin.nfvi_metrics_available(self.account) self.assertEqual(status, RwTypes.RwStatus.SUCCESS) self.assertTrue(result)
def do_nfvi_metrics(self, account, vm_id): try: samples = self._get_driver(account).ceilo_nfvi_metrics(vm_id) metrics = RwmonYang.NfviMetrics() vcpu = samples.get("cpu_util", {}) memory = samples.get("memory_usage", {}) storage = samples.get("disk_usage", {}) metrics.vcpu.utilization = vcpu.get("volume", 0) metrics.memory.used = memory.get("volume", 0) metrics.storage.used = storage.get("volume", 0) def convert_timestamp(t): return dateutil.parser.parse(t).timestamp() timestamps = [] if 'timestamp' in vcpu: timestamps.append(convert_timestamp(vcpu['timestamp'])) if 'timestamp' in memory: timestamps.append(convert_timestamp(memory['timestamp'])) if 'timestamp' in storage: timestamps.append(convert_timestamp(storage['timestamp'])) metrics.timestamp = max(timestamps) if timestamps else 0.0 return metrics except Exception as e: logger.exception(e)
def __init__(self): self._metrics = dict() self._metrics['test-vim-id-1'] = RwmonYang.NfviMetrics() self._metrics['test-vim-id-2'] = RwmonYang.NfviMetrics()
def __init__(self): self.metrics = RwmonYang.NfviMetrics()
def nfvi_metrics(self, account, vim_id): metrics = RwmonYang.NfviMetrics() metrics.vcpu.utilization = 0.5 return metrics
def nfvi_metrics(self, account, vm_id): metrics = RwmonYang.NfviMetrics() metrics.vcpu = self.nfvi_vcpu_metrics(account, vm_id) metrics.memory = self.nfvi_memory_metrics(account, vm_id) metrics.storage = self.nfvi_storage_metrics(account, vm_id) return metrics
def nfvi_metrics(self, account, vm_id): return rwmon.NfviMetrics()