component-base: k8s.io/component-base/metrics Index | Files | Directories

package metrics

import "k8s.io/component-base/metrics"

Index

Package Files

collector.go counter.go desc.go gauge.go histogram.go http.go labels.go metric.go opts.go processstarttime.go registry.go summary.go value.go version.go version_parser.go wrappers.go

Constants

const (
    // Serve an HTTP status code 500 upon the first error
    // encountered. Report the error message in the body.
    HTTPErrorOnError promhttp.HandlerErrorHandling = iota

    // Ignore errors and try to serve as many metrics as possible.  However,
    // if no metrics can be served, serve an HTTP status code 500 and the
    // last error message in the body. Only use this in deliberate "best
    // effort" metrics collection scenarios. In this case, it is highly
    // recommended to provide other means of detecting errors: By setting an
    // ErrorLog in HandlerOpts, the errors are logged. By providing a
    // Registry in HandlerOpts, the exposed metrics include an error counter
    // "promhttp_metric_handler_errors_total", which can be used for
    // alerts.
    ContinueOnError

    // Panic upon the first error encountered (useful for "crash only" apps).
    PanicOnError
)

These constants cause handlers serving metrics to behave as described if errors are encountered.

Variables

var DefBuckets = prometheus.DefBuckets

DefBuckets is a wrapper for prometheus.DefBuckets

func BuildFQName Uses

func BuildFQName(namespace, subsystem, name string) string

BuildFQName joins the given three name components by "_". Empty name components are ignored. If the name parameter itself is empty, an empty string is returned, no matter what. Metric implementations included in this library use this function internally to generate the fully-qualified metric name from the name component in their Opts. Users of the library will only need this function if they implement their own Metric or instantiate a Desc (with NewDesc) directly.

func ExponentialBuckets Uses

func ExponentialBuckets(start, factor float64, count int) []float64

ExponentialBuckets is a wrapper for prometheus.ExponentialBuckets.

func HandlerFor Uses

func HandlerFor(reg Gatherer, opts HandlerOpts) http.Handler

HandlerFor returns an uninstrumented http.Handler for the provided Gatherer. The behavior of the Handler is defined by the provided HandlerOpts. Thus, HandlerFor is useful to create http.Handlers for custom Gatherers, with non-default HandlerOpts, and/or with custom (or no) instrumentation. Use the InstrumentMetricHandler function to apply the same kind of instrumentation as it is used by the Handler function.

func LinearBuckets Uses

func LinearBuckets(start, width float64, count int) []float64

LinearBuckets is a wrapper for prometheus.LinearBuckets.

func RegisterBuildInfo Uses

func RegisterBuildInfo(r KubeRegistry)

RegisterBuildInfo registers the build and version info in a metadata metric in prometheus

func RegisterProcessStartTime Uses

func RegisterProcessStartTime(registrationFunc func(Registerable) error) error

RegisterProcessStartTime registers the process_start_time_seconds to a prometheus registry. This metric needs to be included to ensure counter data fidelity.

func SetShowHidden Uses

func SetShowHidden()

SetShowHidden will enable showing hidden metrics. This will no-opt after the initial call

func ShouldShowHidden Uses

func ShouldShowHidden() bool

ShouldShowHidden returns whether showing hidden deprecated metrics is enabled. While the primary usecase for this is internal (to determine registration behavior) this can also be used to introspect

func ValidateShowHiddenMetricsVersion Uses

func ValidateShowHiddenMetricsVersion(v string) []error

ValidateShowHiddenMetricsVersion checks invalid version for which show hidden metrics.

type BaseStableCollector Uses

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

BaseStableCollector which implements almost all of the methods defined by StableCollector is a convenient assistant for custom collectors. It is recommend that inherit BaseStableCollector when implementing custom collectors.

func (*BaseStableCollector) ClearState Uses

func (bsc *BaseStableCollector) ClearState()

ClearState will clear all the states marked by Create. It intends to be used for re-register a hidden metric.

func (*BaseStableCollector) Collect Uses

func (bsc *BaseStableCollector) Collect(ch chan<- prometheus.Metric)

Collect is called by the Prometheus registry when collecting metrics.

func (*BaseStableCollector) CollectWithStability Uses

func (bsc *BaseStableCollector) CollectWithStability(ch chan<- Metric)

