当前位置: 首页>>代码示例>>Python>>正文


Python MetricsAggregator.submit方法代码示例

本文整理汇总了Python中dogstatsd.MetricsAggregator.submit方法的典型用法代码示例。如果您正苦于以下问题:Python MetricsAggregator.submit方法的具体用法?Python MetricsAggregator.submit怎么用?Python MetricsAggregator.submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dogstatsd.MetricsAggregator的用法示例。


在下文中一共展示了MetricsAggregator.submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_gauge

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_gauge(self):
        stats = MetricsAggregator('myhost', 1)

        # Track some counters.
        stats.submit('my.first.gauge:1|g')
        stats.submit('my.first.gauge:5|g')
        stats.submit('my.second.gauge:1.5|g')

        # Ensure they roll up nicely.
        time.sleep(1)
        metrics = self.sort_metrics(stats.flush(False))
        assert len(metrics) == 2

        first, second = metrics

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

        nt.assert_equals(second['metric'], 'my.second.gauge')
        nt.assert_equals(second['points'][0][1], 1.5)


        # Ensure they shall be flushed no more.
        metrics = stats.flush(False)
        assert not len(metrics)
开发者ID:FriedWishes,项目名称:dd-agent,代码行数:28,代码来源:test_dogstatsd.py

示例2: test_histogram

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_histogram(self):
        stats = MetricsAggregator('myhost')

        # Sample all numbers between 1-100 many times. This
        # means our percentiles should be relatively close to themselves.
        percentiles = range(100)
        random.shuffle(percentiles) # in place
        for i in percentiles:
            for j in xrange(20):
                for type_ in ['h', 'ms']:
                    m = 'my.p:%s|%s' % (i, type_)
                    stats.submit(m)

        metrics = self.sort_metrics(stats.flush())

        def assert_almost_equal(i, j, e=1):
            # Floating point math?
            assert abs(i - j) <= e, "%s %s %s" % (i, j, e)

        nt.assert_equal(len(metrics), 5)
        p95, pavg, pcount, pmax, pmed = self.sort_metrics(metrics)
        nt.assert_equal(p95['metric'], 'my.p.95percentile')
        assert_almost_equal(p95['points'][0][1], 95, 10)
        assert_almost_equal(pmax['points'][0][1], 99, 1)
        assert_almost_equal(pmed['points'][0][1], 50, 2)
        assert_almost_equal(pavg['points'][0][1], 50, 2)
        assert_almost_equal(pcount['points'][0][1], 4000, 0) # 100 * 20 * 2
        nt.assert_equals(p95['host'], 'myhost')

        # Ensure that histograms are reset.
        metrics = self.sort_metrics(stats.flush())
        assert not metrics
开发者ID:Qobuz,项目名称:dd-agent,代码行数:34,代码来源:test_dogstatsd.py

示例3: test_sampled_counter

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_sampled_counter(self):

        # Submit a sampled counter.
        stats = MetricsAggregator('myhost')
        stats.submit('sampled.counter:1|c|@0.5')
        metrics = stats.flush()
        assert len(metrics) == 1
        m = metrics[0]
        assert m['metric'] == 'sampled.counter'
        nt.assert_equal(m['points'][0][1], 2)
开发者ID:Qobuz,项目名称:dd-agent,代码行数:12,代码来源:test_dogstatsd.py

示例4: test_diagnostic_stats

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_diagnostic_stats(self):
        stats = MetricsAggregator('myhost')
        for i in xrange(10):
            stats.submit('metric:10|c')
        stats.send_packet_count('datadog.dogstatsd.packet.count')
        metrics = self.sort_metrics(stats.flush())
        nt.assert_equals(2, len(metrics))
        first, second = metrics

        nt.assert_equal(first['metric'], 'datadog.dogstatsd.packet.count')
        nt.assert_equal(first['points'][0][1], 10)
开发者ID:Qobuz,项目名称:dd-agent,代码行数:13,代码来源:test_dogstatsd.py

示例5: test_gauge_sample_rate

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_gauge_sample_rate(self):
        stats = MetricsAggregator('myhost')

        # Submit a sampled gauge metric.
        stats.submit('sampled.gauge:10|g|@0.1')

        # Assert that it's treated normally.
        metrics = stats.flush()
        nt.assert_equal(len(metrics), 1)
        m = metrics[0]
        nt.assert_equal(m['metric'], 'sampled.gauge')
        nt.assert_equal(m['points'][0][1], 10)
