{"id":21704135,"url":"https://github.com/so1n/aiostatsd","last_synced_at":"2025-07-24T07:33:27.367Z","repository":{"id":54392743,"uuid":"242765200","full_name":"so1n/aiostatsd","owner":"so1n","description":"an asyncio-based client for send metric to StatsD, Graphite.carbon and DogStatsD.","archived":false,"fork":false,"pushed_at":"2024-03-30T15:08:26.000Z","size":76,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-05T17:04:40.531Z","etag":null,"topics":["asyncio","carbon","dogstatsd","graphite","statsd-client"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/so1n.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-02-24T15:01:04.000Z","updated_at":"2024-02-07T13:02:03.000Z","dependencies_parsed_at":"2025-04-12T15:43:49.940Z","dependency_job_id":null,"html_url":"https://github.com/so1n/aiostatsd","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/so1n/aiostatsd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/so1n%2Faiostatsd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/so1n%2Faiostatsd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/so1n%2Faiostatsd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/so1n%2Faiostatsd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/so1n","download_url":"https://codeload.github.com/so1n/aiostatsd/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/so1n%2Faiostatsd/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266808521,"owners_count":23987450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncio","carbon","dogstatsd","graphite","statsd-client"],"created_at":"2024-11-25T21:43:54.895Z","updated_at":"2025-07-24T07:33:27.305Z","avatar_url":"https://github.com/so1n.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## aiostasd\nan asyncio-based client for send metric to `StatsD`, `Graphite.carbon`, `TelegrafStatsD` and `DogStatsD`.\n\n## Installation\n```Bash\npip install aio_statsd\n```\n## Usage\n### Usage Client\nCreate connection and send gauge metric.\naiostatsd client will automatically send messages in the background when the loop is running\n```Python\nimport asyncio\n\nfrom aio_statsd import StatsdClient\n\nloop = asyncio.get_event_loop()\nclient = StatsdClient()\nloop.run_until_complete(client.connect())\nclient.gauge('test.key', 1)\nloop.run_forever()\n```\nUse context manager\n```Python\nimport asyncio\n\nfrom aio_statsd import StatsdClient\n\n\nasync def main():\n    async with StatsdClient() as client:\n        client.gauge('test.key', 1)\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(main())\n```\n### Client param\n- host: default value 'localhost', Statsd Server ip\n- port: default value 8125, Statsd Server port\n- protocol: default value ProtocolFlag.udp, Transport Layer Prrotocol, Select Tcp:`ProtocolFlag.udp` or Udp:`ProtocolFlag.tcp` \n- timeout: default value 0, send msg timeout, if timeout==0, not enable timeout\n- debug: default value False, enable debug\n- close_timeout: default value 9, Within a few seconds after the client is closed, continue to send messages which in the queue\n- create_timeout: default value 9, Create connection timeout\n- max_len: default value 10000, deque length\n- sample_rate(Use in StatsD Client, DogStatsD Client): default value 1, use sample rate in Statsd or DogStatsD\n### send metric\n```Python\nimport asyncio\n\nfrom aio_statsd import StatsdClient\n\n\nasync def main():\n    async with StatsdClient() as client:\n        client.gauge('test.key', 1)\n        client.counter('test.key', 1)\n        client.sets('test.key', 1)\n        client.timer('test.key', 1)\n        with client.timeit('test'):\n            pass  # run your code\n        \n        # all metric support sample rate\n        client.gauge('test1.key', 1, sample_rate=0.5)\n        \n        # mutli metric support(not support sample rate, the sample rate will always be set to 1)\n        from aio_statsd import StatsdProtocol\n        metric = StatsdProtocol()   \n        metric.gauge('test2.key', 1)\n        metric.sets('test2.key', 1)\n        client.send_statsd(metric)     \n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(main())\n```\n### Other Client\n#### Graphite(carbon)\n```python\nimport asyncio\n\nfrom aio_statsd import GraphiteClient\n\nloop = asyncio.get_event_loop()\nclient = GraphiteClient()\nloop.run_until_complete(client.connect())\nclient.send_graphite('test.key', 1) # Multiple clients timestamp interval synchronization\nloop.run_forever()\n```\n#### DogStatsD\n\u003eNote: Not tested in production\n```python\nimport asyncio\n\nfrom aio_statsd import DogStatsdClient\n\n\nasync def main():\n    async with DogStatsdClient() as client:\n        client.gauge('test.key', 1)\n        client.distribution('test.key', 1)\n        client.increment('test.key',1)\n        client.histogram('test.key', 1)\n        client.timer('test.key', 1)\n        with client.timeit('test'):\n            pass  # run your code\n        \n        # all metric support sample rate and DogStatsD tag\n        client.gauge('test1.key', 1, sample_rate=0.5, tag_dict={'tag': 'tag1'})\n        \n        # mutli metric support(\n        #   DogStatsdProtocol will store the message in its own queue and\n        #   DogStatsDClient traverses to read DogStatsdProtocol's message and send it\n        # )\n        from aio_statsd import DogStatsdProtocol\n        metric = DogStatsdProtocol()   \n        metric.gauge('test2.key', 1, tag_dict={'tag': 'tag1'})\n        metric.histogram('test2.key', 1)\n        client.send_dog_statsd(metric, sample_rate=0.5)\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(main())\n```\n#### TelegrafStatsd\n\u003eNote: Not tested in production\n```python\nimport asyncio\n\nfrom aio_statsd import TelegrafStatsdClient\n\n\nasync def main():\n    async with TelegrafStatsdClient() as client:\n        client.gauge('test.key', 1)\n        client.distribution('test.key', 1)\n        client.increment('test.key',1)\n        client.histogram('test.key', 1)\n        client.timer('test.key', 1)\n        with client.timeit('test'):\n            pass  # run your code\n        \n        # all metric support sample rate and TelegrafStatsd tag\n        client.gauge('test1.key', 1, sample_rate=0.5, tag_dict={'tag': 'tag1'})\n        \n        # mutli metric support(\n        #   TelegrafStatsdProtocol will store the message in its own queue and\n        #   TelegrafStatsDClient traverses to read TelegrafStatsdProtocol's message and send it\n        # )\n        from aio_statsd import TelegrafStatsdProtocol \n        metric = TelegrafStatsdProtocol()   \n        metric.gauge('test2.key', 1, tag_dict={'tag': 'tag1'})\n        metric.histogram('test2.key', 1)\n        client.send_telegraf_statsd(metric, sample_rate=0.5)\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(main())\n```\n#### Telegraf\n\u003eNote: Not tested in production\n```Python\nimport asyncio\n\nfrom aio_statsd import TelegrafClient\n\n\nasync def main():\n    async with TelegrafClient() as client:\n        client.send_telegraf('test.key', {\"field1\": 100}, user_server_time=True)\n```\n### Use in web frameworks\n[fast_tools example](https://github.com/so1n/fast-tools/blob/master/example/statsd_middleware.py)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fso1n%2Faiostatsd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fso1n%2Faiostatsd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fso1n%2Faiostatsd/lists"}