dynamicvector

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2018 License: MIT Imports: 8 Imported by: 0

README

dynamicvector

go-doc CircleCI codecov

prometheus golang dynamic vector

Documentation

Overview

Package dynamicvector give flexibility to add any number of labels into prometheus Vector. It also give a feature to expire old metrics that never been updated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter struct {
	*Vector
}

Counter is a counter dynamicvector

func NewCounter

func NewCounter(opts CounterOpts) *Counter

NewCounter will return a new dynamicvector counter.

func (*Counter) GetMetricWith

func (c *Counter) GetMetricWith(labels prometheus.Labels) (prometheus.Counter, error)

With is a syntatic sugar for Vector.GetMetricWith

func (*Counter) With

func (c *Counter) With(labels prometheus.Labels) prometheus.Counter

With is a syntatic sugar for Vector.With

type CounterOpts

type CounterOpts = Opts

CounterOpts is an alias for Opts

type CounterUnit

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

CounterUnit implement prometheus.Counter and Metric

func (*CounterUnit) Add

func (u *CounterUnit) Add(val float64)

Add implement prometheus.Counter

func (*CounterUnit) Collect

func (u *CounterUnit) Collect(ch chan<- prometheus.Metric)

Collect implement prometheus.Counter (prometheus.Collector)

func (*CounterUnit) Desc

func (u *CounterUnit) Desc() *prometheus.Desc

Desc implement prometheus.Counter (prometheus.Metric)

func (*CounterUnit) Describe

func (u *CounterUnit) Describe(ch chan<- *prometheus.Desc)

Describe implement prometheus.Counter (prometheus.Collector)

func (*CounterUnit) Inc

func (u *CounterUnit) Inc()

Inc implement prometheus.Counter

func (*CounterUnit) LastEdit

func (u *CounterUnit) LastEdit() time.Time

LastEdit implement Metric

func (*CounterUnit) Write

func (u *CounterUnit) Write(metric *dto.Metric) error

Write implement prometheus.Counter (prometheus.Metric)

type GCStat

type GCStat struct {
	// Number of deleted metrics
	Deleted int

	// Whether metric exceed limit or not.
	LimitExceeded bool
}

GCStat is status for garbage collector.

type Gauge

type Gauge struct {
	*Vector
}

Gauge is a gauge dynamicvector

func NewGauge

func NewGauge(opts GaugeOpts) *Gauge

NewGauge will return a new dynamicvector gauge.

func (*Gauge) GetMetricWith

func (g *Gauge) GetMetricWith(labels prometheus.Labels) (prometheus.Gauge, error)

With is a syntatic sugar for Vector.GetMetricWith

func (*Gauge) With

func (g *Gauge) With(labels prometheus.Labels) prometheus.Gauge

With is a syntatic sugar for Vector.With(labels).(prometheus.Gauge)

type GaugeOpts

type GaugeOpts = Opts

GaugeOpts is an alias for Opts

type GaugeUnit

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

GaugeUnit implement prometheus.Gauge and Metric

func (*GaugeUnit) Add

func (u *GaugeUnit) Add(v float64)

Add implement prometheus.Gauge

func (*GaugeUnit) Collect

func (u *GaugeUnit) Collect(ch chan<- prometheus.Metric)

Collect implement prometheus.Gauge (prometheus.Collector)

func (*GaugeUnit) Dec

func (u *GaugeUnit) Dec()

Dec implement prometheus.Gauge

func (*GaugeUnit) Desc

func (u *GaugeUnit) Desc() *prometheus.Desc

Desc implement prometheus.Gauge (prometheus.Metric)

func (*GaugeUnit) Describe

func (u *GaugeUnit) Describe(ch chan<- *prometheus.Desc)

Describe implement prometheus.Gauge (prometheus.Collector)

func (*GaugeUnit) Inc

func (u *GaugeUnit) Inc()

Inc implement prometheus.Gauge

func (*GaugeUnit) LastEdit

func (u *GaugeUnit) LastEdit() time.Time

LastEdit implement Metric

func (*GaugeUnit) Set

func (u *GaugeUnit) Set(v float64)

Set implement prometheus.Gauge

func (*GaugeUnit) SetToCurrentTime

func (u *GaugeUnit) SetToCurrentTime()

SetToCurrentTime implement prometheus.Gauge

func (*GaugeUnit) Sub

func (u *GaugeUnit) Sub(v float64)

Sub implement prometheus.Gauge

func (*GaugeUnit) Write

func (u *GaugeUnit) Write(metric *dto.Metric) error

Write implement prometheus.Gauge (prometheus.Metric)

type Histogram

type Histogram struct {
	*Vector
}

Histogram is a histogram dynamicvector

func NewHistogram

func NewHistogram(opts HistogramOpts) *Histogram

NewHistogram will return a new dynamicvector histogram.

func (*Histogram) GetMetricWith

func (h *Histogram) GetMetricWith(labels prometheus.Labels) (prometheus.Histogram, error)

