: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

Issues
  • 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
  • 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
  • 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
  • sendStats time.NewTicker did not stop the tick

    sendStats time.NewTicker did not stop the tick

    https://github.com/daheige/statsviz/blob/master/statsviz.go#L87

    After this operation, the timer will not leak before the function exits. Especially before the service exits smoothly, it is recommended to clean up the timer here.

    fix it like this: tick := time.NewTicker(defaultSendPeriod) defer tick.Stop()

    opened by daheige 2
  • Examples use go mod

    Examples use go mod

    Remove install.sh script into _examples main packages. Just use go.mod for that. Also, that simplify TestExamples since we can just use go build and go run to start the examples servers.

    opened by arl 1
  • _examples/fiber: fix

    _examples/fiber: fix

    Use app.Use rather than app.Get Also, prints the URL with the trailing slash on stdout, since without it you get a 404 Last but not least, not that it mattered, but the whole file was dos-formatted...

    Fixes #58

    thanks @vcabbage :-)

    opened by arl 1
  • [ui] improve colorscale of the sizeClasses heatmap

    [ui] improve colorscale of the sizeClasses heatmap

    Current one is not so easy to read at first glance, it has too many colors, and is probably not vision-impaired friendly at all.

    image

    We should probably switch to a monochromatic colorscale (if possible one that is accessible to highest number of users). See https://medium.com/envoy-design/how-to-design-an-accessible-color-scheme-4a13ca12c92b

    enhancement ui 
    opened by arl 0
  • [ui] Improve the scale of the Y axis of sizeClasses heatmap

    [ui] Improve the scale of the Y axis of sizeClasses heatmap

    We're currently using a linear Y axis, which makes low size classes difficulty visible, if not hidden.

    linear (default):

    image

    log 10

    Switching to a log 10 axis improves that, but makes the highest size classes barely visible. image

    log 10 axis is obtained by setting the axis type to log in Plotly.

    layout: {
        yaxis: {
            title: 'size classes',
            type: 'log', 
        },
    },
    

    log 2 ?

    Using log 2 could help, but would require manual tick creation (see this plotly issue).

    equal heights?

    Another possibility is to give each bucket the same height, independently of the actual size class it represents. Doc

    enhancement ui 
    opened by arl 0
  • [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 4
  • [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 ui 
    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 161 May 20, 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 852 Jun 16, 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 486 Jun 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 13 Mar 30, 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 1 Feb 15, 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 73 May 24, 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 588 Jun 24, 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 21 Jun 9, 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 99 Jun 17, 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 Jun 20, 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.3k Jun 29, 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 3.5k Jun 28, 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 Jun 28, 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 670 Jun 22, 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 May 19, 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 486 Jun 29, 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
Litestream-read-replica-demo - A demo application for running live read replication on fly.io with Litestream

Litestream Read Replica Demo A demo application for running live read replicatio

Ben Johnson 64 Jun 3, 2022
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 Apr 14, 2022
A Go middleware that stores various information about your web application (response time, status code count, etc.)

Go stats handler stats is a net/http handler in golang reporting various metrics about your web application. This middleware has been developed and re

Florent Messa 585 Jun 22, 2022
GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.

GraphJin - Build APIs in 5 minutes GraphJin gives you a high performance GraphQL API without you having to write any code. GraphQL is automagically co

Vikram Rangnekar 2.2k Jun 30, 2022
Instant loginless chats with people that share an IP with you.

localchat Instant web chat rooms (anything under the /<room> path goes). Defaults to your local public IP, which means in most cases people from the s

fiatjaf 36 Mar 3, 2022
Instant messaging platform. Backend in Go. Clients: Swift iOS, Java Android, JS webapp, scriptable command line; chatbots

Tinode Instant Messaging Server Instant messaging server. Backend in pure Go (license GPL 3.0), client-side binding in Java, Javascript, and Swift, as

Tinode 8.9k Jun 20, 2022
GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.

GraphJin - Build APIs in 5 minutes GraphJin gives you a high performance GraphQL API without you having to write any code. GraphQL is automagically co

Vikram Rangnekar 2.2k Jun 30, 2022
Instant messaging server for the Extensible Messaging and Presence Protocol (XMPP).

Instant messaging server for the Extensible Messaging and Presence Protocol (XMPP).

Miguel Ángel Ortuño 1.3k Jun 23, 2022
Pixie gives you instant visibility by giving access to metrics, events, traces and logs without changing code.

Pixie gives you instant visibility by giving access to metrics, events, traces and logs without changing code.

Pixie Labs 3.5k Jun 29, 2022
null 55 Jun 16, 2022