Help us shape the future of Go! Take the 2026 Go Developer Survey

webview

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTemplate = `` /* 926-byte string literal not displayed */

	DefaultMaxPoints  = 30
	DefaultTimeFormat = "15:04:05"
	DefaultInterval   = 2000
	DefaultAddr       = "localhost:18066"
	DefaultTheme      = ThemeMacarons
)
View Source
const (
	//
	VCPU = "CPU"
)
View Source
const (
	//
	VNetInterfaces = "Network Interfaces"
)

Variables

View Source
var ChartNames = map[string]string{
	"rx": "download",
	"tx": "upload",
}
View Source
var ErrNotImplemented = errors.New("not implemented yet")
View Source
var ErrNotSupported = errors.New("not supported")
View Source
var GoStatsFrequency = 250 * time.Millisecond

the defaut frequency for Go stats.

View Source
var GoStatsRoute = "/rt/gostats"

the path for Go stats

View Source
var StaticFiles fs.FS
View Source
var ViewerTmplHTML string // the template has only one unnamed action ({{.}}) which will be replaced with json data

Functions

func Addr

func Addr() string

Addr returns the default server listening address

func GenerateHTMLReport

func GenerateHTMLReport(ctx context.Context, htmlFilename string, jsData string)

GenerateHTMLReport produces HTML file from jsData if filename is ":" opens result from a temporary local web browser

func GetNetStats

func GetNetStats(interfaces []net.Interface, dir string) []float64

return rx/tx counters for interfaces - Linux version

func GetSockOpt

func GetSockOpt(fd uintptr, value int) (int, error)

func HasNetStats

func HasNetStats() error

func Interval

func Interval() int

Interval returns the default collecting interval of ViewManager

func LinkAddr

func LinkAddr() string

LinkAddr returns the default html link address

func OpenViewer

func OpenViewer(ctx context.Context, openBrowser bool)

func SetConfiguration

func SetConfiguration(opts ...Option)

Types

type CPUViewer

type CPUViewer struct {
	// contains filtered or unexported fields
}

CPUViewer collects the cpu number metrics via `gopsutil/cpu`

func (*CPUViewer) Name

func (vr *CPUViewer) Name() string

func (*CPUViewer) Serve

func (vr *CPUViewer) Serve(w http.ResponseWriter, _ *http.Request)

func (*CPUViewer) SetStatsMgr

func (vr *CPUViewer) SetStatsMgr(smgr *StatsMgr)

func (*CPUViewer) View

func (vr *CPUViewer) View() *charts.Line

type Metrics

type Metrics struct {
	Values []float64 `json:"values"`
	Time   string    `json:"time"`
}

Metrics

type NetInterfacesViewer

type NetInterfacesViewer struct {
	// contains filtered or unexported fields
}

NetInterfacesViewer collects network interfaces counters

func (*NetInterfacesViewer) Name

func (vr *NetInterfacesViewer) Name() string

func (*NetInterfacesViewer) Serve

func (*NetInterfacesViewer) SetStatsMgr

func (vr *NetInterfacesViewer) SetStatsMgr(smgr *StatsMgr)

func (*NetInterfacesViewer) View

func (vr *NetInterfacesViewer) View() *charts.Line

type Option

type Option func(c *config)

func WithAddr

func WithAddr(addr string) Option

WithAddr sets the listening address and link address

func WithInterval

func WithInterval(interval int) Option

WithInterval sets the interval of collecting and pulling metrics

func WithLinkAddr

func WithLinkAddr(addr string) Option

WithLinkAddr sets the html link address

func WithMaxPoints

func WithMaxPoints(n int) Option

WithMaxPoints sets the maximum points of each chart series

func WithTemplate

func WithTemplate(t string) Option

WithTemplate sets the rendered template which fetching stats from the server and handling the metrics data

func WithTheme

func WithTheme(theme Theme) Option

WithTheme sets the theme of the charts

func WithTimeFormat

func WithTimeFormat(s string) Option

WithTimeFormat sets the time format for the line-chart Y-axis label

type StatsMgr

type StatsMgr struct {
	Ctx    context.Context
	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

func NewStatsMgr

func NewStatsMgr(ctx context.Context, tick time.Duration) *StatsMgr

func (*StatsMgr) Tick

func (s *StatsMgr) Tick()

type Theme

type Theme string
const (
	ThemeWesteros Theme = types.ThemeWesteros
	ThemeMacarons Theme = types.ThemeMacarons
)

type ViewManager

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

ViewManager

func NewViewManager

func NewViewManager(tick time.Duration, path string, interfaceNames []string, debug bool) (*ViewManager, error)

New creates a new ViewManager instance

func (*ViewManager) PerfRegister

func (vm *ViewManager) PerfRegister(views ...viewer.Viewer)

PerfRegister registers perf views to the external ViewManager

func (*ViewManager) Register

func (vm *ViewManager) Register(views ...Viewer)

Register registers views to the ViewManager

func (*ViewManager) RegisterRoutes

func (vm *ViewManager) RegisterRoutes(mux *http.ServeMux)

type Viewer

type Viewer interface {
	Name() string
	View() *charts.Line
	Serve(w http.ResponseWriter, _ *http.Request)
	SetStatsMgr(smgr *StatsMgr)
}

Viewer is the abstraction of a Graph which in charge of collecting metrics from somewhere

func NewCPUViewer

func NewCPUViewer(tick time.Duration, path string) Viewer

NewCPUViewer returns the CPUViewer instance Series: CPUCores

func NewNetInterfacesViewer

func NewNetInterfacesViewer(tick time.Duration, ifaces []net.Interface, dir string, path string) Viewer

NewNetInterfacesViewer returns the NetInterfacesViewer instance Series: net interfaces

Jump to

Keyboard shortcuts

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