当前位置:网站首页>golang-gin-pprof-使用以及安全问题
golang-gin-pprof-使用以及安全问题
2022-07-31 13:01:00 【SakuraKizuna】
pprof是golang的提供的性能分析工具
直接通过引用github.com/gin-contrib/pprof即可调用
项目代码节选展示:
//性能调优监视 TODO Gin自主隐藏,待优化
authStr := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(config.ProducerUsername+":"+config.ProducerPassword)))
pprofGroup := r.Group("/producer", func(c *gin.Context) {
auth := c.Request.Header.Get("Authorization")
if auth != authStr {
c.Header("www-Authenticate", "Basic")
c.AbortWithStatus(http.StatusUnauthorized)
return
}
c.Next()
})
pprof.RouteRegister(pprofGroup, "flowerxxxxx_pprof")
Gin框架所携带的pprof直接调用即可,但是在生产环境中会引发暴露的问题,导致/debug/pprof接口暴露到公网。
我们将接口注册到新的路由组里,并且将(账号+冒号+密码)Base64后并添加Basic标识,即可触发访问也要输入账号和密码的保护机制。

项目(中小型)pprof分析概览,可查看是否存在goroutine死锁或者cpu异常占用问题。

边栏推荐
- NameNode (NN) 和SecondaryNameNode (2NN)工作机制
- 基于verilog的CRC校验(汇总)
- Fully Dynamically Constrained Robot Efficient Time-Optimal Trajectory Planning
- 电商rpa是什么意思?跟电商rpi是一个意思吗?
- 报错IDEA Terminated with exit code 1
- 中望3D 2023正式发布,设计仿真制造一体化缩短产品开发周期
- Selenium自动化测试之Selenium IDE
- PAT exam summary (exam experience)
- Ali on three sides: MQ message loss, repetition, backlog problem, how to solve?
- IDEA的database使用教程(使用mysql数据库)
猜你喜欢
随机推荐
Indoor real-time laser SLAM control method based on biological excitation neural network
Basic use of dosbox [easy to understand]
求一份常见Oracle故障模拟场景
Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法
阿里三面:MQ 消息丢失、重复、积压问题,怎么解决?
IDEA的database使用教程(使用mysql数据库)
使用openssl命令生成证书和对应的私钥,私钥签名,公钥验签
Build a Valentine's Day confession website (super detailed process, package teaching package)
Flutter keyboard visibility
SAP ABAP OData 服务如何支持 $filter (过滤)操作试读版
C# List用法 List介绍
FastAPI encapsulates a generic response
[RPI]树莓派监控温度及报警关机保护「建议收藏」
如何使用StarUML画类图[通俗易懂]
Getting started with jmeter performance testing steps (performance testing tool jmeter)
基于神经网络的多柔性梁耦合结构振动控制
Cognitive-exercise rehabilitation medical robot application design
FIFO深度计算学习记录(汇总)
SAP 电商云 Spartacus SSR Optimization Engine 几处 timeout 的执行顺序
全动力学约束的机器人高效时间最优轨迹规划









