Documentation ¶
Index ¶
- Variables
- func AddEngine(eng MetricsEngine) error
- func Handler() http.Handler
- func Hotload(name string) error
- type Counter
- type Gauge
- type GroupCounter
- type GroupGauge
- type GroupObserver
- type GroupTagCounter
- type GroupTagGauge
- type GroupTagHistogram
- type HistogramBucketOptions
- type HistogramOptions
- type Metrics
- func (m *Metrics) AddEngine(eng MetricsEngine) error
- func (m *Metrics) Handler() http.Handler
- func (m *Metrics) Hotload(name string) error
- func (m *Metrics) MustNewCounterWithTags(opts Options) *GroupTagCounter
- func (m *Metrics) MustNewGaugeWithTags(opts Options) *GroupTagGauge
- func (m *Metrics) MustNewHistogramWithTags(opts HistogramOptions) *GroupTagHistogram
- func (m *Metrics) NewCounterWithTags(opts Options) (*GroupTagCounter, error)
- func (m *Metrics) NewGaugeWithTags(opts Options) (*GroupTagGauge, error)
- func (m *Metrics) NewHistogramWithTags(opts HistogramOptions) (*GroupTagHistogram, error)
- type MetricsEngine
- type MetricsHandler
- type Observer
- type Options
- type TagCounter
- type TagGauge
- type TagObserver
- type Timer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultMetrics is the generic metrics aggregator // needed for global variables so we can attach new metrics // before the engine (like prometheus) is linked DefaultMetrics *Metrics // Debug flag Debug bool )
Functions ¶
func AddEngine ¶
func AddEngine(eng MetricsEngine) error
AddEngine adds new engine to DefaultMetrics
Types ¶
type Counter ¶
type Counter interface { Inc() Add(float64) }
Counter is an interface that generalizes a group of metrics that are calculate the number over time
type Gauge ¶
Gauge is an interface that generalizes a group of metrics that are used to report a curent level/number
type GroupCounter ¶
type GroupCounter struct {
// contains filtered or unexported fields
}
GroupCounter is a set of Counters that within the same tags
func (*GroupCounter) AddCounter ¶
func (gc *GroupCounter) AddCounter(c Counter)
AddCounter adds counter
type GroupGauge ¶
type GroupGauge struct {
// contains filtered or unexported fields
}
GroupGauge is a set of Gauges that within the same tags
type GroupObserver ¶
type GroupObserver struct {
// contains filtered or unexported fields
}
GroupObserver is a set of Observers that within the same tags
func (*GroupObserver) AddObserver ¶
func (g *GroupObserver) AddObserver(o Observer)
AddObserver adds observer
func (*GroupObserver) Observe ¶
func (g *GroupObserver) Observe(f float64)
Observe calls the metrics ultimately
type GroupTagCounter ¶
type GroupTagCounter struct {
// contains filtered or unexported fields
}
GroupTagCounter a group of different Counters from different metric systems
func MustNewCounterWithTags ¶
func MustNewCounterWithTags(opts Options) *GroupTagCounter
MustNewCounterWithTags constructor with embedded panic
func NewCounterWithTags ¶
func NewCounterWithTags(opts Options) (*GroupTagCounter, error)
NewCounterWithTags is Counter constructor for DefaultMetrics global
func (*GroupTagCounter) AddCounter ¶
func (gtc *GroupTagCounter) AddCounter(c TagCounter)
AddCounter is appending new counter to set
func (*GroupTagCounter) WithLabels ¶
func (gtc *GroupTagCounter) WithLabels(labels ...string) *GroupCounter
WithLabels make a group with given labels
func (*GroupTagCounter) WithTags ¶
func (gtc *GroupTagCounter) WithTags(tags map[string]string) (*GroupCounter, error)
WithTags makes a group with given tags (label-value pairs)
type GroupTagGauge ¶
type GroupTagGauge struct {
// contains filtered or unexported fields
}
GroupTagGauge a group of different Gauges from different metric systems
func MustNewGaugeWithTags ¶
func MustNewGaugeWithTags(opts Options) *GroupTagGauge
MustNewGaugeWithTags gauge constructor with embedded error
func NewGaugeWithTags ¶
func NewGaugeWithTags(opts Options) (*GroupTagGauge, error)
NewGaugeWithTags gauge type constructor
func (*GroupTagGauge) AddGauge ¶
func (gtg *GroupTagGauge) AddGauge(g TagGauge)
AddGauge is appending new gauge to set
func (*GroupTagGauge) WithLabels ¶
func (gtg *GroupTagGauge) WithLabels(labels ...string) *GroupGauge
WithLabels makes a group with given labels
func (*GroupTagGauge) WithTags ¶
func (gtg *GroupTagGauge) WithTags(tags map[string]string) (*GroupGauge, error)
WithTags makes a group with given tags (label-value pairs)
type GroupTagHistogram ¶
type GroupTagHistogram struct {
// contains filtered or unexported fields
}
GroupTagHistogram a group of different Histograms from different metric systems
func MustNewHistogramWithTags ¶
func MustNewHistogramWithTags(opts HistogramOptions) *GroupTagHistogram
MustNewHistogramWithTags constructor with embedded panic
func NewHistogramWithTags ¶
func NewHistogramWithTags(opts HistogramOptions) (*GroupTagHistogram, error)
NewHistogramWithTags Histogram constructor for DefaultMetrics global
func (*GroupTagHistogram) AddHistogram ¶
func (gth *GroupTagHistogram) AddHistogram(o TagObserver)
AddHistogram is appending new histogram to set
func (*GroupTagHistogram) WithLabels ¶
func (gth *GroupTagHistogram) WithLabels(labels ...string) *GroupObserver
WithLabels make a group with given labels
func (*GroupTagHistogram) WithTags ¶
func (gth *GroupTagHistogram) WithTags(tags map[string]string) (*GroupObserver, error)
WithTags makes a group with given tags (label-value pairs)
type HistogramBucketOptions ¶
HistogramBucketOptions an options to fine-tune histogram buckets
type HistogramOptions ¶
type HistogramOptions struct { Namespace string Subsystem string Name string Desc string Tags []string Buckets HistogramBucketOptions }
HistogramOptions a set of options for histogram metric
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics a structure that group all the defined metrics
func (*Metrics) AddEngine ¶
func (m *Metrics) AddEngine(eng MetricsEngine) error
AddEngine adds new engine (like prometheus) to run
func (*Metrics) MustNewCounterWithTags ¶
func (m *Metrics) MustNewCounterWithTags(opts Options) *GroupTagCounter
MustNewCounterWithTags constructor with panic on error embedded
func (*Metrics) MustNewGaugeWithTags ¶
func (m *Metrics) MustNewGaugeWithTags(opts Options) *GroupTagGauge
MustNewGaugeWithTags constructor with panic on error embedded
func (*Metrics) MustNewHistogramWithTags ¶
func (m *Metrics) MustNewHistogramWithTags(opts HistogramOptions) *GroupTagHistogram
MustNewHistogramWithTags constructor with panic on error embedded
func (*Metrics) NewCounterWithTags ¶
func (m *Metrics) NewCounterWithTags(opts Options) (*GroupTagCounter, error)
NewCounterWithTags create a group of counters from defined engines
Example ¶
package main import ( "expvar" "log" "net/http" "strings" "github.com/figment-networks/indexing-engine/metrics" ) // Dummy test engine implementation type MetricsEngineTest struct { } func (m *MetricsEngineTest) Name() string { return "MetricsEngineTest" } func (m *MetricsEngineTest) NewCounterWithTags(opts metrics.Options) (metrics.TagCounter, error) { return NewMetricElementTestCouter(opts), nil } func (m *MetricsEngineTest) NewGaugeWithTags(opts metrics.Options) (metrics.TagGauge, error) { return nil, nil // NOOP } func (m *MetricsEngineTest) NewHistogramWithTags(opts metrics.HistogramOptions) (metrics.TagObserver, error) { return nil, nil // NOOP } func (m *MetricsEngineTest) Handler() http.Handler { return nil } type MetricElementTestCouter struct { metric *MyCounter } func NewMetricElementTestCouter(opts metrics.Options) *MetricElementTestCouter { return &MetricElementTestCouter{ metric: &MyCounter{ expvar.NewInt(strings.Join([]string{opts.Namespace, opts.Subsystem, opts.Name}, "_")), }, } } func (me *MetricElementTestCouter) WithTags(map[string]string) (metrics.Counter, error) { // (lukanus): discard tags for the sake of simple example return me.metric, nil } func (me *MetricElementTestCouter) WithLabels(...string) metrics.Counter { // (lukanus): discard tags for the sake of simple example return me.metric } type MyCounter struct { metric *expvar.Int } func (mc MyCounter) Inc() { mc.metric.Add(1) } func (mc MyCounter) Add(a float64) { mc.metric.Add(int64(a)) } func main() { // Add metrics engine of yout choice metrics global me := &MetricsEngineTest{} err := metrics.AddEngine(me) if err != nil { log.Fatal(err) } // If needed link predeclared values err = metrics.Hotload(me.Name()) if err != nil { log.Fatal(err) } // Create counter in all registred engines counter, err := metrics.NewCounterWithTags(metrics.Options{Namespace: "my", Subsystem: "test", Name: "metric"}) // Use counter counter.WithLabels().Add(1) }
Output:
func (*Metrics) NewGaugeWithTags ¶
func (m *Metrics) NewGaugeWithTags(opts Options) (*GroupTagGauge, error)
NewGaugeWithTags create a group of gauges from defined engines
func (*Metrics) NewHistogramWithTags ¶
func (m *Metrics) NewHistogramWithTags(opts HistogramOptions) (*GroupTagHistogram, error)
NewHistogramWithTags create a group of histograms from defined engines
type MetricsEngine ¶
type MetricsEngine interface { Name() string NewCounterWithTags(opts Options) (TagCounter, error) NewGaugeWithTags(opts Options) (TagGauge, error) NewHistogramWithTags(opts HistogramOptions) (TagObserver, error) Handler() http.Handler }
MetricsEngine is an interface for metric engines
type MetricsHandler ¶
type MetricsHandler struct {
// contains filtered or unexported fields
}
MetricsHandler a way to merge http handlers
func (MetricsHandler) ServeHTTP ¶
func (mh MetricsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP fulfills http.Handler interface
type Observer ¶
type Observer interface {
Observe(float64)
}
Observer is an interface that generalizes a group of metrics that are receiving a set of numeric values in time
type TagCounter ¶
type TagCounter interface { WithTags(map[string]string) (Counter, error) WithLabels(...string) Counter }
TagCounter interface for appending tags to metrics
type TagObserver ¶
type TagObserver interface { WithTags(map[string]string) (Observer, error) WithLabels(...string) Observer }
TagObserver interface for appending tags to metrics
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer This one is taken from prometheus impementation to get rid out of dependancy
func (*Timer) ObserveDuration ¶
ObserveDuration is commiting time duration that passed from it's creation