Documentation
¶
Overview ¶
Package stats is a helper lib for collecting statistics.
Example:
package main
import (
"os"
"time"
"path"
stats "github.com/Brickchain/go-stats.v1"
)
func main() {
// start an inmem metrics sink that will print metrics once per minute.
// set the instance name to the name of our binary.
stats.Setup("inmem", path.Base(os.Args[0]))
someFunc()
// Wait a bit more than a minute in order to see the metrics being printed
time.Sleep(time.Second * 62)
}
func someFunc() {
t := stats.StartTimer("someFunc.total")
defer t.Stop()
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Gauge ¶
Gauge sends a value for a metric.
Example ¶
package main
import (
stats "github.com/Brickchain/go-stats.v1"
)
func main() {
response := []byte("Hello, World")
stats.Gauge("api.get.bytes", float32(len(response)))
}
func Increment ¶
Increment a metric value.
Example ¶
package main
import (
stats "github.com/Brickchain/go-stats.v1"
)
func main() {
stats.Increment("api.get.calls", 1)
}
func Setup ¶
Setup the metrics sink. Takes sink type (datadog, prometheus or inmem) and a name to prepend the metrics keys with.
Example (Datadog) ¶
package main
import (
stats "github.com/Brickchain/go-stats.v1"
)
func main() {
// Requires that the DOGSTATSD environment variable is set and pointing to the statsd port of your dd-agent.
// export DOGSTATSD="localhost:8125"
stats.Setup("datadog", "example")
}
Example (Inmem) ¶
package main
import (
stats "github.com/Brickchain/go-stats.v1"
)
func main() {
// The inmem sink prints the collected metrics to stdout once per minute.
stats.Setup("inmem", "example")
}
Example (Prometheus) ¶
package main
import (
stats "github.com/Brickchain/go-stats.v1"
)
func main() {
// The prometheus sink adds the /metrics handler to your HTTP stack.
// You need to setup a HTTP listener on some port that you point Prometheus to.
stats.Setup("prometheus", "example")
}
Types ¶
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer is the struct that holds the information about an ongoing timer.
func StartTimer ¶
StartTimer starts a new timer and returns a Timer object instance.
Example ¶
package main
import (
stats "github.com/Brickchain/go-stats.v1"
)
func main() {
t := stats.StartTimer("api.get.total")
defer t.Stop()
}
Click to show internal directories.
Click to hide internal directories.