Ejemplo n.º 1
0
def test_tags(tags, defaults, expected):
    metric = aiomeasures.CountingMetric('foo', 1, tags=tags)
    handler = aiomeasures.StatsD(':0', tags=defaults)
    assert handler.format(metric) == 'foo:1|c%s' % expected
Ejemplo n.º 2
0
import aiomeasures
import asyncio
import pytest
from datetime import timedelta

simple = [
    (aiomeasures.CountingMetric('foo', 1), 'foo:1|c'),
    (aiomeasures.CountingMetric('foo', -1), 'foo:-1|c'),
    (aiomeasures.GaugeMetric('foo', 1), 'foo:1|g'),
    (aiomeasures.GaugeMetric('foo', -1), 'foo:-1|g'),
    (aiomeasures.HistogramMetric('foo', 42), 'foo:42|h'),
    (aiomeasures.HistogramMetric('foo', -42), 'foo:-42|h'),
    (aiomeasures.SetMetric('foo', 'bar'), 'foo:bar|s'),
    (aiomeasures.TimingMetric('foo', 100), 'foo:100|ms'),
]

one_second = timedelta(seconds=1)
twenty_ms = timedelta(microseconds=20000)

rated = [
    (aiomeasures.CountingMetric('foo', 1, 0.1), 'foo:1|c|@0.1'),
    (aiomeasures.GaugeMetric('foo', 1, 0.1), 'foo:1|g|@0.1'),
    (aiomeasures.SetMetric('foo', 'bar', 0.1), 'foo:bar|s|@0.1'),
    (aiomeasures.TimingMetric('foo', 100, 0.1), 'foo:100|ms|@0.1'),
    (aiomeasures.HistogramMetric('foo', -42, 0.1), 'foo:-42|h|@0.1'),
    (aiomeasures.CountingMetric('foo', 1, one_second), 'foo:1|c|@1'),
    (aiomeasures.GaugeMetric('foo', 1, one_second), 'foo:1|g|@1'),
    (aiomeasures.SetMetric('foo', 'bar', one_second), 'foo:bar|s|@1'),
    (aiomeasures.TimingMetric('foo', 100, one_second), 'foo:100|ms|@1'),
    (aiomeasures.HistogramMetric('foo', -42, one_second), 'foo:-42|h|@1'),
    (aiomeasures.CountingMetric('foo', 1, twenty_ms), 'foo:1|c|@0.02'),