statsviz 运行时统计信息
最后更新于:2022-04-02 02:52:06
[TOC]
> [github](https://github.com/arl/statsviz)
## 概述
### 流程
1. Import "github.com/arl/statsviz"
2. Register statsviz HTTP handlers
2. Start your program
3. Open your browser at http://host:port/debug/statsviz
![](https://github.com/arl/statsviz/raw/readme-docs/heap.png)
![](https://github.com/arl/statsviz/raw/readme-docs/mspan-mcache.png)
## 示例
### hello world
执行 ``` > go run main.go ``` 浏览器访问 `http://127.0.0.1:6060/debug/statsviz/` ### gin
执行 ``` > go run main.go ``` 浏览器访问 `http://127.0.0.1:8080/debug/statsviz/` ### 其他示例 > [github demo](https://github.com/arl/statsviz/tree/master/_example)
';
main.go
``` package main import ( "log" "net/http" "github.com/arl/statsviz" ) func main() { // code mux := http.NewServeMux() statsviz.Register(mux) statsviz.RegisterDefault() go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }() //code select {} } ```执行 ``` > go run main.go ``` 浏览器访问 `http://127.0.0.1:6060/debug/statsviz/` ### gin
main.go
``` package main import ( "github.com/gin-gonic/gin" "github.com/arl/statsviz" example "github.com/arl/statsviz/_example" ) func main() { // Force the GC to work to make the plots "move". go example.Work() router := gin.New() router.GET("/debug/statsviz/*filepath", func(context *gin.Context) { if context.Param("filepath") == "/ws" { statsviz.Ws(context.Writer, context.Request) return } statsviz.IndexAtRoot("/debug/statsviz").ServeHTTP(context.Writer, context.Request) }) router.Run(":8080") } ```执行 ``` > go run main.go ``` 浏览器访问 `http://127.0.0.1:8080/debug/statsviz/` ### 其他示例 > [github demo](https://github.com/arl/statsviz/tree/master/_example)