def test_gauge_should_keep_values_between_flushes(): state = State() handle_data(b'boo:10|g\n', state) state, oldstate = swap(state) handle_data(b'boo:+10|g\n', state) assert list(state.extract()) == [(b'boo', 20)] assert list(oldstate.extract()) == [(b'boo', 10)]
def test_bad_data(): state = State() handle_data(b'boo\n', state) assert not list(state.extract()) handle_data(b'boo:1|c|@boo\n', state) assert not list(state.extract()) handle_data(b'boo:1\n', state) assert not list(state.extract()) handle_data(b'boo:1|c|@|b\n', state) assert not list(state.extract()) handle_data(b'boo:foo|c\n', state) assert not list(state.extract())
def test_counter(): state = State() handle_data(b'boo:1|c\nboo:1|c|@0.1\n', state) assert list(state.extract()) == [(b'boo.count', 11)]
def test_to_graphite(): state = State() handle_data(b'boo:1|c\nboo:1|c|@0.1\n', state) assert state.to_graphite(101) == b'boo.count 11 101\n'
def test_delta_gauge_with_empty_key(): state = State() handle_data(b'boo:+1|g\n', state) assert list(state.extract()) == []
def test_gauge(): state = State() handle_data(b'boo:1|g\nboo:+2|g\nboo:-1|g|@0.1\n', state) assert list(state.extract()) == [(b'boo', -7)]
def test_set(): state = State() handle_data(b'boo:1|s\nboo:1|s\nboo:2|s\n', state) assert list(state.extract()) == [(b'boo', 2)]
def test_timer_even(): state = State() handle_data(b'boo:1|ms\nboo:2|ms\nboo:3|ms\nboo:4|ms\n', state) assert list(state.extract()) == [(b'boo.count', 4), (b'boo.upper', 0.004), (b'boo.lower', 0.001), (b'boo.mean', 0.0025), (b'boo.stdev', 0.001118033988749895), (b'boo.p50', 0.0025)]
def test_timer_odd(): state = State() handle_data(b'boo:1|ms\nboo:2|ms\nboo:3|ms|@0.1\n', state) assert list(state.extract()) == [(b'boo.count', 12), (b'boo.upper', 0.003), (b'boo.lower', 0.001), (b'boo.mean', 0.002), (b'boo.stdev', 0.000816496580927726), (b'boo.p50', 0.002)]