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.

In addition to adding the HTTP handler, this package registers the following
variables:

The package is sometimes only imported for the side effect of registering its
HTTP handler and the above variables. To use it this way, link this package into
your program:

  1. import _ "expvar"

Index

expvar.go

func

  1. func Do(f func())

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

  1. func Handler() http.

Handler returns the expvar HTTP Handler.

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

func Publish

  1. func Publish(name string, v )

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.

type Float

  1. type Float struct {
  2. // contains filtered or unexported fields
  3. }

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

func NewFloat

  1. func NewFloat(name string) *

func (*Float) Add

  1. func (v *Float) Add(delta )

Add adds delta to v.

func (*Float) Set

  1. func (v *Float) Set(value )

Set sets v to value.

func (*Float) String

  1. func (v *Float) String()

func (*Float) Value

  1. func (v *Float) Value()

type Func

  1. type Func func() interface{}

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

func (Func) String

func (Func) Value

  1. func (f Func) Value() interface{}

  1. type Int struct {
  2. // contains filtered or unexported fields
  3. }

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

  1. func NewInt(name ) *Int

func (*Int)

  1. func (v *) Add(delta int64)

func (*Int)

    func (*Int)

    1. func (v *) String() string

    func (*Int)

    1. func (v *) Value() int64

    type

    1. type KeyValue struct {
    2. Key
    3. Value Var
    4. }

    KeyValue represents a single entry in a Map.

    type

    1. type Map struct {
    2. // contains filtered or unexported fields
    3. }

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

    func

    1. func NewMap(name ) *Map

    func (*Map)

    1. func (v *) Add(key string, delta )

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

    func (*Map) AddFloat

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

    1. func (v *Map) Do(f func())

    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

    1. func (v *Map) Get(key ) Var

    func (*Map)

    1. func (v *) Init() *Map

    Init removes all keys from the map.

    func (*Map)

    1. func (v *) Set(key string, av )

    func (*Map) String

    1. func (v *Map) String()

    type String

    1. type String struct {
    2. // contains filtered or unexported fields
    3. }

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

    func NewString

    1. func NewString(name string) *

    func (*String) Set

    1. func (v *String) Set(value )

    func (*String) String

    1. func (v *String) String()

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

    1. func (v *String) Value()

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

    Var is an abstract type for all exported variables.

    func

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