CollectWithStability sends all metrics to the provided channel. Every custom collector should over-write this method.

func (*BaseStableCollector) Create Uses

func (bsc *BaseStableCollector) Create(version *semver.Version, self StableCollector) bool

Create intends to be called by registry. Create will return true as long as there is one or more metrics not be hidden. Otherwise return false, that means the whole collector will be ignored by registry.

func (*BaseStableCollector) Describe Uses

func (bsc *BaseStableCollector) Describe(ch chan<- *prometheus.Desc)

Describe sends all descriptors to the provided channel. It intend to be called by prometheus registry.

func (*BaseStableCollector) DescribeWithStability Uses

func (bsc *BaseStableCollector) DescribeWithStability(ch chan<- *Desc)

DescribeWithStability sends all descriptors to the provided channel. Every custom collector should over-write this method.

func (*BaseStableCollector) HiddenMetrics Uses

func (bsc *BaseStableCollector) HiddenMetrics() (fqNames []string)

HiddenMetrics tells the list of hidden metrics with fqName.

type Collector Uses

type Collector interface {
    Describe(chan<- *prometheus.Desc)
    Collect(chan<- prometheus.Metric)
}

Collector defines a subset of prometheus.Collector interface methods

type Counter Uses

type Counter struct {
    CounterMetric
    *CounterOpts
    // contains filtered or unexported fields
}

Counter is our internal representation for our wrapping struct around prometheus counters. Counter implements both kubeCollector and CounterMetric.

func NewCounter Uses

func NewCounter(opts *CounterOpts) *Counter

NewCounter returns an object which satisfies the kubeCollector and CounterMetric interfaces. However, the object returned will not measure anything unless the collector is first registered, since the metric is lazily instantiated.

func (*Counter) ClearState Uses

func (r *Counter) ClearState()

ClearState will clear all the states marked by Create. It intends to be used for re-register a hidden metric.

func (*Counter) Collect Uses

func (c *Counter) Collect(ch chan<- prometheus.Metric)

func (*Counter) Create Uses

func (r *Counter) Create(version *semver.Version) bool

Create forces the initialization of metric which has been deferred until the point at which this method is invoked. This method will determine whether the metric is deprecated or hidden, no-opting if the metric should be considered hidden. Furthermore, this function no-opts and returns true if metric is already created.

func (*Counter) DeprecatedVersion Uses

func (c *Counter) DeprecatedVersion() *semver.Version

DeprecatedVersion returns a pointer to the Version or nil

func (*Counter) Describe Uses

func (c *Counter) Describe(ch chan<- *prometheus.Desc)

func (*Counter) FQName Uses

func (r *Counter) FQName() string

FQName returns the fully-qualified metric name of the collector.

func (*Counter) IsCreated Uses

func (r *Counter) IsCreated() bool

func (*Counter) IsDeprecated Uses

func (r *Counter) IsDeprecated() bool

func (*Counter) IsHidden Uses

func (r *Counter) IsHidden() bool

type CounterMetric Uses

type CounterMetric interface {
    Inc()
    Add(float64)
}

CounterMetric is an interface which defines a subset of the interface provided by prometheus.Counter

type CounterOpts Uses

type CounterOpts KubeOpts

CounterOpts is an alias for Opts. See there for doc comments.

type CounterVec Uses

type CounterVec struct {
    *prometheus.CounterVec
    *CounterOpts
    // contains filtered or unexported fields
}

CounterVec is the internal representation of our wrapping struct around prometheus counterVecs. CounterVec implements both kubeCollector and CounterVecMetric.

func NewCounterVec Uses

func NewCounterVec(opts *CounterOpts, labels []string) *CounterVec

NewCounterVec returns an object which satisfies the kubeCollector and CounterVecMetric interfaces. However, the object returned will not measure anything unless the collector is first registered, since the metric is lazily instantiated.

func (*CounterVec) ClearState Uses

func (r *CounterVec) ClearState()

ClearState will clear all the states marked by Create. It intends to be used for re-register a hidden metric.

func (*CounterVec) Create Uses

func (r *CounterVec) Create(version *semver.Version) bool

