Пример #1
0
    def test_recent_point_threshold(self):
        threshold = 100
        # The min is not enabled by default
        stats = MetricsAggregator(
            'myhost',
            recent_point_threshold=threshold,
            histogram_aggregates=DEFAULT_HISTOGRAM_AGGREGATES + ['min'])
        timestamp_beyond_threshold = time.time() - threshold * 2
        timestamp_within_threshold = time.time() - threshold / 2

        # Ensure that old gauges get dropped due to old timestamps
        stats.submit_metric('my.first.gauge', 5, 'g')
        stats.submit_metric('my.first.gauge',
                            1,
                            'g',
                            timestamp=timestamp_beyond_threshold)
        stats.submit_metric('my.second.gauge',
                            20,
                            'g',
                            timestamp=timestamp_beyond_threshold)

        metrics = self.sort_metrics(stats.flush())
        assert len(metrics) == 1

        first = metrics[0]
        nt.assert_equals(first['metric'], 'my.first.gauge')
        nt.assert_equals(first['points'][0][1], 5)
        nt.assert_equals(first['host'], 'myhost')

        # Ensure that old gauges get dropped due to old timestamps
        stats.submit_metric('my.1.gauge', 5, 'g')
        stats.submit_metric('my.1.gauge',
                            1,
                            'g',
                            timestamp=timestamp_within_threshold)
        stats.submit_metric('my.2.counter',
                            20,
                            'c',
                            timestamp=timestamp_within_threshold)
        stats.submit_metric('my.3.set',
                            20,
                            's',
                            timestamp=timestamp_within_threshold)
        stats.submit_metric('my.4.histogram',
                            20,
                            'h',
                            timestamp=timestamp_within_threshold)

        flush_timestamp = time.time()
        metrics = self.sort_metrics(stats.flush())
        nt.assert_equal(len(metrics), 9)

        first, second, third, h1, h2, h3, h4, h5, h6 = metrics
        nt.assert_equals(first['metric'], 'my.1.gauge')
        nt.assert_equals(first['points'][0][1], 1)
        nt.assert_equals(first['host'], 'myhost')
        self.assert_almost_equal(first['points'][0][0],
                                 timestamp_within_threshold, 0.1)

        nt.assert_equals(second['metric'], 'my.2.counter')
        nt.assert_equals(second['points'][0][1], 20)
        self.assert_almost_equal(second['points'][0][0], flush_timestamp, 0.1)

        nt.assert_equals(third['metric'], 'my.3.set')
        nt.assert_equals(third['points'][0][1], 1)
        self.assert_almost_equal(third['points'][0][0], flush_timestamp, 0.1)

        nt.assert_equals(h1['metric'], 'my.4.histogram.95percentile')
        nt.assert_equals(h1['points'][0][1], 20)
        self.assert_almost_equal(h1['points'][0][0], flush_timestamp, 0.1)
        nt.assert_equal(h1['points'][0][0], h2['points'][0][0])
        nt.assert_equal(h1['points'][0][0], h3['points'][0][0])
        nt.assert_equal(h1['points'][0][0], h4['points'][0][0])
        nt.assert_equal(h1['points'][0][0], h5['points'][0][0])
Пример #2
0
    def test_recent_point_threshold(self):
        threshold = 100
        stats = MetricsAggregator('myhost', recent_point_threshold=threshold)
        timestamp_beyond_threshold = time.time() - threshold*2
        timestamp_within_threshold = time.time() - threshold/2

        # Ensure that old gauges get dropped due to old timestamps
        stats.submit_metric('my.first.gauge', 5, 'g')
        stats.submit_metric('my.first.gauge', 1, 'g', timestamp=timestamp_beyond_threshold)
        stats.submit_metric('my.second.gauge', 20, 'g', timestamp=timestamp_beyond_threshold)

        metrics = self.sort_metrics(stats.flush())
        assert len(metrics) == 1

        first = metrics[0]
        nt.assert_equals(first['metric'], 'my.first.gauge')
        nt.assert_equals(first['points'][0][1], 5)
        nt.assert_equals(first['host'], 'myhost')

        # Ensure that old gauges get dropped due to old timestamps
        stats.submit_metric('my.1.gauge', 5, 'g')
        stats.submit_metric('my.1.gauge', 1, 'g', timestamp=timestamp_within_threshold)
        stats.submit_metric('my.2.counter', 20, 'c', timestamp=timestamp_within_threshold)
        stats.submit_metric('my.3.set', 20, 's', timestamp=timestamp_within_threshold)
        stats.submit_metric('my.4.histogram', 20, 'h', timestamp=timestamp_within_threshold)

        flush_timestamp = time.time()
        metrics = self.sort_metrics(stats.flush())
        nt.assert_equal(len(metrics), 8)

        first, second, third, h1, h2, h3, h4, h5 = metrics
        nt.assert_equals(first['metric'], 'my.1.gauge')
        nt.assert_equals(first['points'][0][1], 1)
        nt.assert_equals(first['host'], 'myhost')
        self.assert_almost_equal(first['points'][0][0], timestamp_within_threshold, 0.1)

        nt.assert_equals(second['metric'], 'my.2.counter')
        nt.assert_equals(second['points'][0][1], 20)
        self.assert_almost_equal(second['points'][0][0], flush_timestamp, 0.1)

        nt.assert_equals(third['metric'], 'my.3.set')
        nt.assert_equals(third['points'][0][1], 1)
        self.assert_almost_equal(third['points'][0][0], flush_timestamp, 0.1)

        nt.assert_equals(h1['metric'], 'my.4.histogram.95percentile')
        nt.assert_equals(h1['points'][0][1], 20)
        self.assert_almost_equal(h1['points'][0][0], flush_timestamp, 0.1)
        nt.assert_equal(h1['points'][0][0], h2['points'][0][0])
        nt.assert_equal(h1['points'][0][0], h3['points'][0][0])
        nt.assert_equal(h1['points'][0][0], h4['points'][0][0])
        nt.assert_equal(h1['points'][0][0], h5['points'][0][0])
Пример #3
0
    def test_recent_point_threshold(self):
        threshold = 100
        stats = MetricsAggregator("myhost", recent_point_threshold=threshold)
        timestamp_beyond_threshold = time.time() - threshold * 2
        timestamp_within_threshold = time.time() - threshold / 2

        # Ensure that old gauges get dropped due to old timestamps
        stats.submit_metric("my.first.gauge", 5, "g")
        stats.submit_metric("my.first.gauge", 1, "g", timestamp=timestamp_beyond_threshold)
        stats.submit_metric("my.second.gauge", 20, "g", timestamp=timestamp_beyond_threshold)

        metrics = self.sort_metrics(stats.flush())
        assert len(metrics) == 1

        first = metrics[0]
        nt.assert_equals(first["metric"], "my.first.gauge")
        nt.assert_equals(first["points"][0][1], 5)
        nt.assert_equals(first["host"], "myhost")

        # Ensure that old gauges get dropped due to old timestamps
        stats.submit_metric("my.1.gauge", 5, "g")
        stats.submit_metric("my.1.gauge", 1, "g", timestamp=timestamp_within_threshold)
        stats.submit_metric("my.2.counter", 20, "c", timestamp=timestamp_within_threshold)
        stats.submit_metric("my.3.set", 20, "s", timestamp=timestamp_within_threshold)
        stats.submit_metric("my.4.histogram", 20, "h", timestamp=timestamp_within_threshold)

        flush_timestamp = time.time()
        metrics = self.sort_metrics(stats.flush())
        nt.assert_equal(len(metrics), 8)

        first, second, third, h1, h2, h3, h4, h5 = metrics
        nt.assert_equals(first["metric"], "my.1.gauge")
        nt.assert_equals(first["points"][0][1], 1)
        nt.assert_equals(first["host"], "myhost")
        self.assert_almost_equal(first["points"][0][0], timestamp_within_threshold, 0.1)

        nt.assert_equals(second["metric"], "my.2.counter")
        nt.assert_equals(second["points"][0][1], 20)
        self.assert_almost_equal(second["points"][0][0], flush_timestamp, 0.1)

        nt.assert_equals(third["metric"], "my.3.set")
        nt.assert_equals(third["points"][0][1], 1)
        self.assert_almost_equal(third["points"][0][0], flush_timestamp, 0.1)

        nt.assert_equals(h1["metric"], "my.4.histogram.95percentile")
        nt.assert_equals(h1["points"][0][1], 20)
        self.assert_almost_equal(h1["points"][0][0], flush_timestamp, 0.1)
        nt.assert_equal(h1["points"][0][0], h2["points"][0][0])
        nt.assert_equal(h1["points"][0][0], h3["points"][0][0])
        nt.assert_equal(h1["points"][0][0], h4["points"][0][0])
        nt.assert_equal(h1["points"][0][0], h5["points"][0][0])
Пример #4
0
    def test_source_classification(self):
        # The min is not enabled by default
        myaggregator = MetricsAggregator('myhost')

        # Ensure that old gauges get dropped due to old timestamps
        myaggregator.submit_metric('my.first.gauge', 5, 'g', source='foo')
        myaggregator.submit_metric('my.first.gauge', 1, 'g', source='foo')
        myaggregator.submit_metric('my.second.gauge', 20, 'g', source='foo')

        # Same metric different source
        myaggregator.submit_metric('my.first.gauge', 10, 'g', source='bar')
        myaggregator.submit_metric('my.first.gauge', 2, 'g', source='bar')
        myaggregator.submit_metric('my.second.gauge', 40, 'g', source='bar')

        # Same metric different source
        myaggregator.submit_metric('my.first.gauge', 15, 'g', source='haz')
        myaggregator.submit_metric('my.first.gauge', 3, 'g', source='haz')

        # Same metric from unknown sources
        myaggregator.submit_metric('my.first.gauge', 15, 'g')
        myaggregator.submit_metric('my.first.gauge', 3, 'g')

        metrics = self.sort_metrics(myaggregator.flush()[:-1])
        assert len(metrics) == 2

        sources = myaggregator.stats.get_aggregator_stats()
        assert len(sources['stats']) == 4
        assert sources['stats']['foo'] == 2
        assert sources['stats']['bar'] == 2
        assert sources['stats']['haz'] == 1
        assert sources['stats'][UNKNOWN_SOURCE] == 1
Пример #5
0
    def test_recent_point_threshold(self):
        threshold = 100
        # The min is not enabled by default
        stats = MetricsAggregator(
            'myhost',
            recent_point_threshold=threshold,
            histogram_aggregates=DEFAULT_HISTOGRAM_AGGREGATES+['min']
        )
        timestamp_beyond_threshold = time.time() - threshold*2
        timestamp_within_threshold = time.time() - threshold/2

        # Ensure that old gauges get dropped due to old timestamps
        stats.submit_metric('my.first.gauge', 5, 'g')
        stats.submit_metric('my.first.gauge', 1, 'g', timestamp=timestamp_beyond_threshold)
        stats.submit_metric('my.second.gauge', 20, 'g', timestamp=timestamp_beyond_threshold)

        metrics = self.sort_metrics(stats.flush())
        assert len(metrics) == 1

        first = metrics[0]
        nt.assert_equals(first[0], 'my.first.gauge')
        nt.assert_equals(first[2], 5)
        nt.assert_equals(first[3]['hostname'], 'myhost')

        # Ensure that old gauges get dropped due to old timestamps
        stats.submit_metric('my.1.gauge', 5, 'g')
        stats.submit_metric('my.1.gauge', 1, 'g', timestamp=timestamp_within_threshold)
        stats.submit_metric('my.2.counter', 20, 'c', timestamp=timestamp_within_threshold)
        stats.submit_metric('my.3.set', 20, 's', timestamp=timestamp_within_threshold)
        stats.submit_metric('my.4.histogram', 20, 'h', timestamp=timestamp_within_threshold)

        flush_timestamp = time.time()
        metrics = self.sort_metrics(stats.flush())
        nt.assert_equal(len(metrics), 9)

        first, second, third, h1, h2, h3, h4, h5, h6 = metrics
        nt.assert_equals(first[0], 'my.1.gauge')
        nt.assert_equals(first[2], 1)
        nt.assert_equals(first[3]['hostname'], 'myhost')
        self.assert_almost_equal(first[1], timestamp_within_threshold, 0.1)

        nt.assert_equals(second[0], 'my.2.counter')
        nt.assert_equals(second[2], 20)
        self.assert_almost_equal(second[1], flush_timestamp, 0.1)

        nt.assert_equals(third[0], 'my.3.set')
        nt.assert_equals(third[2], 1)
        self.assert_almost_equal(third[1], flush_timestamp, 0.1)

        nt.assert_equals(h1[0], 'my.4.histogram.95percentile')
        nt.assert_equals(h1[2], 20)
        self.assert_almost_equal(h1[1], flush_timestamp, 0.1)
        nt.assert_equal(h1[1], h2[1])
        nt.assert_equal(h1[1], h3[1])
        nt.assert_equal(h1[1], h4[1])
        nt.assert_equal(h1[1], h5[1])