def test_track_process_memory_exception(self, logger_mock): with mock.patch( "azure_monitor.sdk.auto_collection.performance_metrics.PROCESS", throw(Exception), ): performance_metrics_collector = PerformanceMetrics( meter=self._meter, labels=self._test_labels) obs = Observer( callback=performance_metrics_collector._track_process_memory, name="\\Process(??APP_WIN32_PROC??)\\Private Bytes", description="Amount of memory process has used in bytes", unit="byte", value_type=int, meter=self._meter, ) performance_metrics_collector._track_process_memory(obs) self.assertEqual(logger_mock.exception.called, True)
def test_track_process_memory(self): with mock.patch( "azure_monitor.sdk.auto_collection.performance_metrics.PROCESS" ) as process_mock: performance_metrics_collector = PerformanceMetrics( meter=self._meter, labels=self._test_labels) memory = collections.namedtuple("memory", "rss") pmem = memory(rss=100) process_mock.memory_info.return_value = pmem obs = Observer( callback=performance_metrics_collector._track_process_memory, name="\\Process(??APP_WIN32_PROC??)\\Private Bytes", description="Amount of memory process has used in bytes", unit="byte", value_type=int, meter=self._meter, ) performance_metrics_collector._track_process_memory(obs) self.assertEqual( obs.aggregators[tuple(self._test_labels.items())].current, 100)