Create forces the initialization of metric which has been deferred until the point at which this method is invoked. This method will determine whether the metric is deprecated or hidden, no-opting if the metric should be considered hidden. Furthermore, this function no-opts and returns true if metric is already created.

func (*CounterVec) Delete Uses

func (v *CounterVec) Delete(labels map[string]string) bool

Delete deletes the metric where the variable labels are the same as those passed in as labels. It returns true if a metric was deleted.

It is not an error if the number and names of the Labels are inconsistent with those of the VariableLabels in Desc. However, such inconsistent Labels can never match an actual metric, so the method will always return false in that case.

func (*CounterVec) DeprecatedVersion Uses

func (v *CounterVec) DeprecatedVersion() *semver.Version

DeprecatedVersion returns a pointer to the Version or nil

func (*CounterVec) FQName Uses

func (r *CounterVec) FQName() string

FQName returns the fully-qualified metric name of the collector.

func (*CounterVec) IsCreated Uses

func (r *CounterVec) IsCreated() bool

func (*CounterVec) IsDeprecated Uses

func (r *CounterVec) IsDeprecated() bool

func (*CounterVec) IsHidden Uses

func (r *CounterVec) IsHidden() bool

func (*CounterVec) Reset Uses

func (v *CounterVec) Reset()

Reset deletes all metrics in this vector.

func (*CounterVec) With Uses

func (v *CounterVec) With(labels map[string]string) CounterMetric

With returns the Counter 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 Counter is created IFF the counterVec has been registered to a metrics registry.

func (*CounterVec) WithLabelValues Uses

func (v *CounterVec) WithLabelValues(lvs ...string) CounterMetric

WithLabelValues returns the Counter for the given slice of label values (same order as the VariableLabels in Desc). If that combination of label values is accessed for the first time, a new Counter is created IFF the counterVec has been registered to a metrics registry.

type CounterVecMetric Uses

type CounterVecMetric interface {
    WithLabelValues(...string) CounterMetric
    With(prometheus.Labels) CounterMetric
}

CounterVecMetric is an interface which prometheus.CounterVec satisfies.

type Desc Uses

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

Desc is a prometheus.Desc extension.

Use NewDesc to create new Desc instances.

func NewDesc Uses

func NewDesc(fqName string, help string, variableLabels []string, constLabels Labels,
    stabilityLevel StabilityLevel, deprecatedVersion string) *Desc

NewDesc extends prometheus.NewDesc with stability support.

The stabilityLevel should be valid stability label, such as "metrics.ALPHA" and "metrics.STABLE"(Maybe "metrics.BETA" in future). Default value "metrics.ALPHA" will be used in case of empty or invalid stability label.

The deprecatedVersion represents in which version this Metric be deprecated. The deprecation policy outlined by the control plane metrics stability KEP.

func (*Desc) ClearState Uses

func (d *Desc) ClearState()

ClearState will clear all the states marked by Create. It intends to be used for re-register a hidden metric.

func (*Desc) DeprecatedVersion Uses

func (d *Desc) DeprecatedVersion() *semver.Version

DeprecatedVersion returns a pointer to the Version or nil

func (*Desc) GetRawDesc Uses

func (d *Desc) GetRawDesc() *Desc

GetRawDesc will returns a new *Desc with original parameters provided to NewDesc().

It will be useful in testing scenario that the same Desc be registered to different registry.

1. Desc `D` is registered to registry 'A' in TestA (Note: `D` maybe created)
2. Desc `D` is registered to registry 'B' in TestB (Note: since 'D' has been created once, thus will be ignored by registry 'B')

func (*Desc) IsCreated Uses

func (d *Desc) IsCreated() bool

IsCreated returns if metric has been created.

func (*Desc) IsDeprecated Uses

func (d *Desc) IsDeprecated() bool

IsDeprecated returns if metric has been deprecated

func (*Desc) IsHidden Uses

func (d *Desc) IsHidden() bool

IsHidden returns if metric will be hidden

func (*Desc) String Uses

func (d *Desc) String() string

String formats the Desc as a string. The stability metadata maybe annotated in 'HELP' section if called after registry, otherwise not. e.g. "Desc{fqName: "normal_stable_descriptor", help: "[STABLE] this is a stable descriptor", constLabels: {}, variableLabels: []}"

type Gatherer Uses

type Gatherer interface {
    prometheus.Gatherer
}

Gatherer is the interface for the part of a registry in charge of gathering the collected metrics into a number of MetricFamilies.

type Gauge Uses

type Gauge struct {
    GaugeMetric
    *GaugeOpts
    // contains filtered or unexported fields
}

Gauge is our internal representation for our wrapping struct around prometheus gauges. kubeGauge implements both kubeCollector and KubeGauge.

func NewGauge Uses

func NewGauge(opts *GaugeOpts) *Gauge

NewGauge returns an object which satisfies the kubeCollector and KubeGauge interfaces. However, the object returned will not measure anything unless the collector is first registered, since the metric is lazily instantiated.

func (*Gauge) ClearState Uses

func (r *Gauge) ClearState()

ClearState will clear all the states marked by Create. It intends to be used for re-register a hidden metric.

func (*Gauge) Collect Uses

func (c *Gauge) Collect(ch chan<- prometheus.Metric)

func (*Gauge) Create Uses

func (r *Gauge) Create(version *semver.Version) bool

Create forces the initialization of metric which has been deferred until the point at which this method is invoked. This method will determine whether the metric is deprecated or hidden, no-opting if the metric should be considered hidden. Furthermore, this function no-opts and returns true if metric is already created.

func (*Gauge) DeprecatedVersion Uses

func (g *Gauge) DeprecatedVersion() *semver.Version

DeprecatedVersion returns a pointer to the Version or nil

func (*Gauge) Describe Uses

func (c *Gauge) Describe(ch chan<- *prometheus.Desc)

func (*Gauge) FQName Uses

func (r *Gauge) FQName() string

FQName returns the fully-qualified metric name of the collector.

func (*Gauge) IsCreated Uses

func (r *Gauge) IsCreated() bool

func (*Gauge) IsDeprecated Uses

func (r *Gauge) IsDeprecated() bool

func (*Gauge) IsHidden Uses

func (r *Gauge) IsHidden() bool

type GaugeFunc Uses

type GaugeFunc interface {
    Metric
    Collector
}

GaugeFunc is a Gauge whose value is determined at collect time by calling a provided function.

To create GaugeFunc instances, use NewGaugeFunc.

func NewGaugeFunc Uses

func NewGaugeFunc(opts GaugeOpts, function func() float64) GaugeFunc

NewGaugeFunc creates a new GaugeFunc based on the provided GaugeOpts. The value reported is determined by calling the given function from within the Write method. Take into account that metric collection may happen concurrently. If that results in concurrent calls to Write, like in the case where a GaugeFunc is directly registered with Prometheus, the provided function must be concurrency-safe.

type GaugeMetric Uses

type GaugeMetric interface {
    Set(float64)
    Inc()
    Dec()
    Add(float64)
    Write(out *dto.Metric) error
    SetToCurrentTime()
}

GaugeMetric is an interface which defines a subset of the interface provided by prometheus.Gauge

type GaugeOpts Uses

type GaugeOpts KubeOpts

GaugeOpts is an alias for Opts. See there for doc comments.

type GaugeVec Uses

type GaugeVec struct {
    *prometheus.GaugeVec
    *GaugeOpts
    // contains filtered or unexported fields
}

GaugeVec is the internal representation of our wrapping struct around prometheus gaugeVecs. kubeGaugeVec implements both kubeCollector and KubeGaugeVec.

func NewGaugeVec Uses

func NewGaugeVec(opts *GaugeOpts, labels []string) *GaugeVec

NewGaugeVec returns an object which satisfies the kubeCollector and KubeGaugeVec interfaces. However, the object returned will not measure anything unless the collector is first registered, since the metric is lazily instantiated.

func (*GaugeVec) ClearState Uses

func (r *GaugeVec) ClearState()

ClearState will clear all the states marked by Create. It intends to be used for re-register a hidden metric.

func (*GaugeVec) Create Uses

func (r *GaugeVec) Create(version *semver.Version) bool

Create forces the initialization of metric which has been deferred until the point at which this method is invoked. This method will determine whether the metric is deprecated or hidden, no-opting if the metric should be considered hidden. Furthermore, this function no-opts and returns true if metric is already created.

func (*GaugeVec) Delete Uses

func (v *GaugeVec) Delete(labels map[string]string) bool

