statsviz

package module
v0.0.0-...-d190a7b Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

statsviz

使用

下载最新版本:

go get github.com/hellobchain/statsviz@latest

样例如下:

mux := http.NewServeMux()
statsviz.Register(mux)

或者 这样方式注册 http.DefaultServeMux:

statsviz.RegisterDefault()

默认URL: /debug/statsviz/.

go func() {
    log.Println(http.ListenAndServe("localhost:6060", nil))
}()

然后浏览器打开:http://localhost:6060/debug/statsviz/.

Documentation

Overview

Package statsviz allows to visualise Go program runtime metrics data in real time: heap, objects, goroutines, GC pauses, scheduler, etc. in your browser.

Register statsviz endpoint on your server http.ServeMux (preferred method):

mux := http.NewServeMux()
statsviz.Register(mux)

Or register on `http.DefaultServeMux`:

statsviz.RegisterDefault()

By default statsviz is served at `/debug/statsviz/`.

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))
}()

Then open your browser at http://localhost:6060/debug/statsviz/.

Index

Constants

This section is empty.

Variables

View Source
var Index = IndexAtRoot(defaultRoot)

Index responds to a request for /debug/statsviz with the statsviz HTML page which shows a live visualization of the statistics sent by the application over the websocket handler Ws.

View Source
var Ws = NewWsHandler(defaultSendFrequency)

Ws is a default Websocket handler, created with NewWsHandler, sending statistics at the default frequency of 1 message per second.

Functions

func IndexAtRoot

func IndexAtRoot(root string) http.HandlerFunc

IndexAtRoot returns an index statsviz handler rooted at root. It's useful if you desire your server to responds with the statsviz HTML page at a path that is different than /debug/statsviz.

func NewWsHandler

func NewWsHandler(frequency time.Duration) http.HandlerFunc

NewWsHandler returns a handler that upgrades the HTTP server connection to the WebSocket protocol and sends application statistics at the given frequency.

If the upgrade fails, an HTTP error response is sent to the client.

func Register

func Register(mux *http.ServeMux, opts ...OptionFunc) error

Register registers statsviz HTTP handlers on the provided mux.

func RegisterDefault

func RegisterDefault(opts ...OptionFunc) error

RegisterDefault registers statsviz HTTP handlers on the default serve mux.

Note this is not advised on a production server, unless it only serves on localhost.

Types

type OptionFunc

type OptionFunc func(s *server) error

An OptionFunc is a server configuration option.

func Root

func Root(root string) OptionFunc

Root sets the root path of statsviz handlers.

func SendFrequency

func SendFrequency(freq time.Duration) OptionFunc

SendFrequency defines the frequency at which statistics are sent from the application to the HTML page.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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