Sanic¶
aiodogstatsd library can be easily used with Sanic web framework by using listeners and middlewares provided.
At first you need to install aiodogstatsd with required extras:
1 | |
Then you can use code below as is to get initialized client and middlewares:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Optionally you can provide additional configuration to the listeners factory:
client_app_key— a key to store initializedaiodogstatsd.Clientin 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 lookupaiodogstatsd.Clientin application context (default:statsd);request_duration_metric_name— name of request duration metric (default:http_request_duration);collect_not_allowed— collect or not405 Method Not Allowedresponses;collect_not_found— collect or not404 Not Foundresponses.