Documentation ¶
Index ¶
- Variables
- func GetJSON(predicate func(string) bool) []byte
- func SetFormatter(f Formatter)
- func SetOutput(out io.Writer)
- func Write() error
- type Counter
- type DefaultMetrics
- func (m *DefaultMetrics) Formatter() Formatter
- func (m *DefaultMetrics) Get(counterName string) *Counter
- func (m *DefaultMetrics) GetJSON(predicate func(string) bool) []byte
- func (m *DefaultMetrics) SetFormatter(f Formatter)
- func (m *DefaultMetrics) SetOutput(out io.Writer)
- func (m *DefaultMetrics) SetRootPrefix(prefix string)
- func (m *DefaultMetrics) StartFileWriter(params FileWriterParams) Stopper
- func (m *DefaultMetrics) WithPrefix(prefix string, v ...interface{}) *PrefixMetrics
- func (m *DefaultMetrics) Write() error
- type FileWriterParams
- type Formatter
- type Metrics
- type PanicHandler
- type PrefixMetrics
- type SortedCounters
- type Stopper
Constants ¶
This section is empty.
Variables ¶
var Default = New()
Default is a standard metrics object.
Functions ¶
func GetJSON ¶
GetJSON filters counters by given predicate and returns them as a json marshaled map.
func SetFormatter ¶
func SetFormatter(f Formatter)
SetFormatter sets formatter for standard metrics. Fore more details see DefaultMetrics.SetFormatter().
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter represents a kind of metric.
type DefaultMetrics ¶
type DefaultMetrics struct {
// contains filtered or unexported fields
}
DefaultMetrics is a default implementation of Metrics.
func (*DefaultMetrics) Formatter ¶
func (m *DefaultMetrics) Formatter() Formatter
Formatter returns a metrics formatter.
func (*DefaultMetrics) Get ¶
func (m *DefaultMetrics) Get(counterName string) *Counter
Get returns counter by name. If counter doesn't exist it will be created.
func (*DefaultMetrics) GetJSON ¶
func (m *DefaultMetrics) GetJSON(predicate func(string) bool) []byte
GetJSON filters counters by given predicate and returns them as a json marshaled map.
func (*DefaultMetrics) SetFormatter ¶
func (m *DefaultMetrics) SetFormatter(f Formatter)
SetFormatter sets a metrics's formatter.
func (*DefaultMetrics) SetOutput ¶
func (m *DefaultMetrics) SetOutput(out io.Writer)
SetOutput sets output destination for metrics.
func (*DefaultMetrics) SetRootPrefix ¶
func (m *DefaultMetrics) SetRootPrefix(prefix string)
SetRootPrefix sets root prefix used to format output
func (*DefaultMetrics) StartFileWriter ¶
func (m *DefaultMetrics) StartFileWriter(params FileWriterParams) Stopper
StartFileWriter starts a goroutine that periodically writes metrics to a file.
func (*DefaultMetrics) WithPrefix ¶
func (m *DefaultMetrics) WithPrefix(prefix string, v ...interface{}) *PrefixMetrics
WithPrefix creates new PrefixMetrics that uses original Metrics with specified prefix.
func (*DefaultMetrics) Write ¶
func (m *DefaultMetrics) Write() error
Write writes all existing metrics to output destination.
Writing metrics to the file using this method will not recreate a file. It appends existing metrics to existing file's data. if you want to write metrics to clear file use StartFileWriter() method.
type FileWriterParams ¶
type FileWriterParams struct { FilePath string UpdateInterval time.Duration NoFlushOnStop bool ErrorHandler func(err error) }
FileWriterParams represents a params for asynchronous file writing operation.
FilePath represents a file path. UpdateInterval determines how often metrics data will be written to a file. NoFlushOnStop disables metrics flushing when the metrics writer finishes. ErrorHandler allows to handle errors from the goroutine that writes metrics.
type Formatter ¶
type Formatter interface {
Format(counters SortedCounters) []byte
}
Formatter determines a format of metrics representation.
func NewFormatter ¶
NewFormatter returns new default formatter.
lineSeparator determines how one line of metric will be separated from another.
As line separator can be used any symbol: e.g. '\n', ':', '.', ','.
Default format for one line of metrics is: "%v = %v". Metrics will be sorted by key.
type Metrics ¶
type Metrics interface { SetOutput(io.Writer) SetFormatter(Formatter) Formatter() Formatter Get(string) *Counter GetJSON(func(string) bool) []byte WithPrefix(string, ...interface{}) *PrefixMetrics Write() error StartFileWriter(FileWriterParams) Stopper }
Metrics is a collection of metrics.
type PanicHandler ¶
type PanicHandler interface {
Handle(err error)
}
PanicHandler is used to handle errors that causing the panic.
type PrefixMetrics ¶
type PrefixMetrics struct { Metrics // contains filtered or unexported fields }
PrefixMetrics is a Metrics wrapper, that always add specified prefix to counters names.
func WithPrefix ¶
func WithPrefix(prefix string, v ...interface{}) *PrefixMetrics
WithPrefix creates new PrefixMetrics that uses original Metrics with specified prefix. For more details see DefaultMetrics.WithPrefix().
func (*PrefixMetrics) Get ¶
func (m *PrefixMetrics) Get(counterName string) *Counter
Get calls underlying Metrics Get method with prefixed counterName.
func (*PrefixMetrics) WithPrefix ¶
func (m *PrefixMetrics) WithPrefix(prefix string, v ...interface{}) *PrefixMetrics
WithPrefix returns new PrefixMetrics with extended prefix.
type SortedCounters ¶
SortedCounters represents counters slice sorted by name
type Stopper ¶
type Stopper interface {
Stop()
}
Stopper is used to stop started entities.
func StartFileWriter ¶
func StartFileWriter(p FileWriterParams) Stopper
StartFileWriter starts a goroutine that periodically writes metrics to a file. For more details see DefaultMetrics.StartFileWriter().