python 监控系统 statsd+graphite

一.安装statsd

1. statsd+graphite安装过程有点复杂,依赖好几个框架,幸好有了docker,一条命令搞定

docker pull hopsoft/graphite-statsd

使用参考项目网站:https://github.com/hopsoft/docker-graphite-statsd

2. 启动:
docker run -d --name graphite --restart=always -p 5100:80 -p 5101:81 -p 2003-2004:2003-2004 -p 2023-2024:2023-2024 -p 8125:8125/udp -p 8126:8126 hopsoft/graphite-statsd

其中 5100:80端口是grafana应用,5101:81是graphite,都是web端口
8125和8126是statsd端口。
可以修改5100以及5101为自己需要的端口,但不能修改80和81,否则无法正常启动运行。

3.查看

docker ps -a

4.测试数据

while true; do echo -n “example:$((RANDOM % 100))|c” | nc -w 1 -u 127.0.0.1 8125; done

5.查看数据

访问ip:port http://120.1.20.1:5101

6.杀掉

docker rm -f graphite

二.与gunicorn 结合

https://gunicorn-docs.readthedocs.io/en/latest/instrumentation.html

示例:

gunicorn -w 9 -k gevent -b 0.0.0.0:5102 --statsd-host 0.0.0.0:8125 --statsd-prefix test gun_test:app

猜你喜欢

转载自blog.csdn.net/socct_yj/article/details/123055011