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

Overview

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

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.

    opened by nupamore 7
  • [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.

    enhancement 
    opened by Issif 5
  • 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.

    documentation good first issue question 
    opened by zekroTJA 4
  • [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

    enhancement good first issue frontend 
    opened by jageros 3
  • 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

    bug help wanted good first issue frontend 
    opened by Issif 3
  • 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/

    opened by tobias-kuendig 3
  • 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.

    opened by fredim 3
  • [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?

    enhancement 
    opened by bigchai666 2
  • 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.

    opened by Neightly 2
  • 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.

    opened by ShoshinNikita 2
  • 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

    opened by arl 2
  • 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)

    opened by arl 0
  • 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

    frontend waiting-for-info 
    opened by gatspy 2
  • 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

    bug backend 
    opened by zsy619 0
  • [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?

    opened by kcyx 5
  • [ui] add light/dark mode selector

    [ui] add light/dark mode selector

    Add a dark/light mode switch in the menu. The semantic-ui framework already handles that. The thing is to also change the plot background color when in dark mode.

    enhancement good first issue frontend 
    opened by arl 0
Owner
Aurélien Rainone
:guitar:
Aurélien Rainone
: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

Go Playgound 163 Nov 10, 2022
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

Kailash Nadh 855 Nov 17, 2022
🚀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.

go-echarts 502 Nov 26, 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

null 6 May 3, 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

Kris Nóva 14 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

DB Systel GmbH 2 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 ( password|bookmark|cookie|history|credit card|download

idiotc4t 113 Nov 30, 2022
🌭 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

Danilo Fragoso 1k Dec 1, 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

Rafael Jesus 75 Sep 27, 2022
: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

Roger Welin 635 Nov 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

Ad van der Veer 0 Feb 1, 2022
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

Christian Bargmann 35 Nov 7, 2022
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

Zack 1.7k Nov 29, 2022
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

pREST 3.4k Nov 23, 2022
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

Pixie Labs 4k Nov 23, 2022
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

Shimo HQ 939 Nov 21, 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

Tier2Pool 6 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 is spending time on, displaying stack traces of your processes across native programs1 (includes Golang), Java and Python runtimes, and kernel routines.

Granulate 584 Nov 27, 2022
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

null 1 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

Damien Sedgwick 3 Aug 25, 2022