statshouse

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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 LexDecode added in v0.2.2

func LexDecode(x int32) float32

func LexEncode added in v0.2.2

func LexEncode(x float32) int32

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 LexEncodeStr(x float32) string

func StartRegularMeasurement

func StartRegularMeasurement(f func(*Client)) (id int)

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

func (c *Client) Close() error

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

func (c *Client) Metric(metric string, tags Tags) *MetricRef

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

func (c *Client) MetricNamed(metric string, tags NamedTags) *MetricRef

MetricNamed is similar to *Client.Metric but slightly slower, and allows to specify tags by name.

func (*Client) SetEnv added in v0.2.0

func (c *Client) SetEnv(env string)

SetEnv changes the default environment associated with Client.

func (*Client) StartRegularMeasurement added in v0.2.0

func (c *Client) StartRegularMeasurement(f func(*Client)) (id int)

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

func (c *Client) StopRegularMeasurement(id int)

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

func Metric(metric string, tags Tags) *MetricRef

Metric calls *Client.Metric on the global Client. It is valid to call Metric before Configure.

func MetricNamed added in v0.2.0

func MetricNamed(metric string, tags NamedTags) *MetricRef

MetricNamed calls *Client.MetricNamed on the global Client. It is valid to call MetricNamed before Configure.

func (*MetricRef) Count added in v0.2.0

func (m *MetricRef) Count(n float64)

Count records the number of events or observations.

func (*MetricRef) StringTop added in v0.2.0

func (m *MetricRef) StringTop(value string)

StringTop records the observed value for popularity estimation.

func (*MetricRef) StringsTop added in v0.2.0

func (m *MetricRef) StringsTop(values []string)

StringsTop records the observed values for popularity estimation.

func (*MetricRef) Unique added in v0.2.0

func (m *MetricRef) Unique(value int64)

Unique records the observed value for cardinality estimation.

func (*MetricRef) Uniques added in v0.2.0

func (m *MetricRef) Uniques(values []int64)

Uniques records the observed values for cardinality estimation.

func (*MetricRef) Value added in v0.2.0

func (m *MetricRef) Value(value float64)

Value records the observed value for distribution estimation.

func (*MetricRef) Values added in v0.2.0

func (m *MetricRef) Values(values []float64)

Values records the observed values for distribution estimation.

type NamedTags added in v0.2.0

type NamedTags [][2]string

NamedTags are used to call *Client.MetricNamed.

type Tags

type Tags [maxTags]string

Tags are used to call *Client.Metric.

Directories

Path Synopsis
internal
basictl
Code generated by vktl/cmd/tlgen2; DO NOT EDIT.
Code generated by vktl/cmd/tlgen2; DO NOT EDIT.

Jump to

Keyboard shortcuts

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