本文整理汇总了Python中datadog.dogstatsd.base.DogStatsd.socket方法的典型用法代码示例。如果您正苦于以下问题:Python DogStatsd.socket方法的具体用法?Python DogStatsd.socket怎么用?Python DogStatsd.socket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datadog.dogstatsd.base.DogStatsd
的用法示例。
在下文中一共展示了DogStatsd.socket方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_tags_from_environment_and_constant
# 需要导入模块: from datadog.dogstatsd.base import DogStatsd [as 别名]
# 或者: from datadog.dogstatsd.base.DogStatsd import socket [as 别名]
def test_tags_from_environment_and_constant(self):
with preserve_environment_variable('DATADOG_TAGS'):
os.environ['DATADOG_TAGS'] = 'country:china,age:45,blue'
statsd = DogStatsd(constant_tags=['country:canada', 'red'])
statsd.socket = FakeSocket()
statsd.gauge('gt', 123.4)
t.assert_equal('gt:123.4|g|#country:canada,red,country:china,age:45,blue', statsd.socket.recv())
示例2: test_timing
# 需要导入模块: from datadog.dogstatsd.base import DogStatsd [as 别名]
# 或者: from datadog.dogstatsd.base.DogStatsd import socket [as 别名]
def test_timing(self):
"""
Timings can be submitted from concurrent threads.
"""
# Create a DogStatsd client with a mocked socket
statsd = DogStatsd()
statsd.socket = self.socket
# Samples
values = set(range(10000))
# Submit metrics from different threads
self._submit_with_multiple_threads(statsd, "timing", values)
# All metrics were properly submitted
self.assertMetrics(values)
示例3: test_decrement
# 需要导入模块: from datadog.dogstatsd.base import DogStatsd [as 别名]
# 或者: from datadog.dogstatsd.base.DogStatsd import socket [as 别名]
def test_decrement(self):
"""
Decrements can be submitted from concurrent threads.
"""
# Create a DogStatsd client with a mocked socket
statsd = DogStatsd()
statsd.socket = self.socket
# Samples
values = set(range(10000))
expected_value = set([-value for value in values])
# Submit metrics from different threads
self._submit_with_multiple_threads(statsd, "decrement", expected_value)
# All metrics were properly submitted
self.assertMetrics(values)
示例4: test_timed_context_manager_threaded
# 需要导入模块: from datadog.dogstatsd.base import DogStatsd [as 别名]
# 或者: from datadog.dogstatsd.base.DogStatsd import socket [as 别名]
def test_timed_context_manager_threaded(self, mock_time):
"""
`timed` context manager plays well with concurrent threads.
"""
# Create a DogStatsd client with a mocked socket
statsd = DogStatsd()
statsd.socket = self.socket
# Set up the mocked time
mock_time.return_value = 0
# Method to time
def bar():
"""
Wait 5 time units and return.
"""
initial_time = mock_time.return_value
with statsd.timed("foo"):
while mock_time.return_value < initial_time + 2:
pass
# Run the method within multiple threads
threads = []
for value in range(10):
t = threading.Thread(target=bar)
threads.append(t)
# Bump time so that previous thread can complete
mock_time.return_value += 1
t.start()
# Sleep to let the threads start
time.sleep(0.1)
# Bump time so that all threads completes
time.sleep(0.1)
mock_time.return_value += 1
time.sleep(0.1)
mock_time.return_value += 1
for t in threads:
t.join()
# All metrics were properly submitted
expected_values = [2 for _ in xrange(0, 10)]
self.assertMetrics(expected_values)
示例5: test_accessing_socket_multiple_times_returns_same_socket
# 需要导入模块: from datadog.dogstatsd.base import DogStatsd [as 别名]
# 或者: from datadog.dogstatsd.base.DogStatsd import socket [as 别名]
def test_accessing_socket_multiple_times_returns_same_socket(self):
dogpound = DogStatsd()
fresh_socket = FakeSocket()
dogpound.socket = fresh_socket
t.assert_equal(fresh_socket, dogpound.get_socket())
t.assert_not_equal(FakeSocket(), dogpound.get_socket())