2013-04-23 18:51:17 +02:00
|
|
|
|
2017-11-16 00:43:27 +01:00
|
|
|
from argparse import ArgumentParser
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2013-04-18 22:58:19 +02:00
|
|
|
from django.conf import settings
|
2017-11-16 00:43:27 +01:00
|
|
|
from django.core.management.base import BaseCommand
|
2013-04-18 22:58:19 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def add_arguments(self, parser: 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
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def handle(self, *args: Any, **options: 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)
|