Delete deletes the metric where the variable labels are the same as those passed in as labels. It returns true if a metric was deleted.

It is not an error if the number and names of the Labels are inconsistent with those of the VariableLabels in Desc. However, such inconsistent Labels can never match an actual metric, so the method will always return false in that case.

func (*GaugeVec) DeprecatedVersion Uses

func (v *GaugeVec) DeprecatedVersion() *semver.Version

DeprecatedVersion returns a pointer to the Version or nil

func (*GaugeVec) FQName Uses

func (r *GaugeVec) FQName() string

FQName returns the fully-qualified metric name of the collector.

func (*GaugeVec) IsCreated Uses

func (r *GaugeVec) IsCreated() bool

func (*GaugeVec) IsDeprecated Uses

func (r *GaugeVec) IsDeprecated() bool

func (*GaugeVec) IsHidden Uses

func (r *GaugeVec) IsHidden() bool

func (*GaugeVec) Reset Uses

func (v *GaugeVec) Reset()

Reset deletes all metrics in this vector.

func (*GaugeVec) With Uses

func (v *GaugeVec) With(labels map[string]string) GaugeMetric

With returns the GaugeMetric 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 GaugeMetric is created IFF the gaugeVec has been registered to a metrics registry.

func (*GaugeVec) WithLabelValues Uses

func (v *GaugeVec) WithLabelValues(lvs ...string) GaugeMetric

WithLabelValues returns the GaugeMetric for the given slice of label values (same order as the VariableLabels in Desc). If that combination of label values is accessed for the first time, a new GaugeMetric is created IFF the gaugeVec has been registered to a metrics registry.

type HandlerOpts Uses

type HandlerOpts promhttp.HandlerOpts

HandlerOpts specifies options how to serve metrics via an http.Handler. The zero value of HandlerOpts is a reasonable default.

type Histogram Uses

type Histogram struct {
    ObserverMetric
    *HistogramOpts
    // contains filtered or unexported fields
}

Histogram is our internal representation for our wrapping struct around prometheus histograms. Summary implements both kubeCollector and ObserverMetric

func NewHistogram Uses

func NewHistogram(opts *HistogramOpts) *Histogram

NewHistogram returns an object which is Histogram-like. However, nothing will be measured until the histogram is registered somewhere.

func (*Histogram) ClearState Uses

func (r *Histogram) ClearState()

ClearState will clear all the states marked by Create. It intends to be used for re-register a hidden metric.

func (*Histogram) Collect Uses

func (c *Histogram) Collect(ch chan<- prometheus.Metric)

func (*Histogram) Create Uses

func (r *Histogram) Create(version *semver.Version) bool

Create forces the initialization of metric which has been deferred until the point at which this method is invoked. This method will determine whether the metric is deprecated or hidden, no-opting if the metric should be considered hidden. Furthermore, this function no-opts and returns true if metric is already created.

func (*Histogram) DeprecatedVersion Uses

func (h *Histogram) DeprecatedVersion() *semver.Version

DeprecatedVersion returns a pointer to the Version or nil

func (*Histogram) Describe Uses

func (c *Histogram) Describe(ch chan<- *prometheus.Desc)

func (*Histogram) FQName Uses

func (r *Histogram) FQName() string

FQName returns the fully-qualified metric name of the collector.

func (*Histogram) IsCreated Uses

func (r *Histogram) IsCreated() bool

func (*Histogram) IsDeprecated Uses

func (r *Histogram) IsDeprecated() bool

func (*Histogram) IsHidden Uses

func (r *Histogram) IsHidden() bool

type HistogramOpts Uses

type HistogramOpts struct {
    Namespace         string
    Subsystem         string
    Name              string
    Help              string
    ConstLabels       map[string]string
    Buckets           []float64
    DeprecatedVersion string

    StabilityLevel StabilityLevel
    // contains filtered or unexported fields
}

HistogramOpts bundles the options for creating a Histogram metric. It is mandatory to set Name to a non-empty string. All other fields are optional and can safely be left at their zero value, although it is strongly encouraged to set a Help string.

type HistogramVec Uses

type HistogramVec struct {
    *prometheus.HistogramVec
    *HistogramOpts
    // contains filtered or unexported fields
}

HistogramVec is the internal representation of our wrapping struct around prometheus histogramVecs.

func NewHistogramVec Uses

func NewHistogramVec(opts *HistogramOpts, labels []string) *HistogramVec

NewHistogramVec returns an object which satisfies kubeCollector and wraps the prometheus.HistogramVec object. However, the object returned will not measure anything unless the collector is first registered, since the metric is lazily instantiated.

func (*HistogramVec) ClearState Uses

func (r *HistogramVec) ClearState()

ClearState will clear all the states marked by Create. It intends to be used for re-register a hidden metric.

func (*HistogramVec) Create Uses

func (r *HistogramVec) Create(version *semver.Version) bool

Create forces the initialization of metric which has been deferred until the point at which this method is invoked. This method will determine whether the metric is deprecated or hidden, no-opting if the metric should be considered hidden. Furthermore, this function no-opts and returns true if metric is already created.

func (*HistogramVec) Delete Uses

func (v *HistogramVec) Delete(labels map[string]string) bool

Delete deletes the metric where the variable labels are the same as those passed in as labels. It returns true if a metric was deleted.

It is not an error if the number and names of the Labels are inconsistent with those of the VariableLabels in Desc. However, such inconsistent Labels can never match an actual metric, so the method will always return false in that case.

func (*HistogramVec) DeprecatedVersion Uses

func (v *HistogramVec) DeprecatedVersion() *semver.Version

DeprecatedVersion returns a pointer to the Version or nil

func (*HistogramVec) FQName Uses

func (r *HistogramVec) FQName() string

FQName returns the fully-qualified metric name of the collector.

func (*HistogramVec) IsCreated Uses

func (r *HistogramVec) IsCreated() bool

func (*HistogramVec) IsDeprecated Uses

func (r *HistogramVec) IsDeprecated() bool

func (*HistogramVec) IsHidden Uses

func (r *HistogramVec) IsHidden() bool

func (*HistogramVec) Reset Uses

func (v *HistogramVec) Reset()

Reset deletes all metrics in this vector.

func (*HistogramVec) With Uses

func (v *HistogramVec) With(labels map[string]string) ObserverMetric

With returns the ObserverMetric 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 ObserverMetric is created IFF the HistogramVec has been registered to a metrics registry.

func (*HistogramVec) WithLabelValues Uses

func (v *HistogramVec) WithLabelValues(lvs ...string) ObserverMetric

WithLabelValues returns the ObserverMetric for the given slice of label values (same order as the VariableLabels in Desc). If that combination of label values is accessed for the first time, a new ObserverMetric is created IFF the HistogramVec has been registered to a metrics registry.

type KubeOpts Uses

type KubeOpts struct {
    Namespace         string
    Subsystem         string
    Name              string
    Help              string
    ConstLabels       map[string]string
    DeprecatedVersion string

    StabilityLevel StabilityLevel
    // contains filtered or unexported fields
}

KubeOpts is superset struct for prometheus.Opts. The prometheus Opts structure is purposefully not embedded here because that would change struct initialization in the manner which people are currently accustomed.

Name must be set to a non-empty string. DeprecatedVersion is defined only if the metric for which this options applies is, in fact, deprecated.

type KubeRegistry Uses

type KubeRegistry interface {
    // Deprecated
    RawMustRegister(...prometheus.Collector)
    CustomRegister(c StableCollector) error
    CustomMustRegister(cs ...StableCollector)
    Register(Registerable) error
    MustRegister(...Registerable)
    Unregister(collector Collector) bool
    Gather() ([]*dto.MetricFamily, error)
}

KubeRegistry is an interface which implements a subset of prometheus.Registerer and prometheus.Gatherer interfaces

func NewKubeRegistry Uses

func NewKubeRegistry() KubeRegistry

NewKubeRegistry creates a new vanilla Registry without any Collectors pre-registered.

type Labels Uses

type Labels prometheus.Labels

Labels represents a collection of label name -> value mappings.

type Metric Uses

type Metric interface {
    Desc() *prometheus.Desc
    Write(*dto.Metric) error
}

Metric defines a subset of prometheus.Metric interface methods

func NewLazyConstMetric Uses

func NewLazyConstMetric(desc *Desc, valueType ValueType, value float64, labelValues ...string) Metric

