Files
zulip/zerver/management/commands/send_stats.py
Tim Abbott 8e7ce7cc79 python: Sort migrations/management command imports with isort.
This is a preparatory commit for using isort for sorting all of our
imports, merging changes to files where we can easily review the
changes as something we're happy with.

These are also files with relatively little active development, which
means we don't expect much merge conflict risk from these changes.
2020-01-14 13:07:47 -08:00

28 lines
941 B
Python

from argparse import ArgumentParser
from typing import Any
from django.conf import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = """Send some stats to statsd."""
def add_arguments(self, parser: ArgumentParser) -> None:
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)
def handle(self, *args: Any, **options: str) -> None:
operation = options['operation']
name = options['name']
val = options['val']
if settings.STATSD_HOST != '':
from statsd import statsd
func = getattr(statsd, operation)
func(name, val)