Documentation ¶
Overview ¶
this is s struct for event-flow, and you can define it's size
Index ¶
- Constants
- Variables
- func Collector(name string, i interface{}) error
- func Each(f func(string, interface{}))
- func Get(name string) interface{}
- func GetOrCollector(name string, i interface{}) interface{}
- func InitMetrics(me *Metrics)
- func MustCollector(name string, i interface{})
- func RunHealthchecks()
- func Size() int64
- func UnCollector(name string)
- type Collectry
- type Counter
- type DuplicateMetric
- type EWMA
- type Flow
- type Gauge
- type GaugeFloat64
- type Healthcheck
- type Histogram
- type Meter
- type Metrics
- type Mstring
- type NilHealthcheck
- type Options
- type PrefixedCollectry
- func (r *PrefixedCollectry) Collector(name string, metric interface{}) error
- func (r *PrefixedCollectry) Each(fn func(string, interface{}))
- func (r *PrefixedCollectry) Get(name string) interface{}
- func (r *PrefixedCollectry) GetOrCollector(name string, metric interface{}) interface{}
- func (r *PrefixedCollectry) RunHealthchecks()
- func (r *PrefixedCollectry) Size() int64
- func (r *PrefixedCollectry) Uncollector(name string)
- func (r *PrefixedCollectry) UncollectorAll()
- func (r *PrefixedCollectry) Values() interface{}
- type Sample
- type StandardCollectry
- func (r *StandardCollectry) Collector(name string, i interface{}) error
- func (r *StandardCollectry) Each(f func(string, interface{}))
- func (r *StandardCollectry) Get(name string) interface{}
- func (r *StandardCollectry) GetOrCollector(name string, i interface{}) interface{}
- func (r *StandardCollectry) RunHealthchecks()
- func (r *StandardCollectry) Size() int64
- func (r *StandardCollectry) Uncollector(name string)
- func (r *StandardCollectry) UncollectorAll()
- func (r *StandardCollectry) Values() interface{}
- type StandardHealthcheck
- type Tickable
- type Timer
Constants ¶
const TickDuration = 5 * time.Second
TickDuration defines the rate at which Tick() should get called for EWMA and other Tickable things that rely on EWMA like Meter & Timer.
Variables ¶
var UseNilMetrics bool = false
Functions ¶
func Collector ¶
Collector the given metric under the given name. Returns a DuplicateMetric if a metric by the given name is already Collectored.
func Each ¶
func Each(f func(string, interface{}))
Call the given function for each Collectored metric.
func Get ¶
func Get(name string) interface{}
Get the metric by the given name or nil if none is Collectored.
func GetOrCollector ¶
func GetOrCollector(name string, i interface{}) interface{}
Gets an existing metric or creates and Collectors a new one. Threadsafe alternative to calling Get and Collector on failure.
func MustCollector ¶
func MustCollector(name string, i interface{})
Collector the given metric under the given name. Panics if a metric by the given name is already Collectored.
Types ¶
type Collectry ¶
type Collectry interface { // Call the given function for each Collectored metric. Each(func(string, interface{})) // Get the metric by the given name or nil if none is Collectored. Get(string) interface{} // Gets an existing metric or Collectors the given one. // The interface can be the metric to Collector if not found in Collectry, // or a function returning the metric for lazy instantiation. GetOrCollector(string, interface{}) interface{} // Collector the given metric under the given name. Collector(string, interface{}) error // Run all Collectored healthchecks. RunHealthchecks() // UnCollector the metric with the given name. Uncollector(string) // UnCollector all metrics. (Mostly for testing.) UncollectorAll() // Get metrics Values() interface{} // Get metrics number Size() int64 }
A Collectry holds references to a set of metrics by name and can iterate over them, calling callback functions provided by the user.
This is an interface so as to encourage other structs to implement the Collectry API as appropriate.
var DefaultCollectry Collectry = NewCollectry()
func NewPrefixedCollectry ¶
type Counter ¶
type Counter interface { // Clear the counter: set it to zero. Clear() // Return the current count. Count() int64 // Decrement the counter by the given amount. Dec(amount int64) Counter // Increment the counter by the given amount. Inc(amount int64) Counter }
Counters hold an int64 value that can be incremented and decremented.
type DuplicateMetric ¶
type DuplicateMetric string
DuplicateMetric is the error returned by Collectry.Collector when a metric already exists. If you mean to Collector that metric you must first UnCollector the existing metric.
func (DuplicateMetric) Error ¶
func (err DuplicateMetric) Error() string
type EWMA ¶
type EWMA interface { // Return the moving average rate of events per second. Rate() float64 // Tick the clock to update the moving average. Tick() // Add n uncounted events. Update(n int64) }
EWMAs continuously calculate an exponentially-weighted moving average based on an outside source of clock ticks.
func NewEWMA1 ¶
func NewEWMA1() EWMA
Create a new EWMA with alpha set for a one-minute moving average.
type Flow ¶
type Flow interface { // Clear all flows. Clear() // Return the size of the flows, which is at most the reservoir size. Size() int64 // Return all the values in the flow. Values() (values []string) // right pop and push operation RPop() (string, error) RPush(string) // left pop and push operation LPop() (string, error) LPush(string) }
type Gauge ¶
type Gauge interface { // Update the gauge's value. Update(value int64) // Return the gauge's current value. Value() int64 }
Gauges hold an int64 value that can be set arbitrarily.
type GaugeFloat64 ¶
type GaugeFloat64 interface { // Update the gauge's value. Update(value float64) // Return the gauge's current value. Value() float64 }
Gauges hold an int64 value that can be set arbitrarily.
type Healthcheck ¶
Healthchecks hold an error value describing an arbitrary up/down status.
func NewHealthcheck ¶
func NewHealthcheck(f func(Healthcheck)) Healthcheck
NewHealthcheck constructs a new Healthcheck which will use the given function to update its status.
type Histogram ¶
type Histogram interface { // Clear the histogram. Clear() // Return the count of inputs since the histogram was last cleared. Count() int64 // Return the sum of inputs since the histogram was last cleared. Sum() int64 // Return the maximal value seen since the histogram was last cleared. Max() int64 // Return the mean of all values seen since the histogram was last cleared. Mean() float64 // Return the minimal value seen since the histogram was last cleared. Min() int64 // Return an arbitrary percentile of all values seen since the histogram was // last cleared. Percentile(p float64) float64 // Return a slice of arbitrary percentiles of all values seen since the // histogram was last cleared. Percentiles(ps []float64) []float64 // Return the standard deviation of all values seen since the histogram was // last cleared. StdDev() float64 // Update the histogram with a new value. Update(value int64) // Return the variance of all values seen since the histogram was last cleared. Variance() float64 }
Histograms calculate distribution statistics from an int64 value.
func NewHistogram ¶
Create a new histogram with the given Sample. The initial values compare so that the first value will be both min and max and the variance is flagged for special treatment on its first iteration.
type Meter ¶
type Meter interface { // Return the count of events seen. Count() int64 // Mark the occurance of n events. Mark(n int64) // Tick the clock to update the moving average. Tick() // Return the meter's one-minute moving average rate of events. Rate1() float64 // Return the meter's five-minute moving average rate of events. Rate5() float64 // Return the meter's fifteen-minute moving average rate of events. Rate15() float64 // Return the meter's mean rate of events. RateMean() float64 }
Meters count events to produce exponentially-weighted moving average rates at one-, five-, and fifteen-minutes and a mean rate.
type Metrics ¶
type Metrics struct { Metrics map[string]interface{} Path string Addr string // contains filtered or unexported fields }
metrics-data struct
func NewMetrics ¶
func (*Metrics) Metrics2string ¶
func (*Metrics) MetricsResponse ¶
func (me *Metrics) MetricsResponse(w http.ResponseWriter, req *http.Request)
Metrics数据解析响应
type Mstring ¶
type Mstring interface { // Update the mstring's value. Update(value string) // Return the mstring's current value. Value() string }
plains hold an int64 value that can be set arbitrarily.
type PrefixedCollectry ¶
type PrefixedCollectry struct {
// contains filtered or unexported fields
}
func (*PrefixedCollectry) Collector ¶
func (r *PrefixedCollectry) Collector(name string, metric interface{}) error
Collector the given metric under the given name. The name will be prefixed.
func (*PrefixedCollectry) Each ¶
func (r *PrefixedCollectry) Each(fn func(string, interface{}))
Call the given function for each Collectored metric.
func (*PrefixedCollectry) Get ¶
func (r *PrefixedCollectry) Get(name string) interface{}
Get the metric by the given name or nil if none is Collectored.
func (*PrefixedCollectry) GetOrCollector ¶
func (r *PrefixedCollectry) GetOrCollector(name string, metric interface{}) interface{}
Gets an existing metric or Collectors the given one. The interface can be the metric to Collector if not found in Collectry, or a function returning the metric for lazy instantiation.
func (*PrefixedCollectry) RunHealthchecks ¶
func (r *PrefixedCollectry) RunHealthchecks()
Run all Collectored healthchecks.
func (*PrefixedCollectry) Uncollector ¶
func (r *PrefixedCollectry) Uncollector(name string)
UnCollector the metric with the given name. The name will be prefixed.
func (*PrefixedCollectry) UncollectorAll ¶
func (r *PrefixedCollectry) UncollectorAll()
UnCollector all metrics. (Mostly for testing.)
func (*PrefixedCollectry) Values ¶
func (r *PrefixedCollectry) Values() interface{}
type Sample ¶
type Sample interface { // Clear all samples. Clear() // Return the size of the sample, which is at most the reservoir size. Size() int // Update the sample with a new value. Update(value int64) // Return all the values in the sample. Values() []int64 }
Samples maintain a statistically-significant selection of values from a stream.
func NewExpDecaySample ¶
Create a new exponentially-decaying sample with the given reservoir size and alpha.
func NewUniformSample ¶
Create a new uniform sample with the given reservoir size.
type StandardCollectry ¶
type StandardCollectry struct {
// contains filtered or unexported fields
}
The standard implementation of a Collectry is a mutex-protected map of names to metrics.
func (*StandardCollectry) Collector ¶
func (r *StandardCollectry) Collector(name string, i interface{}) error
Collector the given metric under the given name. Returns a DuplicateMetric if a metric by the given name is already Collectored.
func (*StandardCollectry) Each ¶
func (r *StandardCollectry) Each(f func(string, interface{}))
Call the given function for each Collectored metric.
func (*StandardCollectry) Get ¶
func (r *StandardCollectry) Get(name string) interface{}
Get the metric by the given name or nil if none is Collectored.
func (*StandardCollectry) GetOrCollector ¶
func (r *StandardCollectry) GetOrCollector(name string, i interface{}) interface{}
Gets an existing metric or creates and Collectors a new one. Threadsafe alternative to calling Get and Collector on failure. The interface can be the metric to Collector if not found in Collectry, or a function returning the metric for lazy instantiation.
func (*StandardCollectry) RunHealthchecks ¶
func (r *StandardCollectry) RunHealthchecks()
Run all Collectored healthchecks.
func (*StandardCollectry) Uncollector ¶
func (r *StandardCollectry) Uncollector(name string)
UnCollector the metric with the given name.
func (*StandardCollectry) UncollectorAll ¶
func (r *StandardCollectry) UncollectorAll()
UnCollector all metrics. (Mostly for testing.)
func (*StandardCollectry) Values ¶
func (r *StandardCollectry) Values() interface{}
type StandardHealthcheck ¶
type StandardHealthcheck struct {
// contains filtered or unexported fields
}
StandardHealthcheck is the standard implementation of a Healthcheck and stores the status and a function to call to update the status.
func (*StandardHealthcheck) Check ¶
func (h *StandardHealthcheck) Check()
Check runs the healthcheck function to update the healthcheck's status.
func (*StandardHealthcheck) Error ¶
func (h *StandardHealthcheck) Error() error
Error returns the healthcheck's status, which will be nil if it is healthy.
func (*StandardHealthcheck) Healthy ¶
func (h *StandardHealthcheck) Healthy()
Healthy marks the healthcheck as healthy.
func (*StandardHealthcheck) Unhealthy ¶
func (h *StandardHealthcheck) Unhealthy(err error)
Unhealthy marks the healthcheck as unhealthy. The error is stored and may be retrieved by the Error method.
type Tickable ¶
type Tickable interface {
// Tick the clock to update the moving average.
Tick()
}
Tickable defines the interface implemented by poetry that need to Tick.
type Timer ¶
type Timer interface { // Return the count of inputs. Count() int64 // Return the maximal value seen. Max() int64 // Return the mean of all values seen. Mean() float64 // Return the minimal value seen. Min() int64 // Return an arbitrary percentile of all values seen. Percentile(p float64) float64 // Return a slice of arbitrary percentiles of all values seen. Percentiles(ps []float64) []float64 // Return the meter's one-minute moving average rate of events. Rate1() float64 // Return the meter's five-minute moving average rate of events. Rate5() float64 // Return the meter's fifteen-minute moving average rate of events. Rate15() float64 // Return the meter's mean rate of events. RateMean() float64 // Return the standard deviation of all values seen. StdDev() float64 // Start captures the current time and returns a value which implements Stop // to log the elapsed time. It should be used like: // // defer timer.Start().Stop() Start() interface { Stop() } // Record the duration of an event. Update(d time.Duration) // Record the duration of an event that started at a time and ends now. UpdateSince(t time.Time) // Tick the clock to update the moving average. Tick() }
Timers capture the duration and rate of events.
func NewCustomTimer ¶
Create a new timer with the given Histogram and Meter.