示例#1
0
    def test_merge_last_updated_none(self):
        observer1 = ValueObserverAggregator()
        observer2 = ValueObserverAggregator()

        mmsc_checkpoint1 = MinMaxSumCountAggregator._TYPE(3, 150, 101, 3)
        mmsc_checkpoint2 = MinMaxSumCountAggregator._TYPE(1, 33, 44, 2)

        checkpoint1 = ValueObserverAggregator._TYPE(*(mmsc_checkpoint1 +
                                                      (23, )))

        checkpoint2 = ValueObserverAggregator._TYPE(*(mmsc_checkpoint2 +
                                                      (27, )))

        observer1.mmsc.checkpoint = mmsc_checkpoint1
        observer2.mmsc.checkpoint = mmsc_checkpoint2

        observer1.last_update_timestamp = 0
        observer2.last_update_timestamp = 100

        observer1.checkpoint = checkpoint1
        observer2.checkpoint = checkpoint2

        observer1.merge(observer2)

        self.assertEqual(
            observer1.checkpoint,
            (
                min(checkpoint1.min, checkpoint2.min),
                max(checkpoint1.max, checkpoint2.max),
                checkpoint1.sum + checkpoint2.sum,
                checkpoint1.count + checkpoint2.count,
                checkpoint2.last,
            ),
        )
        self.assertEqual(observer1.last_update_timestamp, 100)
示例#2
0
    def test_system_cpu_utilization(self, mock_cpu_times_percent):
        CPUTimesPercent = namedtuple("CPUTimesPercent",
                                     ["idle", "user", "system", "irq"])
        mock_cpu_times_percent.return_value = [
            CPUTimesPercent(idle=1.2, user=3.4, system=5.6, irq=7.8),
            CPUTimesPercent(idle=1.2, user=3.4, system=5.6, irq=7.8),
        ]

        expected = {
            (
                ("cpu", 1),
                ("state", "idle"),
            ):
            ValueObserverAggregator._TYPE(
                min=1.2 / 100,
                max=1.2 / 100,
                sum=1.2 / 100,
                count=1,
                last=1.2 / 100,
            ),
            (
                ("cpu", 1),
                ("state", "user"),
            ):
            ValueObserverAggregator._TYPE(
                min=3.4 / 100,
                max=3.4 / 100,
                sum=3.4 / 100,
                count=1,
                last=3.4 / 100,
            ),
            (
                ("cpu", 1),
                ("state", "system"),
            ):
            ValueObserverAggregator._TYPE(
                min=5.6 / 100,
                max=5.6 / 100,
                sum=5.6 / 100,
                count=1,
                last=5.6 / 100,
            ),
            (
                ("cpu", 1),
                ("state", "irq"),
            ):
            ValueObserverAggregator._TYPE(
                min=7.8 / 100,
                max=7.8 / 100,
                sum=7.8 / 100,
                count=1,
                last=7.8 / 100,
            ),
            (
                ("cpu", 2),
                ("state", "idle"),
            ):
            ValueObserverAggregator._TYPE(
                min=1.2 / 100,
                max=1.2 / 100,
                sum=1.2 / 100,
                count=1,
                last=1.2 / 100,
            ),
            (
                ("cpu", 2),
                ("state", "user"),
            ):
            ValueObserverAggregator._TYPE(
                min=3.4 / 100,
                max=3.4 / 100,
                sum=3.4 / 100,
                count=1,
                last=3.4 / 100,
            ),
            (
                ("cpu", 2),
                ("state", "system"),
            ):
            ValueObserverAggregator._TYPE(
                min=5.6 / 100,
                max=5.6 / 100,
                sum=5.6 / 100,
                count=1,
                last=5.6 / 100,
            ),
            (
                ("cpu", 2),
                ("state", "irq"),
            ):
            ValueObserverAggregator._TYPE(
                min=7.8 / 100,
                max=7.8 / 100,
                sum=7.8 / 100,
                count=1,
                last=7.8 / 100,
            ),
        }
        self._test_metrics("system.cpu.utilization", expected)