Documentation ¶
Overview ¶
Package statsviz allows to visualise Go program runtime metrics data in real time: heap, objects, goroutines, GC pauses, scheduler, etc. in your browser.
Register statsviz endpoint on your server http.ServeMux (preferred method):
mux := http.NewServeMux() statsviz.Register(mux)
Or register on `http.DefaultServeMux`:
statsviz.RegisterDefault()
By default statsviz is served at `/debug/statsviz/`.
If your application is not already running an HTTP server, you need to start one. Add "net/http" and "log" to your imports and the following code to your main function:
go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }()
Then open your browser at http://localhost:6060/debug/statsviz/.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Index = IndexAtRoot(defaultRoot)
Index responds to a request for /debug/statsviz with the statsviz HTML page which shows a live visualization of the statistics sent by the application over the websocket handler Ws.
var Ws = NewWsHandler(defaultSendFrequency)
Ws is a default Websocket handler, created with NewWsHandler, sending statistics at the default frequency of 1 message per second.
Functions ¶
func IndexAtRoot ¶
func IndexAtRoot(root string) http.HandlerFunc
IndexAtRoot returns an index statsviz handler rooted at root. It's useful if you desire your server to responds with the statsviz HTML page at a path that is different than /debug/statsviz.
func NewWsHandler ¶
func NewWsHandler(frequency time.Duration) http.HandlerFunc
NewWsHandler returns a handler that upgrades the HTTP server connection to the WebSocket protocol and sends application statistics at the given frequency.
If the upgrade fails, an HTTP error response is sent to the client.
func Register ¶
func Register(mux *http.ServeMux, opts ...OptionFunc) error
Register registers statsviz HTTP handlers on the provided mux.
func RegisterDefault ¶
func RegisterDefault(opts ...OptionFunc) error
RegisterDefault registers statsviz HTTP handlers on the default serve mux.
Note this is not advised on a production server, unless it only serves on localhost.
Types ¶
type OptionFunc ¶
type OptionFunc func(s *server) error
An OptionFunc is a server configuration option.
func SendFrequency ¶
func SendFrequency(freq time.Duration) OptionFunc
SendFrequency defines the frequency at which statistics are sent from the application to the HTML page.