from __future__ import absolute_import from django.core.management.base import BaseCommand from django.conf import settings class Command(BaseCommand): help = """Send some stats to statsd.""" def add_arguments(self, parser): parser.add_argument('operation', metavar='', type=str, choices=['incr', 'decr', 'timing', 'timer', 'gauge'], help="incr|decr|timing|timer|gauge") parser.add_argument('name', metavar='', type=str) parser.add_argument('val', metavar='', type=str) def handle(self, *args, **options): operation = options['operation'] name = options['name'] val = options['val'] if settings.USING_STATSD: from statsd import statsd func = getattr(statsd, operation) func(name, val)