本文整理汇总了Python中datadog.dogstatsd.base.DogStatsd.timed方法的典型用法代码示例。如果您正苦于以下问题:Python DogStatsd.timed方法的具体用法?Python DogStatsd.timed怎么用?Python DogStatsd.timed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datadog.dogstatsd.base.DogStatsd
的用法示例。
在下文中一共展示了DogStatsd.timed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDogStatsd
# 需要导入模块: from datadog.dogstatsd.base import DogStatsd [as 别名]
# 或者: from datadog.dogstatsd.base.DogStatsd import timed [as 别名]
#.........这里部分代码省略.........
t.assert_equal('foo.gauge:123.4|g', self.recv())
# Test Client level contant tags
def test_gauge_constant_tags(self):
self.statsd.constant_tags=['bar:baz', 'foo']
self.statsd.gauge('gauge', 123.4)
assert self.recv() == 'gauge:123.4|g|#bar:baz,foo'
def test_counter_constant_tag_with_metric_level_tags(self):
self.statsd.constant_tags=['bar:baz', 'foo']
self.statsd.increment('page.views', tags=['extra'])
t.assert_equal('page.views:1|c|#extra,bar:baz,foo', self.recv())
def test_gauge_constant_tags_with_metric_level_tags_twice(self):
metric_level_tag = ['foo:bar']
self.statsd.constant_tags=['bar:baz']
self.statsd.gauge('gauge', 123.4, tags=metric_level_tag)
assert self.recv() == 'gauge:123.4|g|#foo:bar,bar:baz'
# sending metrics multiple times with same metric-level tags
# should not duplicate the tags being sent
self.statsd.gauge('gauge', 123.4, tags=metric_level_tag)
assert self.recv() == 'gauge:123.4|g|#foo:bar,bar:baz'
@staticmethod
def assert_almost_equal(a, b, delta):
assert 0 <= abs(a - b) <= delta, "%s - %s not within %s" % (a, b, delta)
def test_socket_error(self):
self.statsd.socket = BrokenSocket()
self.statsd.gauge('no error', 1)
assert True, 'success'
def test_timed(self):
"""
Measure the distribution of a function's run time.
"""
# In seconds
@self.statsd.timed('timed.test')
def func(a, b, c=1, d=1):
"""docstring"""
time.sleep(0.5)
return (a, b, c, d)
t.assert_equal('func', func.__name__)
t.assert_equal('docstring', func.__doc__)
result = func(1, 2, d=3)
# Assert it handles args and kwargs correctly.
t.assert_equal(result, (1, 2, 1, 3))
packet = self.recv()
name_value, type_ = packet.split('|')
name, value = name_value.split(':')
t.assert_equal('ms', type_)
t.assert_equal('timed.test', name)
self.assert_almost_equal(0.5, float(value), 0.1)
# Repeat, force timer value in milliseconds
@self.statsd.timed('timed.test', use_ms=True)
def func(a, b, c=1, d=1):
"""docstring"""
time.sleep(0.5)
return (a, b, c, d)
示例2: TestDogStatsd
# 需要导入模块: from datadog.dogstatsd.base import DogStatsd [as 别名]
# 或者: from datadog.dogstatsd.base.DogStatsd import timed [as 别名]
#.........这里部分代码省略.........
t.assert_equal('gst:23|g|@0.9|#sampled')
def test_timing(self):
self.statsd.timing('t', 123)
t.assert_equal('t:123|ms', self.recv())
def test_event(self):
self.statsd.event('Title', u'L1\nL2', priority='low', date_happened=1375296969)
t.assert_equal(u'_e{5,6}:Title|L1\\nL2|d:1375296969|p:low', self.recv())
self.statsd.event('Title', u'♬ †øU †øU ¥ºu T0µ ♪',
aggregation_key='key', tags=['t1', 't2:v2'])
t.assert_equal(u'_e{5,19}:Title|♬ †øU †øU ¥ºu T0µ ♪|k:key|#t1,t2:v2', self.recv())
def test_service_check(self):
now = int(time.time())
self.statsd.service_check(
'my_check.name', self.statsd.WARNING,
tags=['key1:val1', 'key2:val2'], timestamp=now,
hostname='i-abcd1234', message=u"♬ †øU \n†øU ¥ºu|m: T0µ ♪")
t.assert_equal(
u'_sc|my_check.name|{0}|d:{1}|h:i-abcd1234|#key1:val1,key2:val2|m:{2}'
.format(self.statsd.WARNING, now, u"♬ †øU \\n†øU ¥ºu|m\: T0µ ♪"), self.recv())
@staticmethod
def assert_almost_equal(a, b, delta):
assert 0 <= abs(a - b) <= delta, "%s - %s not within %s" % (a, b, delta)
def test_socket_error(self):
self.statsd.socket = BrokenSocket()
self.statsd.gauge('no error', 1)
assert True, 'success'
def test_timed(self):
@self.statsd.timed('timed.test')
def func(a, b, c=1, d=1):
"""docstring"""
time.sleep(0.5)
return (a, b, c, d)
t.assert_equal('func', func.__name__)
t.assert_equal('docstring', func.__doc__)
result = func(1, 2, d=3)
# Assert it handles args and kwargs correctly.
t.assert_equal(result, (1, 2, 1, 3))
packet = self.recv()
name_value, type_ = packet.split('|')
name, value = name_value.split(':')
t.assert_equal('ms', type_)
t.assert_equal('timed.test', name)
self.assert_almost_equal(0.5, float(value), 0.1)
def test_timed_context(self):
with self.statsd.timed('timed_context.test'):
time.sleep(0.5)
packet = self.recv()
name_value, type_ = packet.split('|')
name, value = name_value.split(':')
t.assert_equal('ms', type_)
t.assert_equal('timed_context.test', name)