NewLazyConstMetric is a helper of MustNewConstMetric.

Note: If the metrics described by the desc is hidden, the metrics will not be created.

func NewLazyMetricWithTimestamp Uses

func NewLazyMetricWithTimestamp(t time.Time, m Metric) Metric

NewLazyMetricWithTimestamp is a helper of NewMetricWithTimestamp.

Warning: the Metric 'm' must be the one created by NewLazyConstMetric(),

otherwise, no stability guarantees would be offered.

type ObserverMetric Uses

type ObserverMetric interface {
    Observe(float64)
}

ObserverMetric captures individual observations.

type PromRegistry Uses

type PromRegistry interface {
    Register(prometheus.Collector) error
    MustRegister(...prometheus.Collector)
    Unregister(prometheus.Collector) bool
    Gather() ([]*dto.MetricFamily, error)
}

PromRegistry is an interface which implements a subset of prometheus.Registerer and prometheus.Gatherer interfaces

type Registerable Uses

type Registerable interface {
    prometheus.Collector

    // Create will mark deprecated state for the collector
    Create(version *semver.Version) bool

    // ClearState will clear all the states marked by Create.
    ClearState()

    // FQName returns the fully-qualified metric name of the collector.
    FQName() string
}

Registerable is an interface for a collector metric which we will register with KubeRegistry.

type StabilityLevel Uses

type StabilityLevel string

StabilityLevel represents the API guarantees for a given defined metric.

const (
    // ALPHA metrics have no stability guarantees, as such, labels may
    // be arbitrarily added/removed and the metric may be deleted at any time.
    ALPHA StabilityLevel = "ALPHA"
    // STABLE metrics are guaranteed not be mutated and removal is governed by
    // the deprecation policy outlined in by the control plane metrics stability KEP.
    STABLE StabilityLevel = "STABLE"
)

type StableCollector Uses

type StableCollector interface {
    prometheus.Collector

    // DescribeWithStability sends the super-set of all possible metrics.Desc collected
    // by this StableCollector to the provided channel.
    DescribeWithStability(chan<- *Desc)

    // CollectWithStability sends each collected metrics.Metric via the provide channel.
    CollectWithStability(chan<- Metric)

    // Create will initialize all Desc and it intends to be called by registry.
    Create(version *semver.Version, self StableCollector) bool

    // ClearState will clear all the states marked by Create.
    ClearState()

    // HiddenMetrics tells the list of hidden metrics with fqName.
    HiddenMetrics() []string
}

StableCollector extends the prometheus.Collector interface to allow customization of the metric registration process, it's especially intend to be used in scenario of custom collector.

type Summary Uses

type Summary struct {
    ObserverMetric
    *SummaryOpts
    // contains filtered or unexported fields
}

Summary is our internal representation for our wrapping struct around prometheus summaries. Summary implements both kubeCollector and ObserverMetric

DEPRECATED: as per the metrics overhaul KEP

func NewSummary Uses

func NewSummary(opts *SummaryOpts) *Summary

NewSummary returns an object which is Summary-like. However, nothing will be measured until the summary is registered somewhere.

DEPRECATED: as per the metrics overhaul KEP

func (*Summary) ClearState Uses

func (r *Summary) ClearState()

ClearState will clear all the states marked by Create. It intends to be used for re-register a hidden metric.

func (*Summary) Collect Uses

func (c *Summary) Collect(ch chan<- prometheus.Metric)

func (*Summary) Create Uses

func (r *Summary) Create(version *semver.Version) bool

Create forces the initialization of metric which has been deferred until the point at which this method is invoked. This method will determine whether the metric is deprecated or hidden, no-opting if the metric should be considered hidden. Furthermore, this function no-opts and returns true if metric is already created.

func (*Summary) DeprecatedVersion Uses

func (s *Summary) DeprecatedVersion() *semver.Version

DeprecatedVersion returns a pointer to the Version or nil

func (*Summary) Describe Uses

func (c *Summary) Describe(ch chan<- *prometheus.Desc)

func (*Summary) FQName Uses

func (r *Summary) FQName() string

FQName returns the fully-qualified metric name of the collector.

func (*Summary) IsCreated Uses

func (r *Summary) IsCreated() bool

func (*Summary) IsDeprecated Uses

