:rocket: Instant live visualization of your Go application runtime statistics (GC, MemStats, etc.) in the browser

go.dev reference Test Actions Status Go Report Card codecov

Statsviz

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

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

How does it work?

What statsviz does is actually quite simple...

It's composed of 2 HTTP handlers.

When the first one is called(by default /debug/statsviz), it serves an html/js user interface showing some plots, initially empty, in your browser.

The browser then connects to statsviz second HTTP handler. The second one upgrades the connection to the websocket protocol and starts a goroutine that periodically calls runtime.ReadMemStats.

Stats are sent, via websocket, to the user interface, which inturn, updates the plots.

Stats are stored in-browser inside a circular buffer which keep tracks of 60 datapoints, so one minute-worth of data by default. You can change the frequency at which stats are sent by passing SendFrequency to Register.

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

By default 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:

Serve statsviz on /foo/bar instead of default /debug/statsviz:

Serve on https (and wss for websocket):

With gorilla/mux router:

Using labstack/echo router:

With gin-gonic/gin web framework:

With go-chi/chi 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 as png
  • save timeseries to disk
  • load from disk previously saved timeseries

Changelog

See CHANGELOG.md.

License

Owner
Aurélien Rainone
:guitar:
Aurélien Rainone
Comments
  • Support fasthttp

    Support fasthttp

    Fixes #12

    The implementation of websocket module for fastthtp is different. So, changing sendStats to public. And added an example of a web framework fiber that uses fasthttp.

  • [go] add Custom metrics

    [go] add Custom metrics

    Thanks for this tool, it's really useful for debug.

    Could it be possible to add custom metrics and not only those expose by runtime?

    I'm developping an application and it exposes a lot of internal metrics.

    Thank.

  • Usage with fasthttp?

    Usage with fasthttp?

    Is it somehow possible to use this package with fasthttp as HTTP wrapper in combination with fasthttp-routing?

    Because I really like the project and really want to integrate it into one of my projects which bases on these packages.

  • [Bug] /debug/statsviz/tippy-bundle.umd.min.js.map 404

    [Bug] /debug/statsviz/tippy-bundle.umd.min.js.map 404

    /debug/statsviz/libs/js/tippy-bundle.umd.min.js.map 404 Not Found /debug/statsviz/libs/js/bootstrap-toggle.min.js.map 404 Not Found /debug/statsviz/libs/js/popper.min.js.map 404 Not Found /debug/statsviz/libs/js/bootstrap.bundle.min.js.map 404 Not Found

  • On firefox, all graphs are in-line

    On firefox, all graphs are in-line

    Hi,

    I tested with Firefox (103.0.2 Arch Linux (64 bits)) and Chromium (104.0.5112.79 Arch Linux (64 bits)). It works perfectly with Chromium but in Firefox, the graphs are not "responsive" and end up in-line.

    Left - Firefox Right - Chromium

    image

  • Added fixed go-chi example

    Added fixed go-chi example

    This fixes the example removed in #31

    For static files to be accessible, we need to register a catch-all route in go-chi: /debug/statsviz/*

    The statsviz GUI is now accessible via http://localhost:8080/debug/statsviz/

  • moving default basepath to var, convenience functions to change/creat…

    moving default basepath to var, convenience functions to change/creat…

    …e index

    hey - love the project. so, my own server has quite an extensive list of handlers, and I just want to put this under a deeper directory structure. actually, I just needed the NewIndex function, but i added the RootDir stuff in case it was useful.

  • [webpage] auto re-connect after restart server?

    [webpage] auto re-connect after restart server?

    the main process may be killed and then restarted while developing. but therefore the webpage stopped receiving metrics from the process? so can you please make the webpage reconnect the backend automatically after the restart?

  • server.freq not used

    server.freq not used

    func SendFrequency(freq time.Duration) OptionFunc {
    	return func(s *server) error {
    		s.freq = freq
    		return nil
    	}
    }
    
    func sendStats(conn *websocket.Conn) error {
    	tick := time.NewTicker(defaultSendFrequency)
    	defer tick.Stop()
    
    	var stats stats
    	for {
    		select {
    		case <-tick.C:
    			runtime.ReadMemStats(&stats.Mem)
    			stats.NumGoroutine = runtime.NumGoroutine()
    			if err := conn.WriteJSON(stats); err != nil {
    				return err
    			}
    		}
    	}
    }
    

    sendStats always use defaultSendFrequency, instead of server.freq. so that SendFrequency does nothing.

  • Support custom frequency

    Support custom frequency

    I noticed that server.freq is unused despite the fact there's a special option to set custom frequency. So, I added a function NewWsHandler that accepts send frequency and returns http.HandlerFunc. Old behavior of Ws is preserved.

  • Improve tests

    Improve tests

    Improve testing Reorganize example (one example per directory) Improve the ci step which build all examples Various improvements to README.md and CONTRIBUTING.md RegisterDefault now returns an error instead of calling log.Fatal

  • Add Issues and Pull-request templates

    Add Issues and Pull-request templates

    pretty standard stuff, maybe reuse a template or use a template generator?

    Issue template should thank the user and ask them:

    • to run go env
    • to share Go code
    • to explain what they did
    • what they were expecting
    • what happened instead

    PR template should just thank the user and ask them to link the PR to a specific issue (and possibly to have created that issue first)

  • js error

    js error

    plot.js:215 
            
        Uncaught ReferenceError: tippy is not defined
        at Plot._installHeatmapTooltip (plot.js:215:26)
        at Plot.createElement (plot.js:203:18)
        at attachPlots (app.js:100:14)
        at ws.onmessage (app.js:57:13)
    

    image

  • beego run statsviz has a javascript error

    beego run statsviz has a javascript error

    代码如下:

    package handler
    
    import (
    	"net/http/pprof"
    
    	"github.com/arl/statsviz"
    	"github.com/beego/beego/v2/server/web"
    	"github.com/beego/beego/v2/server/web/context"
    )
    
    func init() {
    	// web.Router(defaultPprofPrefix, &PprofController{}, "*:Index")
    	web.AutoPrefix(defaultPprofPrefix, &PprofController{})
    	// web.Router(defaultStatsvizPrefix, &PprofController{}, "*:StatIndex")
    	// web.Router(defaultStatsvizPrefix+":path([\\w]+)", &PprofController{}, "*:StatPath")
    	// web.Router(defaultStatsvizPrefix+"ws", &PprofController{}, "*:StatWs")
    
    	web.Any("/debug/pprof/", func(ctx *context.Context) {
    		pprof.Index(ctx.ResponseWriter, ctx.Request)
    	})
    
    	web.Any(defaultStatsvizPrefix, func(ctx *context.Context) {
    		statsviz.Index.ServeHTTP(ctx.ResponseWriter, ctx.Request)
    	})
    
    	web.Any(defaultStatsvizPrefix+":path([\\w]+)", func(ctx *context.Context) {
    		statsviz.Index.ServeHTTP(ctx.ResponseWriter, ctx.Request)
    	})
    
    	web.Any(defaultStatsvizPrefix+"ws", func(ctx *context.Context) {
    		statsviz.Ws.ServeHTTP(ctx.ResponseWriter, ctx.Request)
    	})
    }
    
    

    错误提示: image

  • [Question] Custom metrics implementation questions

    [Question] Custom metrics implementation questions

    Custom metrics is now easier after new released #75. But it seems that custom metrics like cpu, memory, io and network etc. must be implemented only inside statsviz's plot package which would be too invasive for the lib itself. Maybe we can change statsviz's interface for add-on metrics using http package's middleware pattern?

:chart_with_upwards_trend: Monitors Go MemStats + System stats such as Memory, Swap and CPU and sends via UDP anywhere you want for logging etc...

Package stats Package stats allows for gathering of statistics regarding your Go application and system it is running on and sent them via UDP to a se

Nov 10, 2022
Instant, disposable, single-binary web based live chat server. Go + VueJS.
Instant, disposable, single-binary web based live chat server. Go + VueJS.

Niltalk Niltalk is a web based disposable chat server. It allows users to create password protected disposable, ephemeral chatrooms and invite peers t

Jan 4, 2023
🚀Statsview is a real-time Golang runtime stats visualization profiler
🚀Statsview is a real-time Golang runtime stats visualization profiler

Statsview is a real-time Golang runtime stats visualization profiler. It is built top on another open-source project, go-echarts, which helps statsview to show its graphs on the browser.

Dec 29, 2022
Control your legacy Reciva based internet radios (Crane, Grace Digital, Tangent, etc.) via REST api or web browser.

reciva-web-remote Control your legacy Reciva based internet radios (Crane, Grace Digital, Tangent, etc.) via REST api or web browser. Usage This progr

May 3, 2022
A tiny wrapper around NSQ topic and channel :rocket:

Event Bus NSQ A tiny wrapper around go-nsq topic and channel. Protect nsq calls with gobreaker. Installation go get -u github.com/rafaeljesus/nsq-even

Sep 27, 2022
:rocket: Modern cross-platform HTTP load-testing tool written in Go
:rocket: Modern cross-platform HTTP load-testing tool written in Go

English | 中文 Cassowary is a modern HTTP/S, intuitive & cross-platform load testing tool built in Go for developers, testers and sysadmins. Cassowary d

Dec 29, 2022
A research implementation of team rocket's leaderless consensus protocol

rocket A research implementation of team rocket's leaderless consensus protocol backlog Run consensus tests with agents that have corrupted configurat

Feb 1, 2022
High-performance GitHub webhook events toolset for Go :rocket:
High-performance GitHub webhook events toolset for Go :rocket:

githubevents GitHub webhook events toolset for Go githubevents is a webhook events toolset for the Go programming language inspired by octokit/webhook

Dec 24, 2022
Identify containers at runtime and observe them. No container runtime required. Read only access to the kernel.

Linux Telemetry The Double Slit Experiment Taken from an interesting physics anomaly where the behavior of a physical system mutates simply by being o

Sep 18, 2022
golang-runtime-di is a framework for runtime dependency injection in go

golang-runtime-di description golang-runtime-di is a framework for runtime dependency injection in go. usage quickstart add it to your go.mod: go get

Aug 1, 2022
hack-browser-data is an open-source tool that could help you decrypt data from the browser.
hack-browser-data is an open-source tool that could help you decrypt data  from the browser.

hack-browser-data is an open-source tool that could help you decrypt data ( password|bookmark|cookie|history|credit card|download

Dec 23, 2022
🌭 The hotdog web browser and browser engine 🌭
🌭 The hotdog web browser and browser engine 🌭

This is the hotdog web browser project. It's a web browser with its own layout and rendering engine, parsers, and UI toolkit! It's made from scratch e

Dec 30, 2022
Host yo' self from your browser, your phone, your toaster.
Host yo' self from your browser, your phone, your toaster.

A hosting service from the browser, because why not. Try it at hostyoself.com. See it in action Here's an example where I use hostyoself.com to host i

Jan 1, 2023
pREST (PostgreSQL REST), simplify and accelerate development, ⚡ instant, realtime, high-performance on any Postgres application, existing or new

pREST pREST (PostgreSQL REST), simplify and accelerate development, instant, realtime, high-performance on any Postgres application, existing or new P

Jan 9, 2023
Instant Kubernetes-Native Application Observability
Instant Kubernetes-Native Application Observability

What is Pixie? Pixie gives you instant visibility by giving access to metrics, events, traces and logs without changing code. We're building up Pixie

Jan 4, 2023
Mogo: a lightweight browser-based logs analytics and logs search platform for some datasource(ClickHouse, MySQL, etc.)
Mogo: a lightweight browser-based logs analytics and logs search platform for some datasource(ClickHouse, MySQL, etc.)

mogo Mogo is a lightweight browser-based logs analytics and logs search platform

Dec 30, 2022
A mining pool proxy tool, support BTC, ETH, ETC, XMR mining pool, etc.

Tier2Pool A mining pool proxy tool, support BTC, ETH, ETC, XMR mining pool, etc. Build I use Ubuntu as a demo. sudo update sudo apt install git make s

Jul 29, 2022
gProfiler combines multiple sampling profilers to produce unified visualization of what your CPU
gProfiler combines multiple sampling profilers to produce unified visualization of what your CPU

gProfiler combines multiple sampling profilers to produce unified visualization of what your CPU is spending time on, displaying stack traces of your processes across native programs1 (includes Golang), Java and Python runtimes, and kernel routines.

Dec 27, 2022
GoAdmin is a toolkit to help you build a data visualization admin panel for your golang app.
GoAdmin is a toolkit to help you build a data visualization admin panel for your golang app.

the missing golang data admin panel builder tool. Documentation | 中文文档 | 中文介绍 | DEMO | 中文DEMO | Twitter | Forum Inspired by laravel-admin Preface GoAd

Nov 25, 2021
Op - A small tool that will allow you to open language or framework documentation in your browser from your terminal

op "op" is a small tool that will allow you to open language or framework docume

Aug 25, 2022