def test_report_and_send_metrics(self):
        # given
        experiment_start = time.time()
        second_after_start = experiment_start + 1.0

        # and
        experiment = MagicMock()

        # and
        metric_service = self.metric_service_factory.create(
            gauge_mode=GaugeMode.SYSTEM, experiment=experiment, reference_timestamp=experiment_start)
        metrics_container = metric_service.metrics_container

        # when
        metric_service.report_and_send(timestamp=second_after_start)

        # then
        self.backend.send_hardware_metric_reports.assert_called_once_with(
            experiment,
            metrics_container.metrics(),
            [
                MetricReport(
                    metric=metrics_container.cpu_usage_metric,
                    values=[MetricValue(timestamp=second_after_start, running_time=1.0, gauge_name=u'cpu', value=ANY)]
                ),
                MetricReport(
                    metric=metrics_container.memory_metric,
                    values=[MetricValue(timestamp=second_after_start, running_time=1.0, gauge_name=u'ram', value=ANY)]
                )
            ]
        )
Esempio n. 2
0
 def __metric_value_for_gauge(self, gauge, timestamp):
     return MetricValue(
         timestamp=timestamp,
         running_time=timestamp - self.__reference_timestamp,
         gauge_name=gauge.name(),
         value=gauge.value()
     )
Esempio n. 3
0
 def __metric_value_for_gauge(self, gauge, timestamp):
     value = gauge.value()
     return (MetricValue(
         timestamp=timestamp,
         running_time=timestamp - self.__reference_timestamp,
         gauge_name=gauge.name(),
         value=value,
     ) if value else None)
    def test_report_metrics(self):
        # given
        measurement_timestamp = self.reference_timestamp + 10

        # when
        metric_reports = self.metric_reporter.report(measurement_timestamp)

        # then
        expected_time = measurement_timestamp - self.reference_timestamp
        expected_reports = [
            MetricReport(metric=self.metrics_container.cpu_usage_metric,
                         values=[
                             MetricValue(timestamp=measurement_timestamp,
                                         running_time=expected_time,
                                         gauge_name=u'cpu',
                                         value=self.fixture.cpu_gauge_value)
                         ]),
            MetricReport(metric=self.metrics_container.memory_metric,
                         values=[
                             MetricValue(timestamp=measurement_timestamp,
                                         running_time=expected_time,
                                         gauge_name=u'ram',
                                         value=self.fixture.memory_gauge_value)
                         ]),
            MetricReport(
                metric=self.metrics_container.gpu_usage_metric,
                values=[
                    MetricValue(timestamp=measurement_timestamp,
                                running_time=expected_time,
                                gauge_name=u'0',
                                value=self.fixture.gpu0_usage_gauge_value),
                    MetricValue(timestamp=measurement_timestamp,
                                running_time=expected_time,
                                gauge_name=u'2',
                                value=self.fixture.gpu1_usage_gauge_value)
                ]),
            MetricReport(
                metric=self.metrics_container.gpu_memory_metric,
                values=[
                    MetricValue(timestamp=measurement_timestamp,
                                running_time=expected_time,
                                gauge_name=u'0',
                                value=self.fixture.gpu0_memory_gauge_value),
                    MetricValue(timestamp=measurement_timestamp,
                                running_time=expected_time,
                                gauge_name=u'2',
                                value=self.fixture.gpu1_memory_gauge_value)
                ])
        ]
        self.assertListEqual(expected_reports, metric_reports)