func (r *Summary) IsDeprecated() bool

func (*Summary) IsHidden Uses

func (r *Summary) IsHidden() bool

type SummaryOpts Uses

type SummaryOpts struct {
    Namespace         string
    Subsystem         string
    Name              string
    Help              string
    ConstLabels       map[string]string
    Objectives        map[float64]float64
    MaxAge            time.Duration
    AgeBuckets        uint32
    BufCap            uint32
    DeprecatedVersion string

    StabilityLevel StabilityLevel
    // contains filtered or unexported fields
}

SummaryOpts bundles the options for creating a Summary metric. It is mandatory to set Name to a non-empty string. While all other fields are optional and can safely be left at their zero value, it is recommended to set a help string and to explicitly set the Objectives field to the desired value as the default value will change in the upcoming v0.10 of the library.

type SummaryVec Uses

type SummaryVec struct {
    *prometheus.SummaryVec
    *SummaryOpts
    // contains filtered or unexported fields
}

SummaryVec is the internal representation of our wrapping struct around prometheus summaryVecs.

DEPRECATED: as per the metrics overhaul KEP

func NewSummaryVec Uses

func NewSummaryVec(opts *SummaryOpts, labels []string) *SummaryVec

NewSummaryVec returns an object which satisfies kubeCollector and wraps the prometheus.SummaryVec object. However, the object returned will not measure anything unless the collector is first registered, since the metric is lazily instantiated.

DEPRECATED: as per the metrics overhaul KEP

func (*SummaryVec) ClearState Uses

func (r *SummaryVec) ClearState()

ClearState will clear all the states marked by Create. It intends to be used for re-register a hidden metric.

func (*SummaryVec) Create Uses

func (r *SummaryVec) Create(version *semver.Version) bool

Create forces the initialization of metric which has been deferred until the point at which this method is invoked. This method will determine whether the metric is deprecated or hidden, no-opting if the metric should be considered hidden. Furthermore, this function no-opts and returns true if metric is already created.

func (*SummaryVec) Delete Uses

func (v *SummaryVec) Delete(labels map[string]string) bool

Delete deletes the metric where the variable labels are the same as those passed in as labels. It returns true if a metric was deleted.

It is not an error if the number and names of the Labels are inconsistent with those of the VariableLabels in Desc. However, such inconsistent Labels can never match an actual metric, so the method will always return false in that case.

func (*SummaryVec) DeprecatedVersion Uses

func (v *SummaryVec) DeprecatedVersion() *semver.Version

DeprecatedVersion returns a pointer to the Version or nil

func (*SummaryVec) FQName Uses

func (r *SummaryVec) FQName() string

FQName returns the fully-qualified metric name of the collector.

func (*SummaryVec) IsCreated Uses

func (r *SummaryVec) IsCreated() bool

func (*SummaryVec) IsDeprecated Uses

func (r *SummaryVec) IsDeprecated() bool

func (*SummaryVec) IsHidden Uses

func (r *SummaryVec) IsHidden() bool

func (*SummaryVec) Reset Uses

func (v *SummaryVec) Reset()

Reset deletes all metrics in this vector.

func (*SummaryVec) With Uses

func (v *SummaryVec) With(labels map[string]string) ObserverMetric

With returns the ObserverMetric 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 ObserverMetric is created IFF the summaryVec has been registered to a metrics registry.

func (*SummaryVec) WithLabelValues Uses

func (v *SummaryVec) WithLabelValues(lvs ...string) ObserverMetric

WithLabelValues returns the ObserverMetric for the given slice of label values (same order as the VariableLabels in Desc). If that combination of label values is accessed for the first time, a new ObserverMetric is created IFF the summaryVec has been registered to a metrics registry.

type ValueType Uses

type ValueType int

ValueType is an enumeration of metric types that represent a simple value.

const (
    CounterValue ValueType
    GaugeValue
    UntypedValue
)

Possible values for the ValueType enum.

Directories

PathSynopsis
legacyregistry
prometheus/clientgo
prometheus/clientgo/leaderelection
prometheus/ratelimiter
prometheus/restclient
prometheus/version
prometheus/workqueue
testutil

Package metrics imports 15 packages (graph) and is imported by 177 packages. Updated 2019-12-16. Refresh now. Tools for package owners.