2013-04-23 18:51:17 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from argparse import ArgumentParser
|
2013-04-18 22:58:19 +02:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
2015-08-21 02:10:41 +02:00
|
|
|
help = """Send some stats to statsd."""
|
2013-04-18 22:58:19 +02:00
|
|
|
|
2015-08-21 02:10:41 +02:00
|
|
|
def add_arguments(self, parser):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (ArgumentParser) -> None
|
2015-08-21 02:10:41 +02:00
|
|
|
parser.add_argument('operation', metavar='<operation>', type=str,
|
|
|
|
choices=['incr', 'decr', 'timing', 'timer', 'gauge'],
|
|
|
|
help="incr|decr|timing|timer|gauge")
|
|
|
|
parser.add_argument('name', metavar='<name>', type=str)
|
|
|
|
parser.add_argument('val', metavar='<val>', type=str)
|
2013-04-18 22:58:19 +02:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (*Any, **str) -> None
|
2015-08-21 02:10:41 +02:00
|
|
|
operation = options['operation']
|
|
|
|
name = options['name']
|
|
|
|
val = options['val']
|
2013-04-18 22:58:19 +02:00
|
|
|
|
2015-08-22 22:18:55 +02:00
|
|
|
if settings.STATSD_HOST != '':
|
2013-04-18 22:58:19 +02:00
|
|
|
from statsd import statsd
|
|
|
|
|
|
|
|
func = getattr(statsd, operation)
|
|
|
|
func(name, val)
|