metrics

package
v0.0.0-...-9008a76 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DataDogMetricTypeRate = iota + 100

	DataDogDefaultRate float64 = 1
)

Custom metric types

View Source
const (
	MetricTypeMonotonicCounter = iota
	MetricTypeUpDownCounter
	MetricTypeHistogram
	MetricTypeDistribution

	MetricTypeInvalid
)

Type definitions for the different kind of metrics available.

View Source
const (
	PrometheusMetricTypeSummary = iota + 100
	PrometheusMetricTypeInvalid
)

Definitions of special metric types that can only be used with Prometheus.

View Source
const (
	// MetricTypeExtension is the minimum value for a custom metric type
	MetricTypeExtension = iota + 100
)

we allow to special types of metrics for specialized implementations ? :

Variables

This section is empty.

Functions

func Serve

func Serve(conf *PrometheusConfig)

Serve starts the server from where the metrics can be scraped

Types

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Catalog contains the list of defined metrics.

func (*Catalog) Def

func (mc *Catalog) Def(name string) (*Def, int)

Def returns a metric definition by its name.

type DataDogMeter

type DataDogMeter struct {
	// contains filtered or unexported fields
}

DataDogMeter is an implementation of metrics for DataDog

func (*DataDogMeter) Add

func (m *DataDogMeter) Add(key string, val float64)

Add adds an int value

func (*DataDogMeter) AddWL

func (m *DataDogMeter) AddWL(key string, val float64, labels map[string]string)

AddWL with labels that apply only to this record

func (*DataDogMeter) Dec

func (m *DataDogMeter) Dec(key string)

Dec decreases an integer value

func (*DataDogMeter) DecWL

func (m *DataDogMeter) DecWL(key string, labels map[string]string)

DecWL decreases an integer value adding labels to this record

func (*DataDogMeter) Inc

func (m *DataDogMeter) Inc(key string)

Inc increases an integer value

func (*DataDogMeter) IncWL

func (m *DataDogMeter) IncWL(key string, labels map[string]string)

IncWL increases and integer value adding labels to this records

func (*DataDogMeter) Rec

func (m *DataDogMeter) Rec(key string, val float64)

Rec records a value (similar to what a Gauge would be)

func (*DataDogMeter) RecWL

func (m *DataDogMeter) RecWL(key string, val float64, labels map[string]string)

RecWL with labels that apply only to this record

func (*DataDogMeter) Str

func (m *DataDogMeter) Str(key string, val string)

Str sets a label value for all metrics that have defined it

type DataDogMeterConfig

type DataDogMeterConfig struct {
	StatsDAddr  string
	MetricDefs  Defs
	DefaultRate float64
}

DataDogMeterConfig has the required configuration for a DataDotMeter

type Def

type Def struct {
	Name       string
	MetricType int
	Labels     []string
}

Def contains the information for a metric definition. It contains the name of the metric, the type, and the labels that can be applied to this metric.

type Defs

type Defs []Def

Defs defines a list of metric definitions.

func (Defs) Clean

func (md Defs) Clean(l logs.Logger) Catalog

Clean resets the MetricsCatalog leaving it empty.

func (Defs) Merge

func (md Defs) Merge(other Defs, override bool) Defs

Merge adds metrics definitions from another catalog, with option of overriding an existing one if the name of the matric already exists.

type Meter

type Meter interface {
	// Inc increases an integer value
	Inc(key string)
	// Dec decreases an integer value
	Dec(key string)
	// Add adds an int value
	Add(key string, val float64)
	// Rec records a value (similar to what a Gauge would be)
	Rec(key string, val float64)

	// Str sets a label value for all metrics that have defined it
	Str(key string, val string)

	// IncWL increases and integer value adding labels to this records
	IncWL(key string, labels map[string]string)
	// DecWL decreases an integer value adding labels to this record
	DecWL(key string, labels map[string]string)
	// AddWL with labels that apply only to this record
	AddWL(key string, val float64, labels map[string]string)
	// RecWL with labels that apply only to this record
	RecWL(key string, val float64, labels map[string]string)
}

