Documentation ¶
Index ¶
- Constants
- func Close() error
- func Configure(logf LoggerFunc, statsHouseAddr string, env string)
- func StartRegularMeasurement(f func(*Registry)) (id int)
- func StopRegularMeasurement(id int)
- type LoggerFunc
- type Metric
- type RawTags
- type Registry
- func (r *Registry) AccessMetric(metric string, tagsList Tags) *Metric
- func (r *Registry) AccessMetricRaw(metric string, tags RawTags) *Metric
- func (r *Registry) Close() error
- func (r *Registry) SetEnv(env string)
- func (r *Registry) StartRegularMeasurement(f func(*Registry)) (id int)
- func (r *Registry) StopRegularMeasurement(id int)
- type Tags
Constants ¶
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 ¶
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 ¶
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 ¶
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) StringsTop ¶
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 (*Registry) AccessMetricRaw ¶
see statlogs.AccessMetricRaw for documentation
func (*Registry) StartRegularMeasurement ¶
see statlogs.StartRegularMeasurement for documentation
func (*Registry) StopRegularMeasurement ¶
see statlogs.StopRegularMeasurement for documentation