statsviz

package module
v0.1.2-0...-1a063cf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2020 License: MIT Imports: 11 Imported by: 0

README

go.dev reference Go Report Card

Statsviz

Instant live visualization of your Go application runtime statistics (GC, MemStats, etc.).

  • Import import "github.com/arl/statsviz"
  • Register statsviz HTTP handlers
  • Start your program
  • Open your browser at http://host:port/debug/statsviz
  • Enjoy...

Usage

go get -u github.com/arl/statsviz

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

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

Or register them with the http.DefaultServeMux:

statsviz.RegisterDefault()

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

The handled path is /debug/statsviz/.

Then open your browser at http://localhost:6060/debug/statsviz/

Examples

Using http.DefaultServeMux:

Using your own http.ServeMux:

Using gorilla/mux Router:

Plots

On the plots where it matters, garbage collections are shown as vertical lines.

Heap
Heap plot image
MSpans / MCaches
MSpan/MCache plot image
Size classes heatmap
Size classes heatmap image
Objects
Objects plot image
Goroutines
Goroutines plot image
GC/CPU fraction
GC/CPU fraction plot image

Contributing

Pull-requests are welcome! More details in CONTRIBUTING.md

Roadmap

  • add stop-the-world duration heatmap
  • increase data retention
  • light/dark mode selector
  • plot image export

Changelog

  • v0.1.1 / 2020-10-12

    • Bugfix: do not leak timer in sendStats
  • v0.1.0 / 2020-10-10

    • First released version

License

Documentation

Overview

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

The package is typically only imported for the side effect of registering its HTTP handler. The handled path is /debug/statsviz/.

To use statsviz, link this package into your program:

import _ "github.com/arl/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))
}()

If you are not using DefaultServeMux, you will have to register handlers with the mux you are using.

Then open your browser at http://localhost:6060/debug/statsviz/

Index

Constants

This section is empty.

Variables

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.

The package initialization registers it as /debug/statsviz/.

View Source
var (
	RootDir = "/debug/statsviz/"
)

Functions

func NewIndex

func NewIndex(prefix string) http.Handler

func Register

func Register(mux *http.ServeMux)

Register registers statsviz HTTP handlers on the provided mux.

func RegisterDefault

func RegisterDefault()

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.

func SetRootDir

func SetRootDir(prefix string)

func Ws

func Ws(w http.ResponseWriter, r *http.Request)

Ws upgrades the HTTP server connection to the WebSocket protocol and sends application statistics every second.

If the upgrade fails, an HTTP error response is sent to the client. The package initialization registers it as /debug/statsviz/ws.

Types

This section is empty.

Directories

Path Synopsis
Package websocket implements the WebSocket protocol defined in RFC 6455.
Package websocket implements the WebSocket protocol defined in RFC 6455.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL