Documentation ¶
Index ¶
- Constants
- func Close() error
- func Configure(logf LoggerFunc, statsHouseAddr string, defaultEnv string)
- func ConfigureNetwork(logf LoggerFunc, network string, statsHouseAddr string, defaultEnv string)
- func LexDecode(x int32) float32
- func LexEncode(x float32) int32
- func LexEncodeStr(x float32) string
- func StartRegularMeasurement(f func(*Client)) (id int)
- func StopRegularMeasurement(id int)
- type Client
- func (c *Client) Close() error
- func (c *Client) Metric(metric string, tags Tags) *MetricRef
- func (c *Client) MetricNamed(metric string, tags NamedTags) *MetricRef
- func (c *Client) SetEnv(env string)
- func (c *Client) StartRegularMeasurement(f func(*Client)) (id int)
- func (c *Client) StopRegularMeasurement(id int)
- type LoggerFunc
- type MetricRef
- type NamedTags
- type Tags
Constants ¶
const ( DefaultAddr = "127.0.0.1:13337" DefaultNetwork = "udp" )
Variables ¶
This section is empty.
Functions ¶
func Close ¶
func Close() error
Close calls *Client.Close on the global Client. Make sure to call Close during app exit to avoid losing the last batch of metrics.
func Configure ¶
func Configure(logf LoggerFunc, statsHouseAddr string, defaultEnv string)
Configure is expected to be called once during app startup to configure the global Client. Specifying empty StatsHouse address will make the client silently discard all metrics.
func ConfigureNetwork ¶ added in v0.3.0
func ConfigureNetwork(logf LoggerFunc, network string, statsHouseAddr string, defaultEnv string)
network must be either "udp" or "unixgram"
func LexEncode ¶ added in v0.2.2
Advanced feature. Encodes float as a raw tag in a special format, used by Statshouse. Ordering of all float values is preserved after encoding. Except all NaNs map to single value which is > +inf, and both zeroes map to 0.
func LexEncodeStr ¶ added in v0.2.2
func StartRegularMeasurement ¶
StartRegularMeasurement calls *Client.StartRegularMeasurement on the global Client. It is valid to call StartRegularMeasurement before Configure.
func StopRegularMeasurement ¶
func StopRegularMeasurement(id int)
StopRegularMeasurement calls *Client.StopRegularMeasurement on the global Client. It is valid to call StopRegularMeasurement before Configure.
Types ¶
type Client ¶ added in v0.2.0
type Client struct {
// contains filtered or unexported fields
}
Client manages metric aggregation and transport to a StatsHouse agent.
func NewClient ¶ added in v0.2.0
func NewClient(logf LoggerFunc, network string, statsHouseAddr string, defaultEnv string) *Client
NewClient creates a new Client to send metrics. Use NewClient only if you are sending metrics to two or more StatsHouse clusters. Otherwise, simply Configure the default global Client.
Specifying empty StatsHouse address will make the client silently discard all metrics. if you get compiler error after updating to recent version of library, pass statshouse.DefaultNetwork to network parameter
func (*Client) Close ¶ added in v0.2.0
Close the Client and flush unsent metrics to the StatsHouse agent. No data will be sent after Close has returned.
func (*Client) Metric ¶ added in v0.2.0
Metric is the preferred way to access MetricRef to record observations. Metric calls should be encapsulated in helper functions. Direct calls like
statshouse.Metric("packet_size", statshouse.Tags{1: "ok"}).Value(float64(len(pkg)))
should be replaced with calls via higher-level helper functions:
RecordPacketSize(true, len(pkg)) func RecordPacketSize(ok bool, size int) { status := "fail" if ok { status = "ok" } statshouse.Metric("packet_size", statshouse.Tags{1: status}).Value(float64(size)) }
As an optimization, it is possible to save the result of Metric for later use:
var countPacketOK = statshouse.Metric("foo", statshouse.Tags{1: "ok"}) countPacketOK.Count(1) // lowest overhead possible
func (*Client) MetricNamed ¶ added in v0.2.0
MetricNamed is similar to *Client.Metric but slightly slower, and allows to specify tags by name.
func (*Client) SetEnv ¶ added in v0.2.0
SetEnv changes the default environment associated with Client.
func (*Client) StartRegularMeasurement ¶ added in v0.2.0
StartRegularMeasurement will call f once per collection interval with no gaps or drift, until StopRegularMeasurement is called with the same ID.
func (*Client) StopRegularMeasurement ¶ added in v0.2.0
StopRegularMeasurement cancels StartRegularMeasurement with the specified ID.
type LoggerFunc ¶
type LoggerFunc func(format string, args ...interface{})
type MetricRef ¶ added in v0.2.0
type MetricRef struct {
// contains filtered or unexported fields
}
MetricRef pointer is obtained via *Client.Metric or *Client.MetricNamed and is used to record attributes of observed events.
func Metric ¶
Metric calls *Client.Metric on the global Client. It is valid to call Metric before Configure.
func MetricNamed ¶ added in v0.2.0
MetricNamed calls *Client.MetricNamed on the global Client. It is valid to call MetricNamed before Configure.
func (*MetricRef) StringTop ¶ added in v0.2.0
StringTop records the observed value for popularity estimation.
func (*MetricRef) StringsTop ¶ added in v0.2.0
StringsTop records the observed values for popularity estimation.
func (*MetricRef) Unique ¶ added in v0.2.0
Unique records the observed value for cardinality estimation.
func (*MetricRef) Uniques ¶ added in v0.2.0
Uniques records the observed values for cardinality estimation.
type NamedTags ¶ added in v0.2.0
type NamedTags [][2]string
NamedTags are used to call *Client.MetricNamed.