Meter is the interface that abstracts the underlying metrics system. All counters used work on Float64 values

type MeterBuilderFn

type MeterBuilderFn func(log logs.Logger) Meter

MeterBuilderFn defines the type of a builder function for Meters

func NewDataDogMeterBuilder

func NewDataDogMeterBuilder(
	l logs.Logger, conf *DataDogMeterConfig) (MeterBuilderFn, error)

NewDataDogMeterBuilder creates a function to create new DataDogMeter's

func NewMockMeterBuilder

func NewMockMeterBuilder() (MeterBuilderFn, error)

NewMockMeterBuilder returns a function to create Mock meters.

func NewMultiMeterBuilder

func NewMultiMeterBuilder(log logs.Logger, builders ...MeterBuilderFn) (MeterBuilderFn, error)

NewMultiMeterBuilder crates a function to build NopMeters

func NewNopMeterBuilder

func NewNopMeterBuilder() (MeterBuilderFn, error)

NewNopMeterBuilder returns a func

func NewPrometheusMeterBuilder

func NewPrometheusMeterBuilder(
	log logs.Logger, conf *PrometheusConfig) (MeterBuilderFn, error)

NewPrometheusMeterBuilder creates a new prometheus function to create prometheus meters.

type MockMeter

type MockMeter struct {
	Incs     []string
	Decs     []string
	Recs     []string
	RecsVals []float64
	Adds     []string
	AddsVals []float64

	Strs map[string]string
}

MockMeter is an implementation of a meter used to check that we are sending

func NewMockMeter

func NewMockMeter() *MockMeter

NewMockMeter creates a new Mock meter.

func (*MockMeter) Add

func (m *MockMeter) Add(key string, val float64)

Add adds an int value

func (*MockMeter) AddWL

func (m *MockMeter) AddWL(key string, val float64, labels map[string]string)

AddWL with labels that apply only to this record

func (*MockMeter) Dec

func (m *MockMeter) Dec(key string)

Dec decreases an integer value

func (*MockMeter) DecWL

func (m *MockMeter) DecWL(key string, labels map[string]string)

DecWL decreases an integer value adding labels to this record

func (*MockMeter) Inc

func (m *MockMeter) Inc(key string)

Inc increases an integer value

func (*MockMeter) IncWL

func (m *MockMeter) IncWL(key string, labels map[string]string)

IncWL increases and integer value adding labels to this records

func (*MockMeter) Rec

func (m *MockMeter) Rec(key string, val float64)

Rec records a value (similar to what a Gauge would be)

func (*MockMeter) RecWL

func (m *MockMeter) RecWL(key string, val float64, labels map[string]string)

RecWL with labels that apply only to this record

func (*MockMeter) Str

func (m *MockMeter) Str(key string, val string)

Str sets a label value for all metrics that have defined it

type MultiMeter

type MultiMeter struct {
	// contains filtered or unexported fields
}

MultiMeter is a meter that allows to send metrics to several other meters.

func NewMultiMeter

func NewMultiMeter(wrapped ...Meter) *MultiMeter

NewMultiMeter creates a MultiMeter

func (*MultiMeter) Add

func (m *MultiMeter) Add(key string, val float64)

Add adds an int value

func (*MultiMeter) AddWL

func (m *MultiMeter) AddWL(key string, val float64, labels map[string]string)

AddWL with labels that apply only to this record

func (*MultiMeter) Dec

func (m *MultiMeter) Dec(key string)

Dec decreases an integer value

func (*MultiMeter) DecWL

func (m *MultiMeter) DecWL(key string, labels map[string]string)

DecWL decreases an integer value adding labels to this record

func (*MultiMeter) Inc

func (m *MultiMeter) Inc(key string)

Inc increases an integer value

func (*MultiMeter) IncWL

