зеркало из https://github.com/microsoft/statsd.git
Merge pull request #381 from SaveTheRbtz/python
Python example improvement
This commit is contained in:
Коммит
59f8c1eb3b
|
@ -93,8 +93,13 @@ class StatsdClient(object):
|
|||
|
||||
>>> StatsdClient.format("example.format", 2, "T")
|
||||
{'example.format': '2|T'}
|
||||
>>> StatsdClient.format(("example.format31", "example.format37"), "2", "T")
|
||||
{'example.format31': '2|T', 'example.format37': '2|T'}
|
||||
>>> formatted = StatsdClient.format(("example.format31", "example.format37"), "2", "T")
|
||||
>>> formatted['example.format31'] == '2|T'
|
||||
True
|
||||
>>> formatted['example.format37'] == '2|T'
|
||||
True
|
||||
>>> len(formatted)
|
||||
2
|
||||
"""
|
||||
data = {}
|
||||
value = "{0}|{1}".format(value, _type)
|
||||
|
@ -117,8 +122,13 @@ class StatsdClient(object):
|
|||
{}
|
||||
>>> from random import seed
|
||||
>>> seed(1)
|
||||
>>> StatsdClient.sample({"example.sample5": "5", "example.sample7": "7"}, 0.99)
|
||||
{'example.sample5': '5|@0.99', 'example.sample7': '7|@0.99'}
|
||||
>>> sampled = StatsdClient.sample({"example.sample5": "5", "example.sample7": "7"}, 0.99)
|
||||
>>> len(sampled)
|
||||
2
|
||||
>>> sampled['example.sample5']
|
||||
'5|@0.99'
|
||||
>>> sampled['example.sample7']
|
||||
'7|@0.99'
|
||||
>>> StatsdClient.sample({"example.sample5": "5", "example.sample7": "7"}, 0.01)
|
||||
{}
|
||||
"""
|
||||
|
@ -140,6 +150,7 @@ class StatsdClient(object):
|
|||
>>> StatsdClient.send({"example.send":"11|c"}, ("127.0.0.1", 8125))
|
||||
"""
|
||||
# TODO(rbtz@): IPv6 support
|
||||
# TODO(rbtz@): Creating socket on each send is a waste of recources
|
||||
udp_sock = socket(AF_INET, SOCK_DGRAM)
|
||||
# TODO(rbtz@): Add batch support
|
||||
for item in _dict.items():
|
||||
|
|
Загрузка…
Ссылка в новой задаче