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 ¶
- type Counter
- type CounterOpts
- type CounterUnit
- func (u *CounterUnit) Add(val float64)
- func (u *CounterUnit) Collect(ch chan<- prometheus.Metric)
- func (u *CounterUnit) Desc() *prometheus.Desc
- func (u *CounterUnit) Describe(ch chan<- *prometheus.Desc)
- func (u *CounterUnit) Inc()
- func (u *CounterUnit) LastEdit() time.Time
- func (u *CounterUnit) Write(metric *dto.Metric) error
- type GCStat
- type Gauge
- type GaugeOpts
- type GaugeUnit
- func (u *GaugeUnit) Add(v float64)
- func (u *GaugeUnit) Collect(ch chan<- prometheus.Metric)
- func (u *GaugeUnit) Dec()
- func (u *GaugeUnit) Desc() *prometheus.Desc
- func (u *GaugeUnit) Describe(ch chan<- *prometheus.Desc)
- func (u *GaugeUnit) Inc()
- func (u *GaugeUnit) LastEdit() time.Time
- func (u *GaugeUnit) Set(v float64)
- func (u *GaugeUnit) SetToCurrentTime()
- func (u *GaugeUnit) Sub(v float64)
- func (u *GaugeUnit) Write(metric *dto.Metric) error
- type Histogram
- type HistogramOpts
- type HistogramUnit
- func (u *HistogramUnit) Collect(ch chan<- prometheus.Metric)
- func (u *HistogramUnit) Desc() *prometheus.Desc
- func (u *HistogramUnit) Describe(ch chan<- *prometheus.Desc)
- func (u *HistogramUnit) LastEdit() time.Time
- func (u *HistogramUnit) Observe(v float64)
- func (u *HistogramUnit) Write(metric *dto.Metric) error
- type Labels
- type Metric
- type Opts
- type Vector
- func (v *Vector) Collect(ch chan<- prometheus.Metric)
- func (v *Vector) Delete(l prometheus.Labels) bool
- func (v *Vector) Describe(ch chan<- *prometheus.Desc)
- func (v *Vector) GC() GCStat
- func (v *Vector) GetMetricWith(labels prometheus.Labels) (prometheus.Metric, error)
- func (v *Vector) Length() int
- func (v *Vector) Reset()
- func (v *Vector) With(l prometheus.Labels) prometheus.Metric
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 CounterUnit ¶
type CounterUnit struct {
// contains filtered or unexported fields
}
CounterUnit implement prometheus.Counter and Metric
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)
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 (*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 GaugeUnit ¶
type GaugeUnit struct {
// contains filtered or unexported fields
}
GaugeUnit implement prometheus.Gauge and Metric
func (*GaugeUnit) Collect ¶
func (u *GaugeUnit) Collect(ch chan<- prometheus.Metric)
Collect implement prometheus.Gauge (prometheus.Collector)
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) SetToCurrentTime ¶
func (u *GaugeUnit) SetToCurrentTime()
SetToCurrentTime implement prometheus.Gauge
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 ¶
func (h *Histogram) With(labels prometheus.Labels) prometheus.Histogram
With is a syntatic sugar for Vector.With(labels).(prometheus.Histogram)
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)
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 ¶
NewCounterUnit will create new counter with specified label values.
func NewGaugeUnit ¶
NewGaugeUnit will create new counter with specified label values.
func NewHistogramUnit ¶
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 (*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 ¶
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) With ¶
func (v *Vector) With(l prometheus.Labels) prometheus.Metric
With behave like GetMetricWith except it will panic instead when there is an error.