statsview

package module
v0.0.0-...-9dc0c21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 11 Imported by: 0

README

🚀 Statsview

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.

Fork of project statsview

Go Reference Go Report Card

🔰 Installation

$ go get -u github.com/mortum5/statsview/...

📝 Usage

Statsview is quite simple to use and all static assets have been packaged into the project which makes it possible to run offline. It's worth pointing out that statsview has integrated the standard net/http/pprof hence statsview will be the only profiler you need.

package main

import (
    "time"

    "github.com/mortum5/statsview"
	"github.com/mortum5/statsview/viewer"
)

func main() {
    // NewEmptyViewers() create empty viewers collection
	viewers := statsview.NewEmptyViewers()
    
    // NewDefaultViewers() create viewers collection with default viewers
	// viewers := statsview.NewDefaultViewers()

	viewers.Register(
		viewer.NewGoroutinesViewer(),
		viewer.NewHeapViewer(),
		viewer.NewStackViewer(),
	)

	mgr := statsview.New(viewers)

    // Start() runs a HTTP server at `localhost:18066` by default.
	go mgr.Start()

	// Stop() will shutdown the http server gracefully
	// mgr.Stop()

	// busy working....
	time.Sleep(time.Minute)
}

    // Visit your browser at http://localhost:18066/debug/statsview
    // Or debug as always via http://localhost:18066/debug/pprof, http://localhost:18066/debug/pprof/heap, ...

⚙️ Configuration

Statsview gets a variety of configurations for the users. Everyone could customize their favorite charts style.

// WithInterval sets the interval(in Millisecond) of collecting and pulling metrics
// default -> 2000
WithInterval(interval int)

// WithMaxPoints sets the maximum points of each chart series
// default -> 30
WithMaxPoints(n int)

// WithTemplate sets the rendered template which fetching stats from the server and
// handling the metrics data
WithTemplate(t string)

// WithAddr sets the listening address and link address
// default -> "localhost:18066"
WithAddr(addr string)

// WithLinkAddr sets the html link address
// default -> "localhost:18066"
WithLinkAddr(addr string)

// WithTimeFormat sets the time format for the line-chart Y-axis label
// default -> "15:04:05"
WithTimeFormat(s string)

// WithBrowserOpen start browser session and open url automatically
// default -> disabled
WithBrowserOpen()

// WithTheme sets the theme of the charts
// default -> Macarons
//
// Optional:
// * ThemeWesteros
// * ThemeMacarons
WithTheme(theme Theme)
Set the options
import (
    "github.com/mortum5/statsview"
    "github.com/mortum5/statsview/viewer"
)

viewers := statsview.NewDefaultViewers()

// set configurations before calling `statsview.New()` method
viewer.SetConfiguration(
    viewer.WithTheme(viewer.ThemeWesteros), 
    viewer.WithAddr("localhost:8087")
)

mgr := statsview.New(viewers)
go mgr.Start()

🗂 Viewers

Viewer is the abstraction of a Graph which in charge of collecting metrics from Runtime. Statsview provides some default viewers as below.

  • GCCPUFractionViewer
  • GCNumViewer
  • GCSizeViewer
  • GoroutinesViewer
  • HeapViewer
  • StackViewer

Viewer wraps a go-echarts *charts.Line instance that means all options/features on it could be used. To be honest, I think that is the most charming thing about this project.

🔖 Snapshot

ThemeMacarons(default)

Macarons

ThemeWesteros

Westeros

📄 License

MIT ©chenjiandongx MIT ©mortum5

Documentation

Overview

Package statsview provide a real-time Golang runtime stats visualization profiler. It is built top on another open-source project, [go-echarts](https://github.com/go-echarts/go-echarts), which helps statsview to show its graphs on the browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ViewManager

type ViewManager struct {
	Smgr   *viewer.StatsMgr
	Views  []viewer.Viewer
	Ctx    context.Context
	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

ViewManager

func New

func New(viewers Viewers) *ViewManager

New creates a new ViewManager instance

func (*ViewManager) Start

func (vm *ViewManager) Start() error

Start runs a http server and begin to collect metrics

func (*ViewManager) Stop

func (vm *ViewManager) Stop()

Stop shutdown the http server gracefully

type Viewers

type Viewers []viewer.Viewer

Viewers represent collection of Viewer

func NewDefaultViewers

func NewDefaultViewers() Viewers

NewDefaultViewers generate default collection that includes - GoroutinesViewer - HeapViewer - StackViewer - GCNumViewer - GCSizeViewer - GCCPUFractionViewer

func NewEmptyViewers

func NewEmptyViewers() Viewers

NewEmptyViewers returns empty collection without any Viewer

func (*Viewers) Register

func (v *Viewers) Register(views ...viewer.Viewer)

Register adds Viewer to collection

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL