Documentation
¶
Index ¶
- Constants
- func Incr[V StatValue](key string, val V, labels ...Label)
- func MeasureSince(key string, start time.Time, labels ...Label)
- func Observe[V StatValue](key string, val V, labels ...Label)
- func Sample[V StatValue](key string, val V, labels ...Label)
- func SetGauge[V StatValue](key string, val V, labels ...Label)
- func Shutdown()
- type AggregateSample
- type AggregatedCounter
- type BlackholeSink
- type Config
- type ConfigOption
- type Counter
- type Distribution
- type Encoder
- type FanoutSink
- type Gauge
- type GaugeValue
- type Histogram
- type InmemSignal
- type InmemSink
- func (i *InmemSink) BuildMetricEmitter(mType MetricType, keys []string, labels []Label) MetricEmitter
- func (i *InmemSink) Data() []*IntervalMetrics
- func (i *InmemSink) DisplayMetrics(resp http.ResponseWriter, req *http.Request) (interface{}, error)
- func (i *InmemSink) Stream(ctx context.Context, encoder Encoder)
- type IntervalMetrics
- type Label
- type MetricEmitter
- type MetricSink
- type MetricType
- type Metrics
- func (m *Metrics) Incr(key string, val float64, labels ...Label)
- func (m *Metrics) MeasureSince(key string, start time.Time, labels ...Label)
- func (m *Metrics) NewAggregatedCounter(key string, labels ...Label) AggregatedCounter
- func (m *Metrics) NewCounter(key string, labels ...Label) Counter
- func (m *Metrics) NewDistribution(key string, labels ...Label) Distribution
- func (m *Metrics) NewGauge(key string, labels ...Label) Gauge
- func (m *Metrics) NewHistogram(key string, labels ...Label) Histogram
- func (m *Metrics) NewPersistentGauge(key string, labels ...Label) PersistentGauge
- func (m *Metrics) NewTimer(key string, labels ...Label) Timer
- func (m *Metrics) Observe(key string, val float64, labels ...Label)
- func (m *Metrics) Sample(key string, val float64, labels ...Label)
- func (m *Metrics) SetGauge(key string, val float64, labels ...Label)
- func (m *Metrics) Shutdown()
- type MetricsSummary
- type PersistentGauge
- type SampledValue
- type ShutdownSink
- type StatValue
- type StatsiteSink
- type Timer
Constants ¶
const ( // DefaultSignal is used with DefaultInmemSignal DefaultSignal = syscall.SIGUSR1 )
Variables ¶
This section is empty.
Functions ¶
func MeasureSince ¶
MeasureSince records the time elapsed since an event, often as a histogram
func Shutdown ¶
func Shutdown()
Shutdown disables metric collection, then blocks while attempting to flush metrics to storage. WARNING: Not all MetricSink backends support this functionality, and calling this will cause them to leak resources. This is intended for use immediately prior to application exit.
Types ¶
type AggregateSample ¶
type AggregateSample struct { Count int // The count of emitted pairs Rate float64 // The values rate per time unit (usually 1 second) Sum float64 // The sum of values SumSq float64 `json:"-"` // The sum of squared values Min float64 // Minimum value Max float64 // Maximum value LastUpdated time.Time `json:"-"` // When value was last updated }
AggregateSample is used to hold aggregate metrics about a sample
func (*AggregateSample) Ingest ¶
func (a *AggregateSample) Ingest(v float64, rateDenom float64)
Ingest is used to update a sample
func (*AggregateSample) Mean ¶
func (a *AggregateSample) Mean() float64
Computes a mean of the values
func (*AggregateSample) Stddev ¶
func (a *AggregateSample) Stddev() float64
Computes a Stddev of the values
func (*AggregateSample) String ¶
func (a *AggregateSample) String() string
type AggregatedCounter ¶
type AggregatedCounter interface { Stop() Incr(delta int64) }
An AggregatedCounter can be useful for extremely hot-path metric instrumentation. It aggregates the total increment delta internally and publishes the current delta on each report interval. Unlike the PersistentGauge, an AggregatedCounter will reset its value to zero on each reporting interval.
func NewAggregatedCounter ¶
func NewAggregatedCounter(key string, labels ...Label) AggregatedCounter
type BlackholeSink ¶
type BlackholeSink struct{}
BlackholeSink is used to just blackhole messages
func (*BlackholeSink) BuildMetricEmitter ¶
func (s *BlackholeSink) BuildMetricEmitter(_ MetricType, _ []string, _ []Label) MetricEmitter
type Config ¶
type Config struct { ServiceName string // Name of service, added to labels if EnableServiceLabel is set HostName string // Hostname to use. If not provided and EnableHostname, it will be os.Hostname EnableHostnameLabel bool // Enable adding hostname to labels EnableServiceLabel bool // Enable adding service to labels EnableServicePrefix bool // Enable adding service to the metrics key EnableRuntimeMetrics bool // Enables profiling of runtime metrics (GC, Goroutines, Memory) EnableTypePrefix bool // Prefixes key with a type ("counter", "gauge", "timer") TimerGranularity time.Duration // Granularity of timers. ProfileInterval time.Duration // Interval to profile runtime metrics PersistentInterval time.Duration // Interval to publish persisted metrics BaseLabels []Label // Default labels applied to all measurements AllowedPrefixes []string // A list of metric prefixes to allow, with '.' as the separator BlockedPrefixes []string // A list of metric prefixes to block, with '.' as the separator AllowedLabels []string // A list of metric labels to allow, with '.' as the separator BlockedLabels []string // A list of metric labels to block, with '.' as the separator FilterDefault bool // Whether to allow metrics by default }
Config is used to configure metrics settings
type ConfigOption ¶ added in v0.0.3
type ConfigOption func(cfg *Config)
type Counter ¶
type Counter interface {
Incr(val float64)
}
func NewCounter ¶
NewCounter creates a memoized counter
type Distribution ¶
type Distribution interface {
Observe(val float64)
}
func NewDistribution ¶
func NewDistribution(key string, labels ...Label) Distribution
NewDistribution creates a memoized histogram
type FanoutSink ¶
type FanoutSink struct {
Sinks []MetricSink
}
FanoutSink is used to sink to fanout values to multiple sinks
func (FanoutSink) BuildMetricEmitter ¶
func (fh FanoutSink) BuildMetricEmitter(mType MetricType, keys []string, labels []Label) MetricEmitter
func (FanoutSink) Shutdown ¶
func (fh FanoutSink) Shutdown()
type GaugeValue ¶
type Histogram ¶
type Histogram interface {
Sample(val float64)
}
func NewHistogram ¶
NewHistogram creates a memoized histogram
type InmemSignal ¶
type InmemSignal struct {
// contains filtered or unexported fields
}
InmemSignal is used to listen for a given signal, and when received, to dump the current metrics from the InmemSink to an io.Writer
func DefaultInmemSignal ¶
func DefaultInmemSignal(inmem *InmemSink) *InmemSignal
DefaultInmemSignal returns a new InmemSignal that responds to SIGUSR1 and writes output to stderr. Windows uses SIGBREAK
func NewInmemSignal ¶
NewInmemSignal creates a new InmemSignal which listens for a given signal, and dumps the current metrics out to a writer
func (*InmemSignal) Stop ¶
func (i *InmemSignal) Stop()
Stop is used to stop the InmemSignal from listening
type InmemSink ¶
type InmemSink struct {
// contains filtered or unexported fields
}
InmemSink provides a MetricSink that does in-memory aggregation without sending metrics over a network. It can be embedded within an application to provide profiling information.
func NewInmemSink ¶
NewInmemSink is used to construct a new in-memory sink. Uses an aggregation interval and maximum retention period.
func (*InmemSink) BuildMetricEmitter ¶
func (i *InmemSink) BuildMetricEmitter(mType MetricType, keys []string, labels []Label) MetricEmitter
func (*InmemSink) Data ¶
func (i *InmemSink) Data() []*IntervalMetrics
Data is used to retrieve all the aggregated metrics Intervals may be in use, and a read lock should be acquired
func (*InmemSink) DisplayMetrics ¶
func (i *InmemSink) DisplayMetrics(resp http.ResponseWriter, req *http.Request) (interface{}, error)
DisplayMetrics returns a summary of the metrics from the most recent finished interval.
type IntervalMetrics ¶
type IntervalMetrics struct { sync.RWMutex // The start time of the interval Interval time.Time // Gauges maps the key to the last set value Gauges map[string]GaugeValue // Counters maps the string key to a sum of the counter // values Counters map[string]SampledValue // Samples maps the key to an AggregateSample, // which has the rolled up view of a sample Samples map[string]SampledValue // contains filtered or unexported fields }
IntervalMetrics stores the aggregated metrics for a specific interval
func NewIntervalMetrics ¶
func NewIntervalMetrics(intv time.Time) *IntervalMetrics
NewIntervalMetrics creates a new IntervalMetrics for a given interval
type MetricEmitter ¶
type MetricEmitter func(val float64)
type MetricSink ¶
type MetricSink interface {
BuildMetricEmitter(mType MetricType, keys []string, labels []Label) MetricEmitter
}
The MetricSink interface is used to transmit metrics information to an external system
func NewInmemSinkFromURL ¶
func NewInmemSinkFromURL(u *url.URL) (MetricSink, error)
NewInmemSinkFromURL creates an InmemSink from a URL. It is used (and tested) from NewMetricSinkFromURL.
func NewMetricSinkFromURL ¶
func NewMetricSinkFromURL(urlStr string) (MetricSink, error)
NewMetricSinkFromURL allows a generic URL input to configure any of the supported sinks. The scheme of the URL identifies the type of the sink, the and query parameters are used to set options.
"statsd://" - Initializes a StatsdSink. The host and port are passed through as the "addr" of the sink
"statsite://" - Initializes a StatsiteSink. The host and port become the "addr" of the sink
"inmem://" - Initializes an InmemSink. The host and port are ignored. The "interval" and "duration" query parameters must be specified with valid durations, see NewInmemSink for details.
func NewStatsiteSinkFromURL ¶
func NewStatsiteSinkFromURL(u *url.URL) (MetricSink, error)
NewStatsiteSinkFromURL creates an StatsiteSink from a URL. It is used (and tested) from NewMetricSinkFromURL.
type MetricType ¶
type MetricType int
const ( MetricTypeCounter MetricType = iota MetricTypeGauge MetricTypeTimer MetricTypeHistogram MetricTypeDistribution )
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics represents an instance of a metrics sink that can be used to emit
func New ¶
func New(sink MetricSink, opts ...ConfigOption) (*Metrics, error)
New is used to create a new instance of Metrics
func NewGlobal ¶
func NewGlobal(sink MetricSink, opts ...ConfigOption) (*Metrics, error)
NewGlobal is the same as New, but it assigns the metrics object to be used globally as well as returning it.
func (*Metrics) MeasureSince ¶
func (*Metrics) NewAggregatedCounter ¶
func (m *Metrics) NewAggregatedCounter(key string, labels ...Label) AggregatedCounter
func (*Metrics) NewDistribution ¶
func (m *Metrics) NewDistribution(key string, labels ...Label) Distribution
func (*Metrics) NewHistogram ¶
func (*Metrics) NewPersistentGauge ¶
func (m *Metrics) NewPersistentGauge(key string, labels ...Label) PersistentGauge
type MetricsSummary ¶
type MetricsSummary struct { Timestamp string Gauges []GaugeValue Counters []SampledValue Samples []SampledValue }
MetricsSummary holds a roll-up of metrics info for a given interval
type PersistentGauge ¶
type PersistentGauge interface { Stop() Set(val int64) int64 Incr(val int64) int64 Decr(val int64) int64 }
A PersistentGauge maintains an observed value internally and publish the last seen value on the publishing interval. The behavior is the same as using the SetGauge method, however instead of each call posting a value to the sink and the sink (e.g. agent) keeping the last value, this happens before the sink.
func NewPersistentGauge ¶
func NewPersistentGauge(key string, labels ...Label) PersistentGauge
type SampledValue ¶
type ShutdownSink ¶
type ShutdownSink interface { MetricSink // Shutdown the metric sink, flush metrics to storage, and cleanup resources. // Called immediately prior to application exit. Implementations must block // until metrics are flushed to storage. Shutdown() }
type StatsiteSink ¶
type StatsiteSink struct {
// contains filtered or unexported fields
}
StatsiteSink provides a MetricSink that can be used with a statsite metrics server
func NewStatsiteSink ¶
func NewStatsiteSink(addr string) (*StatsiteSink, error)
NewStatsiteSink is used to create a new StatsiteSink
func (*StatsiteSink) BuildMetricEmitter ¶
func (s *StatsiteSink) BuildMetricEmitter(mType MetricType, keys []string, labels []Label) MetricEmitter
func (*StatsiteSink) Shutdown ¶
func (s *StatsiteSink) Shutdown()
Close is used to stop flushing to statsite