MCPcopy Index your code
hub / github.com/arl/statsviz

github.com/arl/statsviz @v0.8.0

repository ↗ · DeepWiki ↗ · release v0.8.0 ↗ · + Follow
216 symbols 617 edges 76 files 56 documented · 26% updated 1d ago★ 3,6406 open issues
README

Go Reference Latest tag Mentioned in Awesome Go

Linux CI Others CI Codecov

Statsviz

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

statsviz ui statsviz ui

Install

Get the latest version:

go get github.com/arl/statsviz@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

Examples

If you check any of the boxes below: - [ ] you use some HTTP framework - [ ] you want Statsviz to be located at /my/path/to/statsviz rather than /debug/statsviz - [ ] you want Statsviz under https:// rather than http:// - [ ] you want Statsviz behind some middleware

Then you should call statsviz.NewServer() (with or without options depending on your use case) in order to access the Index() and Ws() methods.

srv, err := statsviz.NewServer(); // Create server or handle error
if err != nil { /* handle error */ }

// Do something with the handlers.
srv.Index()     // UI (dashboard) handler func
srv.Ws()        // Websocket handler func

Examples for the following cases, and more, are found in the _example directory:

  • 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:
  • echo
  • fasthttp
  • fiber
  • gin
  • and many others thanks to many contributors!

How Does That Work?

Statsviz is made of two parts:

  • The Ws serves a Websocket endpoint. When a client connects, your program's runtime/metrics are sent to the browser, once per second, via the websocket connection.

  • the Index http handler serves Statsviz user interface at /debug/statsviz at the address served by your program. When served, the UI connects to the Websocket endpoint and starts receiving data points.

Documentation

Go API

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

Web User Interface

Top Bar

webui-annotated

Category Selector

menu-categories

Each plot belongs to one or more categories. The category selector allows you to filter the visible plots by categories.

Visible Time Range

menu-timerange

Use the time range selector to define the visualized time span.

Show/Hide GC events

menu-gc-events

Show or hide the vertical lines representing garbage collection events.

Pause updates

menu-play

Pause or resume the plot updates.

Plot Controls

webui-annotated

Plots

Which plots are visible depends on: - your Go version,since some plots are only available in newer versions. - what plot categories are currently selected. By default all plots are shown.

Allocation and Free Rate

alloc-free-rate

CGO Calls

cgo

CPU (GC)

cpu-gc

CPU (Overall)

cpu-overall

CPU (Scavenger)

cpu-scavenger

Garbage Collection

garbage-collection

GC Cycles

gc-cycles

GC Pauses

gc-pauses

GC Scan

gc-scan

GC Stack Size

gc-stack-size

Goroutines

goroutines

Heap (Details)

heap-details

Live Bytes

live-bytes

Live Objects

live-objects

Memory Classes

memory-classes

MSpan/MCache

mspan-mcache

Mutex Wait

mutex-wait

Runnable Time

runnable-time

Scheduling Events

sched-events

Size Classes

size-classes

GC Pauses

gc-pauses

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.

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

Extension points exported contracts — how you extend this code

Option (FuncType)
Option is a configuration option for the Server.
statsviz.go

Core symbols most depended-on inside this repo

mustidx
called by 60
internal/plot/registry.go
register
called by 26
internal/plot/registry.go
Index
called by 13
statsviz.go
downsampleFactor
called by 11
internal/plot/hist.go
Root
called by 10
statsviz.go
Register
called by 9
statsviz.go
NewServer
called by 9
statsviz.go
Register
called by 9
statsviz.go

Shape

Function 89
Method 82
Struct 29
Class 10
TypeAlias 4
FuncType 2

Languages

Go70%
TypeScript30%

Modules by API surface

netconn_test.go35 symbols
internal/static/src/plot.js23 symbols
statsviz.go15 symbols
internal/plot/list.go10 symbols
userplot.go9 symbols
internal/plot/types.go9 symbols
statsviz_test.go8 symbols
internal/static/src/PlotManager.js8 symbols
internal/plot/registry.go8 symbols
internal/static/src/StatsManager.js7 symbols
_example/userplots/main.go7 symbols
internal/static/src/RingBuffer.js6 symbols

Dependencies from manifests, versioned

github.com/CloudyKit/fastprinterv0.0.0-2020010918263 · 1×
github.com/CloudyKit/jet/v6v6.2.0 · 1×
github.com/Joker/jadev1.1.3 · 1×
github.com/Shopify/goreferrerv0.0.0-2022072916590 · 1×
github.com/andybalholm/brotliv1.1.0 · 1×
github.com/aymerick/douceurv0.2.0 · 1×
github.com/cloudwego/base64xv0.1.4 · 1×
github.com/cloudwego/iasmv0.2.0 · 1×

For agents

$ claude mcp add statsviz \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact