aiodogstatsd

0.16.0.post0 · active · verified Tue Apr 14

aiodogstatsd is an asyncio-based client for sending metrics to StatsD with support for the DogStatsD extension. It supports gauge, counter, histogram, distribution, and timing metric types. The library is actively maintained, currently at version 0.16.0.post0, and features a consistent release cadence with updates for Python version compatibility and framework integrations.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the aiodogstatsd client using an async context manager and send basic increment, gauge, and timing metrics. The context manager ensures proper connection handling. Environment variables are used for host and port configuration, defaulting to 'localhost' and '9125' respectively.

import asyncio
import os
from aiodogstatsd import Client

async def main():
    # The client uses port 9125 by default, which is common for statsd_exporter.
    # For DataDog Agent or standard StatsD (port 8125), configure explicitly.
    async with Client(host=os.environ.get('STATSD_HOST', 'localhost'), port=int(os.environ.get('STATSD_PORT', '9125'))) as client:
        client.increment("users.online")
        client.gauge("server.cpu.usage", value=42.5, tags={"region": "us-east-1"})
        with client.timeit("db.query.time"): # Context manager for timing
            await asyncio.sleep(0.05)
        print("Metrics sent!")

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →