Statsviz

在浏览器中实时可视化 Go 程序运行指标。「🚀 Visualise your Go program runtime metrics in real time in the browser」

Github星跟蹤圖

go.dev reference
Latest tag
Mentioned in Awesome Go

Test Actions Status
Test Actions Status
codecov

Statsviz

Visualize real time plots of your Go program runtime metrics, including heap, objects, goroutines, GC pauses, scheduler and more, in your browser.

Install

Download the latest version:

go get github.com/arl/statsviz@latest

Please note that, as new metrics are added to the /runtime/metrics package, new plots are added to Statsviz.
This also means that the presence of some plots on the dashboard depends on the Go version you're using.

When in doubt, use the latest ;-)

Usage

Register Statsviz HTTP handlers with your application http.ServeMux.

mux := http.NewServeMux()
statsviz.Register(mux)

go func() {
    log.Println(http.ListenAndServe("localhost:8080", mux))
}()

Open your browser at http://localhost:8080/debug/statsviz

Advanced Usage

If you want more control over Statsviz HTTP handlers, examples are:

  • you're using some HTTP framework
  • you want to place Statsviz handler behind some middleware

then use statsviz.NewServer to obtain a Server instance. Both the Index() and Ws() methods return http.HandlerFunc.

srv, err := statsviz.NewServer(); // Create server or handle error
srv.Index()                       // UI (dashboard) http.HandlerFunc
srv.Ws()                          // Websocket http.HandlerFunc

Please look at examples of usage in the Examples directory.

How Does That Work?

statsviz.Register registers 2 HTTP handlers within the given http.ServeMux:

  • the Index handler serves Statsviz user interface at /debug/statsviz at the address served by your program.

  • The Ws serves a Websocket endpoint. When the browser connects to that endpoint, runtime/metrics are sent to the browser, once per second.

Data points are in a browser-side circular-buffer.

Documentation

Go API

Check out the API reference on pkg.go.dev.

User interface

Controls at the top of the page act on all plots:

  • the groom shows/hides the vertical lines representing garbage collections.
  • the time range selector defines the visualized time span.
  • the play/pause icons stops and resume the refresh of the plots.
  • the light/dark selector switches between light and dark modes.

On top of each plot there are 2 icons:

  • the camera downloads a PNG image of the plot.
  • the info icon shows details about the metrics displayed.

Plots

Depending on your go version, some plots may not be available.

Heap (global)

Heap (details)

Live Objects in Heap

Live Bytes in Heap

MSpan/MCache

Memory classes

Goroutines

Size Classes

GC Scan

GC Cycles

Stop-the-world Pause Latencies

CPU Classes (GC)

Time Goroutines Spend in 'Runnable' state

Time Goroutines Spend Blocked on Mutexes

Starting Size of Goroutines Stacks

Goroutine Scheduling Events

CGO Calls

User Plots

Since v0.6 you can add your own plots to Statsviz dashboard, in order to easily
visualize your application metrics next to runtime metrics.

Please see the userplots example.

Examples

Check out the _example directory to see various ways to use Statsviz, such as:

  • use of http.DefaultServeMux or your own http.ServeMux
  • wrap HTTP handler behind a middleware
  • register the web page at /foo/bar instead of /debug/statsviz
  • use https:// rather than http://
  • register Statsviz handlers with various Go HTTP libraries/frameworks:

Questions / Troubleshooting

Either use GitHub's discussions or come to say hi and ask a live question on #statsviz channel on Gopher's slack.

Contributing

Please use issues for bugs and feature requests.
Pull-requests are always welcome!
More details in CONTRIBUTING.md.

Changelog

See CHANGELOG.md.

License: MIT

See LICENSE

主要指標

概覽
名稱與所有者arl/statsviz
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2020-08-14 00:00:41
推送於2025-05-09 06:34:13
最后一次提交
發布數12
最新版本名稱v0.6.0 (發布於 )
第一版名稱v0.1.0 (發布於 )
用户参与
星數3.3k
關注者數33
派生數124
提交數182
已啟用問題?
問題數39
打開的問題數9
拉請求數69
打開的拉請求數2
關閉的拉請求數11
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?