statsviz: Index | Files | Directories

package statsviz

import ""

Package statsviz serves via its HTTP server an HTML page displaying live visualization of the application runtime statistics.

Either Register statsviz HTTP handlers with the http.ServeMux you're using (preferred method):

mux := http.NewServeMux()

Or register them with the http.DefaultServeMux:


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))


Package Files

assets_gen.go assets_vfsdata.go doc.go handlers.go register.go statsviz.go


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.

func IndexAtRoot Uses

func IndexAtRoot(root string) http.Handler

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 Uses

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 Uses

func Register(mux *http.ServeMux, opts ...OptionFunc) error

Register registers statsviz HTTP handlers on the provided mux.

func RegisterDefault Uses

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.

type OptionFunc Uses

type OptionFunc func(s *server) error

An OptionFunc is a server configuration option.

func Root Uses

func Root(root string) OptionFunc

Root sets the root of statsviz handlers.

func SendFrequency Uses

func SendFrequency(freq time.Duration) OptionFunc

SendFrequency defines the frequency at which statistics are sent from the application to the HTML page.


websocketPackage websocket implements the WebSocket protocol defined in RFC 6455.

Package statsviz imports 12 packages (graph) and is imported by 3 packages. Updated 2020-12-02. Refresh now. Tools for package owners.