metric

package
v0.0.0-...-86cadae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 4 Imported by: 0

README

Metric

Metrics are stored by the handlers and processors to allow the user to know how the proccessing is going and to detect errors.

Metrics are handled by a interface called Provider that each Processor has assigned.
The default is Prometheusprovider.

Provider is a short interface

//Provider is a interface that is used to handle Different metric sources
type Provider interface {
	AddMetric(*Metric) error
	IncrementMetric(name string, value float64) error
	GetMetrics() map[string]*Metric
	GetMetric(name string) *Metric
}

PrometheusProvider

Prometheusprovider is the default metric and is applied to all Handlers and processors unless changed.

To view the metrics, one needs to run

	http.Handle("/metrics", promhttp.Handler())
	http.ListenAndServe(fmt.Sprintf(":%d", port), nil)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrMetricAlreadyExist is when trying to add a new metric but it collides with another named metric
	ErrMetricAlreadyExist = errors.New("trying to add a metric that already exists, instead try to increment it")
	// ErrMetricNotFound is when trying to increment a nonfound metric
	ErrMetricNotFound = errors.New("trying to increment a missing metric")
)

Functions

This section is empty.

Types

type Metric

type Metric struct {
	Description string  `json:"description" yaml:"description"`
	Name        string  `json:"name" yaml:"name"`
	Value       float64 `json:"value" yaml:"value"`
}

Metric is information about a certain value of a processor with a name and description, currently all metric is int64, would be cool with interface, but I cant think of a reason

type PrometheusProvider

type PrometheusProvider struct {
	Metrics map[string]*Metric `json:"metrics"`
	// PromMetric is actually just a mirror of Metrics, its used to export the metric
	// The reaason why we contain our own Metric aswell is because it seems hard to extract values from Prom package
	PromMetrics map[string]prometheus.Counter `json:"-"`
	sync.Mutex
}

PrometheusProvider is a simple Provider for Prom metric for now only support Float64, maybe add more in the future

func NewPrometheusProvider

func NewPrometheusProvider() *PrometheusProvider

NewPrometheusProvider will generate a new metrics holder

func (*PrometheusProvider) AddMetric

func (pp *PrometheusProvider) AddMetric(m *Metric) error

AddMetric is used to add new metrics, or append to old metric

func (*PrometheusProvider) GetMetric

func (pp *PrometheusProvider) GetMetric(name string) *Metric

GetMetric will return a metric if it exists, or nil if not

func (*PrometheusProvider) GetMetrics

func (pp *PrometheusProvider) GetMetrics() map[string]*Metric

GetMetrics is used to extract all metrics

func (*PrometheusProvider) IncrementMetric

func (pp *PrometheusProvider) IncrementMetric(name string, value float64) error

IncrementMetric is used to increase value of metric

type Provider

type Provider interface {
	AddMetric(*Metric) error
	IncrementMetric(name string, value float64) error
	GetMetrics() map[string]*Metric
	GetMetric(name string) *Metric
}

Provider is a interface that is used to handle Different metric sources

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL