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
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
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:
|
2021-02-12 08:19:30 +01:00
|
|
|
parser.add_argument(
|
2021-02-12 08:20:45 +01:00
|
|
|
"operation",
|
|
|
|
metavar="<operation>",
|
|
|
|
choices=["incr", "decr", "timing", "timer", "gauge"],
|
2021-02-12 08:19:30 +01:00
|
|
|
help="incr|decr|timing|timer|gauge",
|
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
parser.add_argument("name", metavar="<name>")
|
|
|
|
parser.add_argument("val", metavar="<val>")
|
2013-04-18 22:58:19 +02:00
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def handle(self, *args: Any, **options: str) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
operation = options["operation"]
|
|
|
|
name = options["name"]
|
|
|
|
val = options["val"]
|
2013-04-18 22:58:19 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
if settings.STATSD_HOST != "":
|
2013-04-18 22:58:19 +02:00
|
|
|
from statsd import statsd
|
|
|
|
|
|
|
|
func = getattr(statsd, operation)
|
|
|
|
func(name, val)
|