Documentation
¶
Overview ¶
Package mio provides tools to combine io.Writer and metrics.Histogram interfaces, so that every non-empty Write call latency value is sampled to Histogram.
Writer and Reader can be used to bind standard metrics.Histogram to io.Writer and io.Reader. SelfCleaningHistogram provides a wrapper over metrics.Histogram with self-cleaning capabilities, which can be used for sharing one Histogram over multiple writers/readers and cleaning sample pool after period of inactivity.
This package is intended to be used with go-metrics: (https://github.com/rcrowley/go-metrics) or metrics (https://github.com/facebookgo/metrics) packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Histogram ¶
type Histogram interface {
Clear()
Count() int64
Max() int64
Mean() float64
Min() int64
Percentile(float64) float64
Percentiles([]float64) []float64
StdDev() float64
Update(int64)
Variance() float64
}
Histogram interface wraps a subset of methods of metrics.Histogram interface so it can be used without type conversion.
type Reader ¶
Reader wraps io.Reader and registers each read operation latency in attached histogram
func NewReader ¶
NewReader attaches provided histogram to reader, returning new io.Reader. If histogram implements Registrar interface, this would also call its Register() method.
type Registrar ¶
type Registrar interface {
Register()
Done()
Shutdown()
}
Registrar interface can be used to track object's concurrent usage.
Its Register method announces goroutine's intent to use this object's facilities; Done method should be called when goroutine finished working with this object. Shutdown method stops associated background goroutines so that resources can be garbage collected.
These methods provide a similar semantics as sync.WaitGroup's Add(1), and Done() methods.
type SelfCleaningHistogram ¶
type SelfCleaningHistogram struct {
Histogram
// contains filtered or unexported fields
}
SelfCleaningHistogram wraps metrics.Histogram, adding self-cleaning feature if no samples were registered for a specified time. SelfCleaningHistogram also implements Registrar interface, call Register() method to announce following sample updates, call Done() after all samples were added. If no outstanding workers registered (for each Register() call Done() call were made), self-cleaning timer would start, cleaning histogram's sample pool in absence of Register() calls before timer fires.
func NewSelfCleaningHistogram ¶
func NewSelfCleaningHistogram(histogram Histogram, delay time.Duration) *SelfCleaningHistogram
NewSelfCleaningHistogram returns SelfCleaningHistogram wrapping specified histogram; its self-cleaning period set to delay.
func (*SelfCleaningHistogram) Done ¶
func (h *SelfCleaningHistogram) Done()
Done implements Registrar interface, using sync.WaitGroup.Done() for each call.
func (*SelfCleaningHistogram) Register ¶
func (h *SelfCleaningHistogram) Register()
Register implements Registrar interface, using sync.WaitGroup.Add(1) for each call, blocking self-cleaning timer until all object's users releases it with Done() call.
func (*SelfCleaningHistogram) Shutdown ¶
func (h *SelfCleaningHistogram) Shutdown()
Shutdown implements Registrar interface, it stops background goroutine. This method should be called as the very last method on object and needed only if object has to be removed and garbage collected.
type Writer ¶
Writer wraps io.Writer and registers each write operation latency in attached histogram
func NewWriter ¶
NewWriter attaches provided histogram to writer, returning new io.Writer. If histogram implements Registrar interface, this would also call its Register() method.