docker部署grafana graphite stastd实时监控告警配置_亲测成功
实时监控请求的次数和响应时间及异常报警
项目中需要监控API接口的调用情况,如:调用次数,每次调用耗时,调用高峰期,异常报警等
grafana graphite stastd这一套对代码没有侵入,也不会影响接口性能
安装docker环境
Centos7离线安装Docker
华为云arm架构安装Docker
树莓派4B raspberrypi在线安装Docker
graphite和stastd安装启动
docker run -d --name graphite \
-p 192.168.1.53:8070:80 -p 192.168.1.53:2023:2023 -p 192.168.1.53:8125:8125/udp \
-v /data/graphite/conf:/opt/graphite/conf/ \
-v /data/graphite/storage:/opt/graphite/storage/ \
hopsoft/graphite-statsd192.168.1.53为服务器内网ipDocker hub官方启动命令如下:
docker run -d \--name graphite \--restart=always \-p 8070:80 \-p 8071:81 \-p 2003-2004:2003-2004 \-p 2023-2024:2023-2024 \-p 8125:8125/udp \-p 8126:8126 \
-v /data/graphite/conf:/opt/graphite/conf/ \
-v /data/graphite/storage:/opt/graphite/storage/ \hopsoft/graphite-statsdhttps://hub.docker.com/r/hopsoft/graphite-statsd
80 80 nginx - grafana
81 81 nginx - graphite
2003 2003 carbon receiver - plaintext
2004 2004 carbon receiver - pickle
2023 2023 carbon aggregator - plaintext
2024 2024 carbon aggregator - pickle
8125 8125 statsd
8126 8126 statsd admin#stastd配置创建statsd的配置文件config_udp.js,内容如下:vim config_udp.js{"graphiteHost": "127.0.0.1","graphitePort": 2003,"port": 8125,"flushInterval": 10000,"graphite": {"legacyNamespace": false,"globalPrefix": "","prefixCounter": "","prefixTimer": "","prefixGauge": "","prefixSet": ""},"servers": [{ server: "./servers/udp", address: "0.0.0.0", port: 8125 }]}复制到容器里
docker cp config_udp.js graphite:/opt/statsd/config_udp.js重启容器
docker restart graphite########老版本的配置statsd创建statsd的配置文件config.js,内容如下:{"graphiteHost": "127.0.0.1","graphitePort": 2023,"port": 8125,"flushInterval": 10000,"deleteIdleStats": true,"graphite": {"legacyNamespace": false,"globalPrefix": "","prefixCounter": "","prefixTimer": "","prefixGauge": "","prefixSet": ""}
}更新配置:
docker cp config.js graphite:/opt/statsd/config.js重启服务
docker restart graphite
grafana安装启动
docker run -d --name grafana \
-p 192.168.1.53:3000:3000 \
-e "GF_AUTH_ANONYMOUS_ENABLED=true" \
grafana/grafanadocker run -d --name grafana \
-p 3000:3000 \
-e "GF_AUTH_ANONYMOUS_ENABLED=true" \
grafana/grafanadocker run -d --name grafana \
-p 192.168.1.53:3000:3000 \
-v /var/lib/grafana:/var/lib/grafana \
-e "GF_AUTH_ANONYMOUS_ENABLED=true" \
grafana/grafana192.168.1.53为服务器内网ip访问
http://192.168.1.53:3000
grafana邮件告警配置
[smtp]
enabled = true
host = mail.e-xxxx.com.cn:25
user = xxxxx
#If the password contains # or ; you have to wrap it with trippel quotes. Ex “”“#password;”“”
password = “”“abcd2022###”“”
;cert_file =
;key_file =
skip_verify = true
from_address = beyondxxxx@e-xxxx.com.cn
[alerting]
#Makes it possible to turn off alert rule execution.
execute_alerts = true
#搜索localhost 把地址改为对应访问ip地址,收到邮件时点击链接,不是localhost
root_url = http://10.10.x.xx:3000
参考链接:
https://github.com/hopsoft/docker-graphite-statsd
https://www.bbsmax.com/R/E35plmB5vX/