func (m *MultiMeter) IncWL(key string, labels map[string]string)

IncWL increases and integer value adding labels to this records

func (*MultiMeter) Rec

func (m *MultiMeter) Rec(key string, val float64)

Rec records a value (similar to what a Gauge would be)

func (*MultiMeter) RecWL

func (m *MultiMeter) RecWL(key string, val float64, labels map[string]string)

RecWL with labels that apply only to this record

func (*MultiMeter) Str

func (m *MultiMeter) Str(key string, val string)

Str sets a label value for all metrics that have defined it

type NopMeter

type NopMeter struct {
}

NopMeter is a meter that does nothing

func NewNopMeter

func NewNopMeter() *NopMeter

NewNopMeter creates a NopMeter

func (*NopMeter) Add

func (m *NopMeter) Add(key string, val float64)

Add adds an int value

func (*NopMeter) AddWL

func (m *NopMeter) AddWL(key string, val float64, labels map[string]string)

AddWL with labels that apply only to this record

func (*NopMeter) Dec

func (m *NopMeter) Dec(key string)

Dec decreases an integer value

func (*NopMeter) DecWL

func (m *NopMeter) DecWL(key string, labels map[string]string)

DecWL decreases an integer value adding labels to this record

func (*NopMeter) Inc

func (m *NopMeter) Inc(key string)

Inc increases an integer value

func (*NopMeter) IncWL

func (m *NopMeter) IncWL(key string, labels map[string]string)

IncWL increases and integer value adding labels to this records

func (*NopMeter) Rec

func (m *NopMeter) Rec(key string, val float64)

Rec records a value (similar to what a Gauge would be)

func (*NopMeter) RecWL

func (m *NopMeter) RecWL(key string, val float64, labels map[string]string)

RecWL with labels that apply only to this record

func (*NopMeter) Str

func (m *NopMeter) Str(key string, val string)

Str sets a label value for all metrics that have defined it

type PrometheusConfig

type PrometheusConfig struct {
	ServerPort string // in the ":7323" form
	ServerPath string // path to serve the metrics

	MetricDefinitions Defs
	MetricsPrefix     string
}

PrometheusConfig is the configuration for creating a Prometheus Meter.

type PrometheusMeter

type PrometheusMeter struct {
	// contains filtered or unexported fields
}

PrometheusMeter is the implementation of a Prometheus Meter

func NewPrometheusMeter

func NewPrometheusMeter(log logs.Logger, promMetrics *prometheusMetrics) *PrometheusMeter

NewPrometheusMeter creates a new prometheus meter

func (*PrometheusMeter) Add

func (pm *PrometheusMeter) Add(key string, val float64)

Add adds an int value

func (*PrometheusMeter) AddWL

func (pm *PrometheusMeter) AddWL(key string, val float64, labels map[string]string)

AddWL with labels that apply only to this record

func (*PrometheusMeter) Dec

func (pm *PrometheusMeter) Dec(key string)

Dec decreases an integer value

func (*PrometheusMeter) DecWL

func (pm *PrometheusMeter) DecWL(key string, labels map[string]string)

DecWL decreases an integer value adding labels to this record

func (*PrometheusMeter) Inc

func (pm *PrometheusMeter) Inc(key string)

Inc increases an integer value

func (*PrometheusMeter) IncWL

func (pm *PrometheusMeter) IncWL(key string, labels map[string]string)

IncWL increases and integer value adding labels to this records

func (*PrometheusMeter) Rec

func (pm *PrometheusMeter) Rec(key string, val float64)

Rec records a value (similar to what a Gauge would be)

func (*PrometheusMeter) RecWL

func (pm *PrometheusMeter) RecWL(key string, val float64, labels map[string]string)

RecWL with labels that apply only to this record

func (*PrometheusMeter) Str

func (pm *PrometheusMeter) Str(key string, val string)

Str sets a label value for all metrics that have defined it

Jump to

Keyboard shortcuts

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