本文整理汇总了Python中datadog.dogstatsd.base.DogStatsd.histogram方法的典型用法代码示例。如果您正苦于以下问题:Python DogStatsd.histogram方法的具体用法?Python DogStatsd.histogram怎么用?Python DogStatsd.histogram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datadog.dogstatsd.base.DogStatsd
的用法示例。
在下文中一共展示了DogStatsd.histogram方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDogStatsd
# 需要导入模块: from datadog.dogstatsd.base import DogStatsd [as 别名]
# 或者: from datadog.dogstatsd.base.DogStatsd import histogram [as 别名]
class TestDogStatsd(object):
def setUp(self):
self.statsd = DogStatsd()
self.statsd.socket = FakeSocket()
def recv(self):
return self.statsd.socket.recv()
def test_initialization(self):
options = {
'statsd_host': "myhost",
'statsd_port': 1234
}
t.assert_equal(statsd.host, "localhost")
t.assert_equal(statsd.port, 8125)
initialize(**options)
t.assert_equal(statsd.host, "myhost")
t.assert_equal(statsd.port, 1234)
def test_set(self):
self.statsd.set('set', 123)
assert self.recv() == 'set:123|s'
def test_gauge(self):
self.statsd.gauge('gauge', 123.4)
assert self.recv() == 'gauge:123.4|g'
def test_counter(self):
self.statsd.increment('page.views')
t.assert_equal('page.views:1|c', self.recv())
self.statsd.increment('page.views', 11)
t.assert_equal('page.views:11|c', self.recv())
self.statsd.decrement('page.views')
t.assert_equal('page.views:-1|c', self.recv())
self.statsd.decrement('page.views', 12)
t.assert_equal('page.views:-12|c', self.recv())
def test_histogram(self):
self.statsd.histogram('histo', 123.4)
t.assert_equal('histo:123.4|h', self.recv())
def test_tagged_gauge(self):
self.statsd.gauge('gt', 123.4, tags=['country:china', 'age:45', 'blue'])
t.assert_equal('gt:123.4|g|#country:china,age:45,blue', self.recv())
def test_tagged_counter(self):
self.statsd.increment('ct', tags=['country:canada', 'red'])
t.assert_equal('ct:1|c|#country:canada,red', self.recv())
def test_tagged_histogram(self):
self.statsd.histogram('h', 1, tags=['red'])
t.assert_equal('h:1|h|#red', self.recv())
def test_sample_rate(self):
self.statsd.increment('c', sample_rate=0)
assert not self.recv()
for i in range(10000):
self.statsd.increment('sampled_counter', sample_rate=0.3)
self.assert_almost_equal(3000, len(self.statsd.socket.payloads), 150)
t.assert_equal('sampled_counter:1|c|@0.3', self.recv())
def test_tags_and_samples(self):
for i in range(100):
self.statsd.gauge('gst', 23, tags=["sampled"], sample_rate=0.9)
def test_tags_and_samples(self):
for i in range(100):
self.statsd.gauge('gst', 23, tags=["sampled"], sample_rate=0.9)
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_event_constant_tags(self):
self.statsd.constant_tags = ['bar:baz', 'foo']
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|#bar:baz,foo', 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,bar:baz,foo', self.recv())
def test_service_check(self):
now = int(time.time())
self.statsd.service_check(
'my_check.name', self.statsd.WARNING,
#.........这里部分代码省略.........
示例2: TestDogStatsd
# 需要导入模块: from datadog.dogstatsd.base import DogStatsd [as 别名]
# 或者: from datadog.dogstatsd.base.DogStatsd import histogram [as 别名]
class TestDogStatsd(object):
def setUp(self):
self.statsd = DogStatsd()
self.statsd.socket = FakeSocket()
def recv(self):
return self.statsd.socket.recv()
def test_initialization(self):
options = {
'statsd_host': "myhost",
'statsd_port': 1234
}
t.assert_equal(statsd.host, "localhost")
t.assert_equal(statsd.port, 8125)
initialize(**options)
t.assert_equal(statsd.host, "myhost")
t.assert_equal(statsd.port, 1234)
def test_set(self):
self.statsd.set('set', 123)
assert self.recv() == 'set:123|s'
def test_gauge(self):
self.statsd.gauge('gauge', 123.4)
assert self.recv() == 'gauge:123.4|g'
def test_counter(self):
self.statsd.increment('page.views')
t.assert_equal('page.views:1|c', self.recv())
self.statsd.increment('page.views', 11)
t.assert_equal('page.views:11|c', self.recv())
self.statsd.decrement('page.views')
t.assert_equal('page.views:-1|c', self.recv())
self.statsd.decrement('page.views', 12)
t.assert_equal('page.views:-12|c', self.recv())
def test_histogram(self):
self.statsd.histogram('histo', 123.4)
t.assert_equal('histo:123.4|h', self.recv())
def test_tagged_gauge(self):
self.statsd.gauge('gt', 123.4, tags=['country:china', 'age:45', 'blue'])
t.assert_equal('gt:123.4|g|#country:china,age:45,blue', self.recv())
def test_tagged_counter(self):
self.statsd.increment('ct', tags=['country:canada', 'red'])
t.assert_equal('ct:1|c|#country:canada,red', self.recv())
def test_tagged_histogram(self):
self.statsd.histogram('h', 1, tags=['red'])
t.assert_equal('h:1|h|#red', self.recv())
def test_sample_rate(self):
self.statsd.increment('c', sample_rate=0)
assert not self.recv()
for i in range(10000):
self.statsd.increment('sampled_counter', sample_rate=0.3)
self.assert_almost_equal(3000, len(self.statsd.socket.payloads), 150)
t.assert_equal('sampled_counter:1|c|@0.3', self.recv())
def test_tags_and_samples(self):
for i in range(100):
self.statsd.gauge('gst', 23, tags=["sampled"], sample_rate=0.9)
def test_tags_and_samples(self):
for i in range(100):
self.statsd.gauge('gst', 23, tags=["sampled"], sample_rate=0.9)
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)
#.........这里部分代码省略.........