metric

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

package metric provides a collection of useful/built-in metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do added in v0.0.8

func Do(f func(KeyValue))

Do calls f for each exported variable. The global variable map is locked during the iteration, but existing entries may be concurrently updated.

func Handler added in v0.0.8

func Handler() http.Handler

Handler returns the metrics HTTP Handler.

This is only needed to install the handler in a non-standard location.

func Publish added in v0.0.8

func Publish(name string, v Var)

Publish declares a named exported variable. This should be called from a package's init function when it creates its Vars. If the name is already registered then this will log.Panic.

func PublishCommandLine added in v0.0.8

func PublishCommandLine()

PublishCommandLine publish command line information.

func PublishMemoryStats added in v0.0.8

func PublishMemoryStats()

PublishMemoryStats publish memory stats.

func RegisterHandler added in v0.0.8

func RegisterHandler()

RegisterHandler registers the standard metrics endpoint: `GET /debug/vars`.

func Start added in v0.0.8

func Start()

Start registers the `GET /debug/vars` endpoint, and publish Golang's built-in metrics: cmdline, and memstats.

Types

type Float added in v0.0.8

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

Float is a 64-bit float variable that satisfies the Var interface.

func NewFloat added in v0.0.8

func NewFloat(name string) *Float

func (*Float) Add added in v0.0.8

func (v *Float) Add(delta float64)

Add adds delta to v.

func (*Float) Set added in v0.0.8

func (v *Float) Set(value float64)

Set sets v to value.

func (*Float) String added in v0.0.8

func (v *Float) String() string

func (*Float) Value added in v0.0.8

func (v *Float) Value() float64

type Func added in v0.0.8

type Func func() interface{}

Func implements Var by calling the function and formatting the returned value using JSON.

func CommandLine

func CommandLine() Func

CommandLine metric.

func MemoryStats

func MemoryStats() Func

MemoryStats metric.

func Server

func Server(address, name string, pid int) Func

Server information.

func (Func) String added in v0.0.8

func (f Func) String() string

func (Func) Value added in v0.0.8

func (f Func) Value() interface{}

type Int added in v0.0.8

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

Int is a 64-bit integer variable that satisfies the Var interface.

func NewInt added in v0.0.8

func NewInt(name string) *Int

func (*Int) Add added in v0.0.8

func (v *Int) Add(delta int64)

func (*Int) Set added in v0.0.8

func (v *Int) Set(value int64)

func (*Int) String added in v0.0.8

func (v *Int) String() string

func (*Int) Value added in v0.0.8

func (v *Int) Value() int64

type KeyValue added in v0.0.8

type KeyValue struct {
	Key   string
	Value Var
}

KeyValue represents a single entry in a Map.

type Map added in v0.0.8

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

Map is a string-to-Var map variable that satisfies the Var interface.

func NewMap added in v0.0.8

func NewMap(name string) *Map

func (*Map) Add added in v0.0.8

func (v *Map) Add(key string, delta int64)

Add adds delta to the *Int value stored under the given map key.

func (*Map) AddFloat added in v0.0.8

func (v *Map) AddFloat(key string, delta float64)

AddFloat adds delta to the *Float value stored under the given map key.

func (*Map) Delete added in v0.0.8

func (v *Map) Delete(key string)

Delete deletes the given key from the map.

func (*Map) Do added in v0.0.8

func (v *Map) Do(f func(KeyValue))

Do calls f for each entry in the map. The map is locked during the iteration, but existing entries may be concurrently updated.

func (*Map) Get added in v0.0.8

func (v *Map) Get(key string) Var

func (*Map) Init added in v0.0.8

func (v *Map) Init() *Map

Init removes all keys from the map.

func (*Map) Set added in v0.0.8

func (v *Map) Set(key string, av Var)

func (*Map) String added in v0.0.8

func (v *Map) String() string

type Metric

type Metric struct {
	// Name of the metric.
	Name string `json:"name" validate:"required"`

	// Var is a valid ExpVar.
	Value Var `json:"value" validate:"required"`
}

Metric definition.

func New

func New(name string, value Var) (*Metric, error)

New is the Metric factory.

type String added in v0.0.8

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

String is a string variable, and satisfies the Var interface.

func NewString added in v0.0.8

func NewString(name string) *String

func (*String) Set added in v0.0.8

func (v *String) Set(value string)

func (*String) String added in v0.0.8

func (v *String) String() string

String implements the Var interface. To get the unquoted string use Value.

func (*String) Value added in v0.0.8

func (v *String) Value() string

type Var added in v0.0.8

type Var interface {
	// String returns a valid JSON value for the variable.
	// Types with String methods that do not return valid JSON
	// (such as time.Time) must not be used as a Var.
	String() string
}

Var is an abstract type for all exported variables.

func Get added in v0.0.8

func Get(name string) Var

Get retrieves a named exported variable. It returns nil if the name has not been registered.

Jump to

Keyboard shortcuts

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