How to use the datadog.statsd.increment function in datadog

To help you get started, we’ve selected a few datadog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github franc-ist / youtube / youtubebot.py View on Github external
async def on_command_error(ctx, error):
    statsd.increment('bot.commands.errored', 1)
    if isinstance(error, commands.MissingRequiredArgument):
        await send_cmd_help(ctx)
    elif isinstance(error, commands.BadArgument):
        await send_cmd_help(ctx)
    elif isinstance(error, commands.CommandOnCooldown):
        await ctx.send("Woah there, {}. That command is on cooldown!".format(ctx.message.author.mention))
    elif isinstance(error, commands.CommandInvokeError):
        logger.exception("Exception in command '{}'".format(
            ctx.command.qualified_name), exc_info=error.original)
        oneliner = "Error in command '{}' - {}: {}".format(
            ctx.command.qualified_name, type(error.original).__name__,
            str(error.original))
        await ctx.send(oneliner)
    elif isinstance(error, commands.CommandNotFound):
        pass
    elif isinstance(error, commands.CheckFailure):
github fourjr / statsy / cogs / brawlstars.py View on Github external
async def on_typing(self, channel, user, when):
        ctx = NoContext(self.bot, user, channel=channel)
        if self.bot.is_closed() or not await self.__local_check(ctx) or user.bot:
            return

        if isinstance(ctx.channel, discord.TextChannel):
            ctx.language = (await self.bot.mongo.config.guilds.find_one({'guild_id': str(ctx.guild.id)}) or {}).get('language', 'messages')
        else:
            ctx.language = 'messages'

        guild_id = getattr(ctx.guild, 'id', 'DM')
        try:
            datadog.statsd.increment('statsy.magic_caching.check', 1, [f'user:{user.id}', f'guild:{guild_id}', 'game:brawlstars'])
            tag = await self.resolve_tag(ctx, None)

            try:
                player = await self.request('get_player', tag, reason='magic caching')
            except ValueError:
                return

            datadog.statsd.increment('statsy.magic_caching.request', 1, [f'user:{user.id}', f'guild:{guild_id}', 'game:brawlstars'])

            try:
                await self.request('get_club', player.club.tag, reason='magic caching')
            except (AttributeError, IndexError):
                pass
        except (utils.NoTag, commands.CheckFailure, brawlstats.RequestError):
            pass
github getsentry / sentry / src / sentry / metrics / dogstatsd.py View on Github external
def incr(self, key, instance=None, tags=None, amount=1, sample_rate=1):
        if tags is None:
            tags = {}
        if self.tags:
            tags.update(self.tags)
        if instance:
            tags["instance"] = instance
        if tags:
            tags = [u"{}:{}".format(*i) for i in tags.items()]
        statsd.increment(self._get_key(key), amount, sample_rate=sample_rate, tags=tags)
github fourjr / statsy / cogs / clashroyale.py View on Github external
client = kwargs.pop('client', self.cr)
        reason = kwargs.pop('reason', 'command')
        try:
            data = self.cache[f'{method}{args}{kwargs}']
        except KeyError:
            speed = time.time()
            data = await getattr(client, method)(*args, **kwargs)
            speed = time.time() - speed
            self.cache[f'{method}{args}{kwargs}'] = data

            if isinstance(data, list):
                status_code = 'list'
            else:
                status_code = data.response.status

            datadog.statsd.increment('statsy.requests', 1, [
                'game:clashroyale', f'code:{status_code}', f'method:{method}', f'reason:{reason}'
            ])
            datadog.statsd.increment('statsy.api_latency', 1, [
                'game:clashroyale', f'speed:{speed}', f'method:{method}'
            ])
        return data
github b1naryth1ef / rowboat / rowboat / plugins / stats.py View on Github external
def on_message_reaction_remove(self, event):
        statsd.increment('guild.messages.reactions.remove', tags=to_tags({
            'channel_id': event.channel_id,
            'user_id': event.user_id,
            'emoji_id': event.emoji.id,
            'emoji_name': event.emoji.name,
        }))
github Mergifyio / mergify-engine / mergify_engine / worker.py View on Github external
def statsd_task_postrun(sender, **kwargs):
    statsd.increment(
        "celery.task_run", tags=[f"task_name:{sender.name}", "service:celery"]
    )
github b1naryth1ef / rowboat / rowboat / plugins / stats.py View on Github external
def on_message_reaction_add(self, event):
        statsd.increment('guild.messages.reactions.add', tags=to_tags({
            'channel_id': event.channel_id,
            'user_id': event.user_id,
            'emoji_id': event.emoji.id,
            'emoji_name': event.emoji.name,
        }))
github fourjr / statsy / cogs / fortnite.py View on Github external
async def post(self, endpoint, payload, *, reason='command'):
        headers = {
            'Authorization': os.getenv('fortnite'),
            'Content-Type': 'application/x-www-form-urlencoded'
        }
        speed = time.time()
        async with self.session.post(
            'https://fortnite-public-api.theapinetwork.com/prod09' + endpoint,
            data=urlencode(payload), headers=headers
        ) as resp:
            speed = speed - time.time()
            datadog.statsd.increment('statsy.api_latency', 1, [
                'game:fortnite', f'speed:{speed}', f'method:{endpoint}'
            ])
            datadog.statsd.increment('statsy.requests', 1, [
                'game:fortnite', f'code:{resp.status}', f'method:{endpoint}', f'reason:{reason}'
            ])
            if resp.status != 200:
                raise utils.APIError
            try:
                data = await resp.json()
                if not data:
                    raise utils.APIError
            except (json.JSONDecodeError, aiohttp.client_exceptions.ContentTypeError):
                raise utils.APIError
            else:
                return data
github ziquanmiao / minikube_datadog / flask_app / app.py View on Github external
def hello_world():
    datadog.statsd.increment('counter_metric',tags=['endpoint:hello_world'])
    my_thread= threading.currentThread().getName()
    time.sleep(0.01)
    logger.info('hello_world has been executed', 
        extra={
            'job_category': 'hello_world', 
            'logger.name': 'my_json', 
            'logger.thread_name' : my_thread
        }
    )
    time.sleep(random.random()* 2)
    return 'Flask has been kuberneted \n'