Documentation ¶
Overview ¶
Package export provides an interface to instrument Go code.
Instrumenting Go code with this package is very similar to the "expvar" package in the vanilla Go distribution. In fact, the variables exported with this package are also registered with the "expvar" package, so that you can also use other existing metric collection frameworks with it. This package differs in that it has an explicitly cumulative type, Derive.
The intended usage pattern of this package is as follows: First, global variables are initialized with NewDerive(), NewGauge(), NewDeriveString() or NewGaugeString(). The Run() function is called as a separate goroutine as part of your program's initialization and, last but not least, the variables are updated with their respective update functions, Add() for Derive and Set() for Gauge.
// Initialize global variable. var requestCounter = export.NewDeriveString("example.com/golang/total_requests") // Call Run() in its own goroutine. func main() { client, err := network.Dial( net.JoinHostPort(network.DefaultIPv6Address, network.DefaultService), network.ClientOptions{}) if err != nil { log.Fatal(err) } go export.Run(client, export.Options{ Interval: 10 * time.Second, }) // … } // Update variable. func requestHandler(w http.ResponseWriter, req *http.Request) { defer requestCounter.Add(1) // … }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Derive ¶
type Derive struct {
// contains filtered or unexported fields
}
Derive represents a cumulative integer data type, for example "requests served since server start". It implements the Var and expvar.Var interfaces.
func NewDerive ¶
func NewDerive(id api.Identifier) *Derive
NewDerive initializes a new Derive, registers it with the "expvar" package and returns it. The initial value is zero.
func NewDeriveString ¶
NewDeriveString parses s as an Identifier and returns a new Derive. If parsing s fails, it will panic. This simplifies initializing global variables.
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge represents an absolute floating point data type, for example "heap memory used". It implements the Var and expvar.Var interfaces.
func NewGauge ¶
func NewGauge(id api.Identifier) *Gauge
NewGauge initializes a new Gauge, registers it with the "expvar" package and returns it. The initial value is NaN.
func NewGaugeString ¶
NewGaugeString parses s as an Identifier and returns a new Gauge. If parsing s fails, it will panic. This simplifies initializing global variables.