Coder Social home page Coder Social logo

rizalgowandy / statsviz Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arl/statsviz

0.0 1.0 0.0 4.95 MB

Instant live visualization of your Go application runtime statistics (GC, MemStats, etc.) with a single import, à la `net/http/pprof` :rocket:

License: MIT License

Shell 6.71% Go 93.29%

statsviz's Introduction

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 that work?

Statsviz serves 2 HTTP handlers.

The first one (by default /debug/statsviz) serves an html/js user interface showing some initially empty plots.

When you points your browser to statsviz user interface page, it connects to statsviz second HTTP handler. This second handler then upgrades the connection to the websocket protocol and starts a goroutine that periodically calls runtime.ReadMemStats, sending the result to the user interface, which inturn, updates the plots.

Stats are stored in-browser inside a circular buffer which keep tracks of a predefined number of datapoints, 60, 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 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/

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

Examples

Have a look at the _example directory to see some different ways to use Statsviz, such as:

  • using http.DefaultServeMux
  • using your own http.ServeMux
  • wrap HTTP handler behind a middleware
  • register at /foo/bar instead of /debug/statviz
  • use https:// rather than http://
  • using with various Go HTTP libraries/frameworks:
    • fasthttp
    • gin
    • and many others thanks to wonderful contributors!

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

statsviz's People

Contributors

arl avatar shoshinnikita avatar diendv96 avatar tobias-kuendig avatar dnnnvx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.