Skip to content

Instantly share code, notes, and snippets.

@cypreess
Last active January 18, 2019 14:06
Show Gist options
  • Save cypreess/dfd8814dd8a242cfbd27b10fd8753e71 to your computer and use it in GitHub Desktop.
Save cypreess/dfd8814dd8a242cfbd27b10fd8753e71 to your computer and use it in GitHub Desktop.
metrics.py
import statsd
from django.conf import settings
statsd_client = statsd.StatsClient(
settings.METRICS_STATSD_HOST, settings.METRICS_STATSD_PORT
)
def metric_counter(key, value=1):
if settings.METRICS_ENABLED:
statsd_client.incr(key, value)
def metric_counter_decrement(key, value=1):
if settings.METRICS_ENABLED:
statsd_client.decr(key, value)
def metric_timing(key, value):
if settings.METRICS_ENABLED:
statsd_client.timing(key, value)
def metric_gauge(key, value):
if settings.METRICS_ENABLED:
statsd_client.gauge(key, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment