expvar

package
v1.20240719.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package expvar provides a standardized interface to public variables, such as operation counters in servers. It exposes these variables via HTTP at /debug/vars in JSON format.

Operations to set or modify these public variables are atomic.

Index

Constants

View Source
const (
	DefaultVarsRoute = "/debug/vars"
)

Constants

Variables

This section is empty.

Functions

func Memstats

func Memstats() runtime.MemStats

Memstats returns the runtime memstats.

Types

type Float64

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

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

func (*Float64) Add

func (v *Float64) Add(delta float64)

Add adds delta to v.

func (*Float64) Set

func (v *Float64) Set(value float64)

Set sets v to value.

func (*Float64) String

func (v *Float64) String() string

String satisfies `Var`.

func (*Float64) Value

func (v *Float64) Value() float64

Value returns the underlying float64 value.

type Func

type Func func() interface{}

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

func (Func) String

func (f Func) String() string

String implements `Var`.

func (Func) Value

func (f Func) Value() interface{}

Value yields the result of calling the function.

type Int

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

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

func (*Int) Add

func (v *Int) Add(delta int64) int64

Add adds to the value.

func (*Int) Set

func (v *Int) Set(value int64)

Set sets the value

func (*Int) String

func (v *Int) String() string

String satisfies `Var`.

func (*Int) Value

func (v *Int) Value() int64

Value returns the current value.

type KeyValue

type KeyValue struct {
	Key   string
	Value Var
}

KeyValue represents a single entry in a Map.

type String

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

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

func (*String) Set

func (v *String) Set(value string)

Set sets the value

func (*String) String

func (v *String) String() string

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

func (*String) Value

func (v *String) Value() string

Value returns the underlying value.

type Var

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.

type Vars

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

Vars is a collection of expvars.

func (*Vars) Do

func (v *Vars) Do(f func(KeyValue) error) error

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

func (*Vars) Forward added in v1.20210221.5

func (v *Vars) Forward(dst *Vars, keyPrefix string) error

Forward forwards the vars contained in this set to another set with a given key prefix.

func (*Vars) Get

func (v *Vars) Get(name string) Var

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

func (*Vars) Handler

func (v *Vars) Handler(w http.ResponseWriter, r *http.Request)

Handler returns an http.HandlerFunc that renders the vars as json.

func (*Vars) Publish

func (v *Vars) Publish(name string, val Var) error

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 (*Vars) WriteTo

func (v *Vars) WriteTo(wr io.Writer) (size int64, err error)

WriteTo writes the vars to a given writer as json.

This is called by the Handler function to return the output.

Jump to

Keyboard shortcuts

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