Skip to content

Instantly share code, notes, and snippets.

@chrboehm
Created August 24, 2018 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrboehm/46bdb1be1a221716423bd34e581c4391 to your computer and use it in GitHub Desktop.
Save chrboehm/46bdb1be1a221716423bd34e581c4391 to your computer and use it in GitHub Desktop.
Statsd Sets for use with WoLpH/python-statsd.
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