Created
August 24, 2018 20:47
-
-
Save chrboehm/46bdb1be1a221716423bd34e581c4391 to your computer and use it in GitHub Desktop.
Statsd Sets for use with WoLpH/python-statsd.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import statsd | |
class Sets(statsd.Client): | |
'''Class to implement a statsd sets message | |
since python-statsd does not have sets. | |
A modified copy of https://python-statsd.readthedocs.io/en/latest/_modules/statsd/raw.html#Raw | |
>>> sets = Sets('test.app') | |
>>> sets.send('name', 12435) | |
True | |
>>> import uuid | |
>>> sets.send('name', str(uuid.uuid4())) | |
True | |
''' | |
def send(self, subname, value): | |
'''Send the data to statsd via self.connection | |
:keyword subname: The subname to report the data to | |
(appended to the client name) | |
:type subname: str | |
:keyword value: The sets value to be recorded | |
''' | |
name = self._get_name(self.name, subname) | |
self.logger.info('%s: %s' % (name, value)) | |
return statsd.Client._send(self, {name: '%s|s' % (value)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment