statlogs

package
v1.0.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultStatsHouseAddr = "127.0.0.1:13337"
)

Variables

This section is empty.

Functions

func Close

func Close() error

Close registry on app exit, otherwise you risk losing some statistics, often related to reason of app exit after Close() no more data will be sent

func Configure

func Configure(logf LoggerFunc, statsHouseAddr string, env string)

Configure is expected to be called once on app startup. Order of Configure/AccessMetricRaw is not important, so AccessMetricRaw can be assigned to global var, then Configure called from main(). Pass empty address to configure Registry to silently discard all data (like /dev/null). If Env is empty (not specified) in call to AccessMetricRaw, env will be used instead.

func StartRegularMeasurement

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

StartRegularMeasurement will call f once per collection interval with no gaps or drift, until StopRegularMeasurement is called with the same ID.

func StopRegularMeasurement

func StopRegularMeasurement(id int)

StopRegularMeasurement cancels StartRegularMeasurement with specified id

Types

type LoggerFunc

type LoggerFunc func(format string, args ...interface{})

type Metric

type Metric struct {
	// contains filtered or unexported fields
}

see AccessMetricRaw docs for documentation

func AccessMetric

func AccessMetric(metric string, tags Tags) *Metric

AccessMetric we recommend to use AccessMetricRaw, but if you need to send custom named tags, use this usage example:

statlogs.AccessMetric("packet_size", statlogs.Tags{{"status", "ok"}, {"code", "2"}}).Value(10e3)

func AccessMetricRaw

func AccessMetricRaw(metric string, tags RawTags) *Metric

AccessMetricRaw is recommended to be used via helper functions, not directly. Instead of

statlogs.AccessMetricRaw("packet_size", statlogs.RawTags{Tag1: "ok"}).Value(float64(len(pkg)))

it is better to create a helper function that encapsulates raw access for your metric:

func RecordPacketSize(ok bool, size int) {
    status := "fail"
    if ok {
        status = "ok"
    }
    statlogs.AccessMetricRaw("packet_size", statlogs.RawTags{Tag1: status}).Value(float64(size))
}

RecordPacketSize(true, len(pkg))

AccessMetricRaw locks mutex for very short time (map access). Metric functions also lock mutex for very short time. so writing statistics cannot block your goroutines.

result of AccessMetricRaw can be saved if map access is too slow for your code, and even can be assigned to global variable

var countPacketOK = statlogs.AccessMetricRaw("foo", statlogs.RawTags{Tag1: "ok"})

so that when packet arrives

countPacketOK.Count(1)

will be extremely fast

func (*Metric) Count

func (m *Metric) Count(n float64)

func (*Metric) StringTop

func (m *Metric) StringTop(value string)

func (*Metric) StringsTop

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

func (*Metric) Unique

func (m *Metric) Unique(value int64)

func (*Metric) Uniques

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

func (*Metric) Value

func (m *Metric) Value(value float64)

func (*Metric) Values

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

type RawTags

type RawTags struct {
	Env, Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7, Tag8, Tag9, Tag10, Tag11, Tag12, Tag13, Tag14, Tag15 string
}

RawTags should not be used directly; see AccessMetricRaw docs for an example of proper usage.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry(logf LoggerFunc, statsHouseAddr string, env string) *Registry

Use only if you are sending metrics to 2 or more statshouses. Otherwise, simply use statlogs.Configure Do not forget to Close registry on app exit, otherwise you risk losing some data, often related to reason of app exit Pass empty address to configure Registry to silently discard all data (like /dev/null).

func (*Registry) AccessMetric

func (r *Registry) AccessMetric(metric string, tagsList Tags) *Metric

func (*Registry) AccessMetricRaw

func (r *Registry) AccessMetricRaw(metric string, tags RawTags) *Metric

see statlogs.AccessMetricRaw for documentation

func (*Registry) Close

func (r *Registry) Close() error

see statlogs.Close for documentation

func (*Registry) SetEnv

func (r *Registry) SetEnv(env string)

func (*Registry) StartRegularMeasurement

func (r *Registry) StartRegularMeasurement(f func(*Registry)) (id int)

see statlogs.StartRegularMeasurement for documentation

func (*Registry) StopRegularMeasurement

func (r *Registry) StopRegularMeasurement(id int)

see statlogs.StopRegularMeasurement for documentation

type Tags

type Tags [][2]string

Jump to

Keyboard shortcuts

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