-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
345 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# AIOHTTP | ||
|
||
`aiodogstatsd` library can be easily used with [`AIOHTTP`](https://aiohttp.readthedocs.io/) web framework by using cleanup context and middleware provided. | ||
|
||
At first you need to install `aiodogstatsd` with required extras: | ||
|
||
```sh | ||
pip install aiodogstatsd[aiohttp] | ||
``` | ||
|
||
Then you can use code below as is to get initialized client and middleware: | ||
|
||
```python | ||
from aiohttp import web | ||
|
||
from aiodogstatsd.contrib import aiohttp as aiodogstatsd | ||
|
||
|
||
app = web.Application(middlewares=[aiodogstatsd.middleware_factory()]) | ||
app.cleanup_ctx.append(aiodogstatsd.cleanup_context_factory()) | ||
``` | ||
|
||
Optionally you can provide additional configuration to the cleanup context factory: | ||
|
||
- `client_app_key` — a key to store initialized `aiodogstatsd.Client` in application context (default: `statsd`); | ||
- `host` — host string of your StatsD server (default: `localhost`); | ||
- `port` — post of your StatsD server (default: `9125`); | ||
- `namespace` — optional namespace string to prefix all metrics; | ||
- `constant_tags` — optional tags dictionary to apply to all metrics; | ||
- `read_timeout` (default: `0.5`); | ||
- `close_timeout`; | ||
- `sample_rate` (default: `1`). | ||
|
||
Optionally you can provide additional configuration to the middleware factory: | ||
|
||
- `client_app_key` — a key to lookup `aiodogstatsd.Client` in application context (default: `statsd`); | ||
- `request_duration_metric_name` — name of request duration metric (default: `http_request_duration`); | ||
- `collect_not_allowed` — collect or not `405 Method Not Allowed` responses; | ||
- `collect_not_found` — collect or not `404 Not Found` responses. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Sanic | ||
|
||
`aiodogstatsd` library can be easily used with [`Sanic`](https://sanicframework.org/) web framework by using listeners and middlewares provided. | ||
|
||
At first you need to install `aiodogstatsd` with required extras: | ||
|
||
```sh | ||
pip install aiodogstatsd[sanic] | ||
``` | ||
|
||
Then you can use code below as is to get initialized client and middlewares: | ||
|
||
```python | ||
from sanic import Sanic | ||
|
||
from aiodogstatsd.contrib import sanic as aiodogstatsd | ||
|
||
|
||
app = Sanic(name="aiodogstatsd") | ||
|
||
listener_setup, listener_close = aiodogstatsd.listeners_factory() | ||
app.register_listener(listener_setup, "before_server_start") | ||
app.register_listener(listener_close, "after_server_stop") | ||
|
||
middleware_req, middleware_resp = aiodogstatsd.middlewares_factory() | ||
app.register_middleware(middleware_req, attach_to="request") | ||
app.register_middleware(middleware_resp, attach_to="response") | ||
``` | ||
|
||
Optionally you can provide additional configuration to the listeners factory: | ||
|
||
- `client_app_key` — a key to store initialized `aiodogstatsd.Client` in application context (default: `statsd`); | ||
- `host` — host string of your StatsD server (default: `localhost`); | ||
- `port` — post of your StatsD server (default: `9125`); | ||
- `namespace` — optional namespace string to prefix all metrics; | ||
- `constant_tags` — optional tags dictionary to apply to all metrics; | ||
- `read_timeout` (default: `0.5`); | ||
- `close_timeout`; | ||
- `sample_rate` (default: `1`). | ||
|
||
Optionally you can provide additional configuration to the middlewares factory: | ||
|
||
- `client_app_key` — a key to lookup `aiodogstatsd.Client` in application context (default: `statsd`); | ||
- `request_duration_metric_name` — name of request duration metric (default: `http_request_duration`); | ||
- `collect_not_allowed` — collect or not `405 Method Not Allowed` responses; | ||
- `collect_not_found` — collect or not `404 Not Found` responses. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Starlette | ||
|
||
`aiodogstatsd` library can be easily used with [`Starlette`](https://www.starlette.io) web framework by using client and middleware provided. | ||
|
||
At first you need to install `aiodogstatsd` with required extras: | ||
|
||
```sh | ||
pip install aiodogstatsd[starlette] | ||
``` | ||
|
||
Then you can use code below as is to get initialized client and middleware: | ||
|
||
```python | ||
from starlette.applications import Starlette | ||
from starlette.middleware import Middleware | ||
|
||
import aiodogstatsd | ||
from aiodogstatsd.contrib.starlette import StatsDMiddleware | ||
|
||
|
||
client = aiodogstatsd.Client() | ||
|
||
app = Starlette( | ||
middleware=[Middleware(StatsDMiddleware, client=client)], | ||
on_startup=[client.connect], | ||
on_shutdown=[client.close], | ||
) | ||
``` | ||
|
||
Optionally you can provide additional configuration to the middleware: | ||
|
||
- `request_duration_metric_name` — name of request duration metric (default: `http_request_duration`); | ||
- `collect_not_allowed` — collect or not `405 Method Not Allowed` responses; | ||
- `collect_not_found` — collect or not `404 Not Found` responses. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# aiodogstatsd | ||
|
||
[![Build Status](https://github.com/Gr1N/aiodogstatsd/workflows/default/badge.svg)](https://github.com/Gr1N/aiodogstatsd/actions?query=workflow%3Adefault) [![codecov](https://codecov.io/gh/Gr1N/aiodogstatsd/branch/master/graph/badge.svg)](https://codecov.io/gh/Gr1N/aiodogstatsd) ![PyPI](https://img.shields.io/pypi/v/aiodogstatsd.svg?label=pypi%20version) ![PyPI - Downloads](https://img.shields.io/pypi/dm/aiodogstatsd.svg?label=pypi%20downloads) ![GitHub](https://img.shields.io/github/license/Gr1N/aiodogstatsd.svg) | ||
|
||
`aiodogstatsd` is an asyncio-based client for sending metrics to StatsD with support of [DogStatsD](https://docs.datadoghq.com/developers/dogstatsd/) extension. | ||
|
||
Library fully tested with [statsd_exporter](https://github.com/prometheus/statsd_exporter) and supports `gauge`, `counter`, `histogram`, `distribution` and `timing` types. | ||
|
||
!!! info | ||
`aiodogstatsd` client by default uses _9125_ port. It's a default port for [statsd_exporter](https://github.com/prometheus/statsd_exporter) and it's different from _8125_ which is used by default in StatsD and [DataDog](https://www.datadoghq.com/). Initialize the client with the proper port you need if it's different from _9125_. | ||
|
||
## Installation | ||
|
||
Just type: | ||
|
||
```sh | ||
pip install aiodogstatsd | ||
``` | ||
|
||
...or if you're interested in integration with [`AIOHTTP`](https://aiohttp.readthedocs.io/), [`Sanic`](https://sanicframework.org/) or [`Starlette`](https://www.starlette.io) frameworks specify corresponding extras: | ||
|
||
```sh | ||
pip install aiodogstatsd[aiohttp,sanic,starlette] | ||
``` | ||
|
||
## At a glance | ||
|
||
Just simply use client as a context manager and send any metric you want: | ||
|
||
```python | ||
import asyncio | ||
|
||
import aiodogstatsd | ||
|
||
|
||
async def main(): | ||
async with aiodogstatsd.Client() as client: | ||
client.increment("users.online") | ||
|
||
|
||
asyncio.run(main()) | ||
``` |
Oops, something went wrong.