开发者ID:Qobuz,项目名称:dd-agent,代码行数:14,代码来源:test_dogstatsd.py

示例6: test_sampled_histogram

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_sampled_histogram(self):
        # Submit a sampled histogram.
        stats = MetricsAggregator('myhost')
        stats.submit('sampled.hist:5|h|@0.5')


        # Assert we scale up properly.
        metrics = self.sort_metrics(stats.flush())
        p95, pavg, pcount, pmax, pmed = self.sort_metrics(metrics)

        nt.assert_equal(pcount['points'][0][1], 2)
        for p in [p95, pavg, pmed, pmax]:
            nt.assert_equal(p['points'][0][1], 5)
开发者ID:Qobuz,项目名称:dd-agent,代码行数:15,代码来源:test_dogstatsd.py

示例7: test_tags

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_tags(self):
        stats = MetricsAggregator('myhost')
        stats.submit('gauge:1|c')
        stats.submit('gauge:2|c|@1')
        stats.submit('gauge:4|c|#tag1,tag2')
        stats.submit('gauge:8|c|#tag2,tag1') # Should be the same as above
        stats.submit('gauge:16|c|#tag3,tag4')

        metrics = self.sort_metrics(stats.flush())

        assert len(metrics) == 3
        first, second, third = metrics

        nt.assert_equal(first['metric'], 'gauge')
        nt.assert_equal(first['tags'], None)
        nt.assert_equal(first['points'][0][1], 3)
        nt.assert_equal(first['host'], 'myhost')

        nt.assert_equal(second['metric'], 'gauge')
        nt.assert_equal(second['tags'], ('tag1', 'tag2'))
        nt.assert_equal(second['points'][0][1], 12)
        nt.assert_equal(second['host'], 'myhost')

        nt.assert_equal(third['metric'], 'gauge')
        nt.assert_equal(third['tags'], ('tag3', 'tag4'))
        nt.assert_equal(third['points'][0][1], 16)
        nt.assert_equal(third['host'], 'myhost')
开发者ID:Qobuz,项目名称:dd-agent,代码行数:29,代码来源:test_dogstatsd.py

示例8: test_sampled_histogram

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_sampled_histogram(self):
        # Submit a sampled histogram.
        stats = MetricsAggregator('myhost', 1)
        stats.submit('sampled.hist:5|h|@0.5')

        time.sleep(1)

        # Assert we scale up properly.
        metrics = self.sort_metrics(stats.flush(False))
        p75, p85, p95, p99, pavg, pcount, pmin, pmax = self.sort_metrics(metrics)

        nt.assert_equal(pcount['points'][0][1], 2)
        for p in [p75, p85, p99, pavg, pmin, pmax]:
            nt.assert_equal(p['points'][0][1], 5)
开发者ID:FriedWishes,项目名称:dd-agent,代码行数:16,代码来源:test_dogstatsd.py

示例9: test_batch_submission

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_batch_submission(self):
        # Submit a sampled histogram.
        stats = MetricsAggregator('myhost')
        metrics = [
            'counter:1|c',
            'counter:1|c',
            'gauge:1|g'
        ]
        packet = "\n".join(metrics)
        stats.submit(packet)

        metrics = self.sort_metrics(stats.flush())
        nt.assert_equal(2, len(metrics))
        counter, gauge = metrics
        assert counter['points'][0][1] == 2
        assert gauge['points'][0][1] == 1
开发者ID:Qobuz,项目名称:dd-agent,代码行数:18,代码来源:test_dogstatsd.py

示例10: test_rate

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_rate(self):
        stats = MetricsAggregator('myhost')
        stats.submit('my.rate:10|_dd-r')
        # Sleep 1 second so the time interval > 0
        time.sleep(1)
        stats.submit('my.rate:40|_dd-r')

        # Check that the rate is calculated correctly
        metrics = stats.flush()
        nt.assert_equal(len(metrics), 1)
        m = metrics[0]
        nt.assert_equals(m['metric'], 'my.rate')
        nt.assert_equals(m['points'][0][1], 30)

        # Assert that no more rates are given
        assert not stats.flush()
开发者ID:Qobuz,项目名称:dd-agent,代码行数:18,代码来源:test_dogstatsd.py

示例11: test_bad_packets_throw_errors

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_bad_packets_throw_errors(self):
        packets = [
            'missing.value.and.type',
            'missing.type:2',
            'missing.value|c',
            '2|c',
            'unknown.type:2|z',
            'string.value:abc|c',
            'string.sample.rate:0|c|@abc',
        ]

        stats = MetricsAggregator('myhost')
        for packet in packets:
            try:
                stats.submit(packet)
            except:
                assert True
            else:
                assert False, 'invalid : %s' % packet
开发者ID:Qobuz,项目名称:dd-agent,代码行数:21,代码来源:test_dogstatsd.py

示例12: test_gauge

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_gauge(self):
        stats = MetricsAggregator('myhost')

        # Track some counters.
        stats.submit('my.first.gauge:1|g')
        stats.submit('my.first.gauge:5|g')
        stats.submit('my.second.gauge:1.5|g')

        # Ensure that gauges roll up correctly.
        metrics = self.sort_metrics(stats.flush())
        assert len(metrics) == 2

        first, second = metrics

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

        nt.assert_equals(second['metric'], 'my.second.gauge')
        nt.assert_equals(second['points'][0][1], 1.5)
开发者ID:Qobuz,项目名称:dd-agent,代码行数:22,代码来源:test_dogstatsd.py

示例13: test_metrics_expiry

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_metrics_expiry(self):
        # Ensure metrics eventually expire and stop submitting.
        stats = MetricsAggregator('myhost', expiry_seconds=1)
        stats.submit('test.counter:123|c')

        # Ensure points keep submitting
        assert stats.flush()
        assert stats.flush()
        time.sleep(0.5)
        assert stats.flush()

        # Now sleep for longer than the expiry window and ensure
        # no points are submitted
        time.sleep(2)
        m = stats.flush()
        assert not m, str(m)

        # If we submit again, we're all good.
        stats.submit('test.counter:123|c')
        assert stats.flush()
开发者ID:Qobuz,项目名称:dd-agent,代码行数:22,代码来源:test_dogstatsd.py

示例14: test_counter

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_counter(self):
        stats = MetricsAggregator('myhost')

        # Track some counters.
        stats.submit('my.first.counter:1|c')
        stats.submit('my.first.counter:5|c')
        stats.submit('my.second.counter:1|c')
        stats.submit('my.third.counter:3|c')

        # Ensure they roll up nicely.
        metrics = self.sort_metrics(stats.flush())
        assert len(metrics) == 3

        first, second, third = metrics
        nt.assert_equals(first['metric'], 'my.first.counter')
        nt.assert_equals(first['points'][0][1], 6)
        nt.assert_equals(first['host'], 'myhost')

        nt.assert_equals(second['metric'], 'my.second.counter')
        nt.assert_equals(second['points'][0][1], 1)

        nt.assert_equals(third['metric'], 'my.third.counter')
        nt.assert_equals(third['points'][0][1], 3)

        # Ensure that counters reset to zero.
        metrics = self.sort_metrics(stats.flush())
        first, second, third = metrics
        nt.assert_equals(first['metric'], 'my.first.counter')
        nt.assert_equals(first['points'][0][1], 0)
        nt.assert_equals(second['metric'], 'my.second.counter')
        nt.assert_equals(second['points'][0][1], 0)
        nt.assert_equals(third['metric'], 'my.third.counter')
        nt.assert_equals(third['points'][0][1], 0)
开发者ID:Qobuz,项目名称:dd-agent,代码行数:35,代码来源:test_dogstatsd.py

示例15: test_counter

# 需要导入模块: from dogstatsd import MetricsAggregator [as 别名]
# 或者: from dogstatsd.MetricsAggregator import submit [as 别名]
    def test_counter(self):
        stats = MetricsAggregator('myhost', 1)

        # Track some counters.
        stats.submit('my.first.counter:1|c')
        stats.submit('my.first.counter:5|c')
        stats.submit('my.second.counter:1|c')
        stats.submit('my.third.counter:3|c')

        time.sleep(1)
        # Ensure they roll up nicely.
        metrics = self.sort_metrics(stats.flush(False))
        assert len(metrics) == 3

        first, second, third = metrics
        nt.assert_equals(first['metric'], 'my.first.counter')
        nt.assert_equals(first['points'][0][1], 6)
        nt.assert_equals(first['host'], 'myhost')

        nt.assert_equals(second['metric'], 'my.second.counter')
        nt.assert_equals(second['points'][0][1], 1)

        nt.assert_equals(third['metric'], 'my.third.counter')
        nt.assert_equals(third['points'][0][1], 3)

        # Ensure they're gone now.
        assert not len(stats.flush(False))
开发者ID:FriedWishes,项目名称:dd-agent,代码行数:29,代码来源:test_dogstatsd.py


注:本文中的dogstatsd.MetricsAggregator.submit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。