With is a syntatic sugar for Vector.GetMetricWith

func (*Histogram) With

With is a syntatic sugar for Vector.With(labels).(prometheus.Histogram)

type HistogramOpts

type HistogramOpts = Opts

HistogramOpts is an alias for Opts

type HistogramUnit

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

func (*HistogramUnit) Collect

func (u *HistogramUnit) Collect(ch chan<- prometheus.Metric)

func (*HistogramUnit) Desc

func (u *HistogramUnit) Desc() *prometheus.Desc

func (*HistogramUnit) Describe

func (u *HistogramUnit) Describe(ch chan<- *prometheus.Desc)

func (*HistogramUnit) LastEdit

func (u *HistogramUnit) LastEdit() time.Time

func (*HistogramUnit) Observe

func (u *HistogramUnit) Observe(v float64)

func (*HistogramUnit) Write

func (u *HistogramUnit) Write(metric *dto.Metric) error

type Labels

type Labels struct {
	// Constant is constant label.
	Constant prometheus.Labels

	// Keys is label keys.
	Keys []string
	// contains filtered or unexported fields
}

Labels represent structure data for Metric. It designed to be used internally for dynamicvector.

func NewLabels

func NewLabels(constantLabels prometheus.Labels) *Labels

NewLabels will create new Labels with initial constant.

func (*Labels) Hash

func (l *Labels) Hash(label prometheus.Labels) uint64

Hash will return hash value from labels.

func (*Labels) Include

func (l *Labels) Include(lbl prometheus.Labels) bool

Include will check whether lbl is subset of Labels or not.

func (*Labels) PromLabelsToValues

func (l *Labels) PromLabelsToValues(lbl prometheus.Labels) []string

PromLabelsToValues will generate label values from prometheus labels. If there is label key that has not registered to Labels yet, it will be added.

func (*Labels) ValuesToPromLabels

func (l *Labels) ValuesToPromLabels(values []string) prometheus.Labels

ValuesToPromLabels will generate prometheus.Labels given label values and constant labels.

type Metric

type Metric interface {
	prometheus.Metric

	// LastEdit return last time metric is edited
	LastEdit() time.Time
}

Metric is an interface that encapsulate prometheus.Metric interface

func NewCounterUnit

func NewCounterUnit(vec *Vector, labelValues []string) Metric

NewCounterUnit will create new counter with specified label values.

func NewGaugeUnit

func NewGaugeUnit(vec *Vector, labelValues []string) Metric

NewGaugeUnit will create new counter with specified label values.

func NewHistogramUnit

func NewHistogramUnit(vec *Vector, labelValues []string) Metric

NewHistogramUnit will create new hitogram with specified label values.

type Opts

type Opts struct {
	// Namespace, Subsystem, and Name are components of the fully-qualified
	// name of the Metric (created by joining these components with
	// "_"). Only Name is mandatory.
	Namespace string
	Subsystem string
	Name      string

	// Help provides information about this metric. Mandatory!
	Help string

	// ConstLabels are used to attach fixed labels to this metric.
	ConstLabels prometheus.Labels

	// Buckets defines the buckets into which observations are counted. Only for Histogram.
	Buckets []float64

	// Expire are used to set how long dynamicvector will keep the metrics. Zero
	// mean never expire.
	Expire time.Duration

	// MaxLength is maximum length that this vector is allowed to have. Zero mean no maximum length.
	MaxLength int
}

Opts is an option for creating metric vector.

type Vector

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

Vector is a dynamicvector that used to keep metrics.

func NewVector

func NewVector(opts Opts, cons func(v *Vector, labelValues []string) Metric) *Vector

NewVector will create new vector with specified option and metric constructor.

func (*Vector) Collect

func (v *Vector) Collect(ch chan<- prometheus.Metric)

Collect implement prometheus.Collector.

func (*Vector) Delete

func (v *Vector) Delete(l prometheus.Labels) bool

Delete will delete metric that have exact match labels from vector.

func (*Vector) Describe

func (v *Vector) Describe(ch chan<- *prometheus.Desc)

Describe implement prometheus.Collector.

func (*Vector) GC

func (v *Vector) GC() GCStat

GC will do housekeeping work related to this metrics and return number of metrics that is deleted. Currently there are two things that this method do. First, delete all expired metrics. Second, delete all metrics for vector that exceed MaxLength.

func (*Vector) GetMetricWith

func (v *Vector) GetMetricWith(labels prometheus.Labels) (prometheus.Metric, error)

GetMetricWith returns the Metric for the given Labels map (the label names must match those of the VariableLabels in Desc). If that label map is accessed for the first time, a new Metric is created. Return error if maxLen is exceeded.

func (*Vector) Length

func (v *Vector) Length() int

Length will return number of metrics in this vector.

func (*Vector) Reset

func (v *Vector) Reset()

Reset will delete all metrics in vector.

func (*Vector) With

With behave like GetMetricWith except it will panic instead when there is an error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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