Skip to content

Instantly share code, notes, and snippets.

@perryism
Created November 22, 2024 23:52
Show Gist options
  • Save perryism/9cd08971d2e039afdbe3c69d41836f31 to your computer and use it in GitHub Desktop.
Save perryism/9cd08971d2e039afdbe3c69d41836f31 to your computer and use it in GitHub Desktop.
A local statsd stub
from datetime import datetime
from contextlib import contextmanager
class DummyStatsd:
def increment(self, event, tags=None):
print("*" * 80)
print(f"DummyStatsd.increment(event={event}, tags={tags})")
print("*" * 80)
def histogram(self, event, value, tags=None):
print("*" * 80)
print(f"DummyStatsd.histogram(event={event}, value={value}, tags={tags})")
print("*" * 80)
def distribution(self, event, value, tags=None):
print("*" * 80)
print(f"DummyStatsd.distribution(event={event}, value={value}, tags={tags})")
print("*" * 80)
@contextmanager
def timed(self, event, tags=None):
start_time = datetime.now()
try:
yield
finally:
end_time = datetime.now()
duration = (end_time - start_time).total_seconds()
print("*" * 80)
print(f"DummyStatsd.timed(event={event}, duration={duration}, tags={tags})")
print("*" * 80)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment