Documentation ¶
Overview ¶
Package metrics provide easy to use, stand alone metrics and exposes it via HTTP. It can create metric's snapshots each defined interval and store it in a pool. That useful for fast monitoring of current performance without necessity of data export to external applications.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a cumulative metric that represents a single numerical value that only ever goes up. Satsfies Metric interface.
func NewCounter ¶
NewCounter returns new counter that satsfies Metric interface.
type DefaultRegistry ¶
DefaultRegistry its a plain container for metrics. It just keeps metric
func (*DefaultRegistry) AddMetrics ¶
func (r *DefaultRegistry) AddMetrics(metrics ...Metric) error
AddMetrics adds one or more metrics into registry
func (*DefaultRegistry) GetMetricByName ¶
func (r *DefaultRegistry) GetMetricByName(name string) (Metric, error)
GetMetricByName returns metric by given name
func (*DefaultRegistry) GetMetrics ¶
func (r *DefaultRegistry) GetMetrics() map[string]Metric
GetMetrics returns map of registred metrics
type ErrEmptyMetricName ¶
type ErrEmptyMetricName struct{}
ErrEmptyMetricName error type on empty metric name.
func (ErrEmptyMetricName) Error ¶
func (e ErrEmptyMetricName) Error() string
type ErrEmptyRegistryName ¶
type ErrEmptyRegistryName struct{}
ErrEmptyRegistryName error type on empty registry name.
func (ErrEmptyRegistryName) Error ¶
func (e ErrEmptyRegistryName) Error() string
type ErrMetricExists ¶
type ErrMetricExists string
ErrMetricExists error type - metric with provided name exists.
func (ErrMetricExists) Error ¶
func (e ErrMetricExists) Error() string
type ErrMetricUnknown ¶
type ErrMetricUnknown string
ErrMetricUnknown error type on provided metric name is unknown.
func (ErrMetricUnknown) Error ¶
func (e ErrMetricUnknown) Error() string
type ErrRegistryExists ¶
type ErrRegistryExists string
ErrRegistryExists error type - registry with provided is exists.
func (ErrRegistryExists) Error ¶
func (e ErrRegistryExists) Error() string
type ErrRegistryUnknown ¶
type ErrRegistryUnknown string
ErrRegistryUnknown error type on provided registry name is unknown.
func (ErrRegistryUnknown) Error ¶
func (e ErrRegistryUnknown) Error() string
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge is a metric that represents a single float64 value that can arbitrarily go up and down. Satsfies Metric interface.
type Metric ¶
type Metric interface { // Get returns a metric value. Get() interface{} // String returns formatted value of metric. String() string // Name returns metric name. Name() string // contains filtered or unexported methods }
Metric is an abstract type of metric.
type Registry ¶
type Registry interface { AddMetrics(metrics ...Metric) error GetMetricByName(name string) (Metric, error) GetMetrics() map[string]Metric }
Registry is an abstract type for metric countainer
func GetRegistryByName ¶
GetRegistryByName returns Registry by given name
func NewRegistry ¶
NewRegistry creates a new registry and adds it into the registry map
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is a struct for snapshoted metrics It stores snapshot timestamp and map of metrics
func (*Snapshot) GetMetricByName ¶
GetMetricByName returns Metric by given name
func (*Snapshot) GetMetrics ¶
GetMetrics returns all metrics from snapshot
func (*Snapshot) GetTimestamp ¶
GetTimestamp returns timestamp of metrics snapshot
type TrackRegistry ¶
type TrackRegistry struct { DefaultRegistry // contains filtered or unexported fields }
TrackRegistry is a registry that can stores the pool of snapshoted metrics.
func (*TrackRegistry) GetSnapshots ¶
func (r *TrackRegistry) GetSnapshots() []Snapshot
GetSnapshots returns slice of swaped metrics
type Tracker ¶
Tracker is an abstract type for countainer with metrics snaphshot Implements Registry interface
func NewTrackRegistry ¶
func NewTrackRegistry(name string, capacity int, interval time.Duration, align bool) (Tracker, error)
NewTrackRegistry creates a new TrackRegistry and adds it into the registry map. It makes the snapshots of metric on each interval and keeps it in pool with specified capacity. If align is set to true, metric's archiving will be align by interval duration. For examaple:
// If application will be started at 12:10:13 // this registry will create snaphosts at 13:10:13, 14:10:13, 15:10:13 etc. NewTrackRegistry("stat per minute", 10, time.Hour, false) // but this will create snaphosts at 13:00:00, 14:00:00, 15:00:00 etc. NewTrackRegistry("stat per minute", 10, time.Hour, true)