metrics

package
v0.0.0-...-de40865 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 10 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindHistogramWithNameAndLabels

func FindHistogramWithNameAndLabels(metrics MetricFamilyMap, name string, labelNamesAndValues ...string) (*dto.Histogram, error)

FindHistogramWithNameAndLabels returns the histogram in metrics with name that matches the labels in labelNamesAndValues. If no histogram with name is present in metrics, if labelNamesAndValues matches anything other than exactly one metric, or if the matching metric is not a histogram, an error is returned.

func FindMetricsInFamilyMatchingLabels

func FindMetricsInFamilyMatchingLabels(mf *dto.MetricFamily, labelNamesAndValues ...string) []*dto.Metric

FindMetricsInFamilyMatchingLabels returns all the metrics in mf that match the labels in labelNamesAndValues.

func MatchesLabels

func MatchesLabels(m *dto.Metric, labelNamesAndValues ...string) bool

MatchesLabels returns true if m has all the labels in l.

func WithSkipZeroValueMetrics

func WithSkipZeroValueMetrics(options *metricOptions)

WithSkipZeroValueMetrics controls whether metrics aggregation should skip zero value metrics.

Types

type HistogramData

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

HistogramData keeps data required to build histogram Metric.

func (*HistogramData) AddHistogram

func (d *HistogramData) AddHistogram(histo *dto.Histogram)

AddHistogram adds histogram from gathered metrics to this histogram data. Do not call this function after Metric() has been invoked, because histogram created by Metric is using the buckets map (doesn't make a copy), and it's not allowed to change the buckets after they've been passed to a prometheus.Metric.

func (*HistogramData) AddHistogramData

func (d *HistogramData) AddHistogramData(histo HistogramData)

AddHistogramData merges another histogram data into this one. Do not call this function after Metric() has been invoked, because histogram created by Metric is using the buckets map (doesn't make a copy), and it's not allowed to change the buckets after they've been passed to a prometheus.Metric.

func (*HistogramData) Copy

func (d *HistogramData) Copy() *HistogramData

Copy returns a copy of this histogram data.

func (HistogramData) Count

func (d HistogramData) Count() uint64

Count returns the histogram count value.

func (*HistogramData) Metric

func (d *HistogramData) Metric(desc *prometheus.Desc, labelValues ...string) prometheus.Metric

Metric returns prometheus metric from this histogram data.

Note that returned metric shares bucket with this HistogramData, so avoid doing more modifications to this HistogramData after calling Metric.

type HistogramDataCollector

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

HistogramDataCollector combines histogram data, with prometheus descriptor. It can be registered into prometheus to report histogram with stored data. Data can be updated via Add method.

func NewHistogramDataCollector

func NewHistogramDataCollector(desc *prometheus.Desc) *HistogramDataCollector

NewHistogramDataCollector creates new histogram data collector.

func (*HistogramDataCollector) Add

func (*HistogramDataCollector) Collect

func (h *HistogramDataCollector) Collect(out chan<- prometheus.Metric)

func (*HistogramDataCollector) Describe

func (h *HistogramDataCollector) Describe(out chan<- *prometheus.Desc)

type MetricFamiliesPerTenant

type MetricFamiliesPerTenant []struct {
	// contains filtered or unexported fields
}

MetricFamiliesPerTenant is a collection of metrics gathered via calling Gatherer.Gather() method on different gatherers, one per tenant.

func (MetricFamiliesPerTenant) GetSumOfCounters

func (d MetricFamiliesPerTenant) GetSumOfCounters(counter string) float64

func (MetricFamiliesPerTenant) GetSumOfGauges

func (d MetricFamiliesPerTenant) GetSumOfGauges(gauge string) float64

func (MetricFamiliesPerTenant) SendMaxOfGauges

func (d MetricFamiliesPerTenant) SendMaxOfGauges(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string)

func (MetricFamiliesPerTenant) SendMaxOfGaugesPerTenant

func (d MetricFamiliesPerTenant) SendMaxOfGaugesPerTenant(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string)

func (MetricFamiliesPerTenant) SendMinOfGauges

func (d MetricFamiliesPerTenant) SendMinOfGauges(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string)

func (MetricFamiliesPerTenant) SendSumOfCounters

func (d MetricFamiliesPerTenant) SendSumOfCounters(out chan<- prometheus.Metric, desc *prometheus.Desc, counter string)

func (MetricFamiliesPerTenant) SendSumOfCountersPerTenant

func (d MetricFamiliesPerTenant) SendSumOfCountersPerTenant(out chan<- prometheus.Metric, desc *prometheus.Desc, metric string, options ...MetricOption)

SendSumOfCountersPerTenant provides metrics on a per-tenant basis, with additional and optional label names. This function assumes that `tenant` is the first label on the provided metric Desc.

func (MetricFamiliesPerTenant) SendSumOfCountersWithLabels

func (d MetricFamiliesPerTenant) SendSumOfCountersWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, counter string, labelNames ...string)

func (MetricFamiliesPerTenant) SendSumOfGauges

func (d MetricFamiliesPerTenant) SendSumOfGauges(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string)

func (MetricFamiliesPerTenant) SendSumOfGaugesPerTenant

func (d MetricFamiliesPerTenant) SendSumOfGaugesPerTenant(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string)

SendSumOfGaugesPerTenant provides metrics on a per-tenant basis. This function assumes that `tenant` is the first label on the provided metric Desc.

func (MetricFamiliesPerTenant) SendSumOfGaugesPerTenantWithLabels

func (d MetricFamiliesPerTenant) SendSumOfGaugesPerTenantWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, metric string, labelNames ...string)

SendSumOfGaugesPerTenantWithLabels provides metrics with the provided label names on a per-tenant basis. This function assumes that `tenant` is the first label on the provided metric Desc

func (MetricFamiliesPerTenant) SendSumOfGaugesWithLabels

func (d MetricFamiliesPerTenant) SendSumOfGaugesWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string, labelNames ...string)

func (MetricFamiliesPerTenant) SendSumOfHistograms

func (d MetricFamiliesPerTenant) SendSumOfHistograms(out chan<- prometheus.Metric, desc *prometheus.Desc, histogramName string)

func (MetricFamiliesPerTenant) SendSumOfHistogramsWithLabels

func (d MetricFamiliesPerTenant) SendSumOfHistogramsWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, histogramName string, labelNames ...string)

func (MetricFamiliesPerTenant) SendSumOfSummaries

func (d MetricFamiliesPerTenant) SendSumOfSummaries(out chan<- prometheus.Metric, desc *prometheus.Desc, summaryName string)

func (MetricFamiliesPerTenant) SendSumOfSummariesPerTenant

func (d MetricFamiliesPerTenant) SendSumOfSummariesPerTenant(out chan<- prometheus.Metric, desc *prometheus.Desc, summaryName string)

func (MetricFamiliesPerTenant) SendSumOfSummariesWithLabels

func (d MetricFamiliesPerTenant) SendSumOfSummariesWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, summaryName string, labelNames ...string)

type MetricFamilyMap

type MetricFamilyMap map[string]*dto.MetricFamily

MetricFamilyMap is a map of metric names to their family (metrics with same name, but different labels) Keeping map of metric name to its family makes it easier to do searches later.

func NewMetricFamilyMap

func NewMetricFamilyMap(metrics []*dto.MetricFamily) (MetricFamilyMap, error)

NewMetricFamilyMap sorts output from Gatherer.Gather method into a map. Gatherer.Gather specifies that there metric families are uniquely named, and we use that fact here. If they are not, this method returns error.

func NewMetricFamilyMapFromGatherer

func NewMetricFamilyMapFromGatherer(gatherer prometheus.Gatherer) (MetricFamilyMap, error)

NewMetricFamilyMapFromGatherer is like NewMetricFamilyMap but gets metrics directly from a prometheus.Gatherer instance.

func (MetricFamilyMap) MaxGauges

func (mfm MetricFamilyMap) MaxGauges(name string) float64

MaxGauges returns max of gauges or NaN, if no gauge was found.

func (MetricFamilyMap) MinGauges

func (mfm MetricFamilyMap) MinGauges(name string) float64

MinGauges returns minimum of gauges or NaN if no gauge was found.

func (MetricFamilyMap) SumCounters

func (mfm MetricFamilyMap) SumCounters(name string) float64

SumCounters returns sum of counters or 0, if no counter was found.

func (MetricFamilyMap) SumGauges

func (mfm MetricFamilyMap) SumGauges(name string) float64

SumGauges returns sum of gauges or 0, if no gauge was found.

func (MetricFamilyMap) SumHistograms

func (mfm MetricFamilyMap) SumHistograms(name string) HistogramData

func (MetricFamilyMap) SumHistogramsTo

func (mfm MetricFamilyMap) SumHistogramsTo(name string, output *HistogramData)

func (MetricFamilyMap) SumSummaries

func (mfm MetricFamilyMap) SumSummaries(name string) SummaryData

func (MetricFamilyMap) SumSummariesTo

func (mfm MetricFamilyMap) SumSummariesTo(name string, output *SummaryData)

type MetricOption

type MetricOption func(options *metricOptions)

MetricOption defines a functional-style option for metrics aggregation.

func WithLabels

func WithLabels(labelNames ...string) MetricOption

WithLabels set labels to use for aggregations.

type SummaryData

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

SummaryData keeps all data needed to create summary metric

func (*SummaryData) AddSummary

func (s *SummaryData) AddSummary(sum *dto.Summary)

func (*SummaryData) Metric

func (s *SummaryData) Metric(desc *prometheus.Desc, labelValues ...string) prometheus.Metric

type TenantRegistries

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

TenantRegistries holds Prometheus registries for multiple tenants, guaranteeing multi-thread safety and stable ordering.

func NewTenantRegistries

func NewTenantRegistries(logger log.Logger) *TenantRegistries

NewTenantRegistries makes new TenantRegistries.

func (*TenantRegistries) AddTenantRegistry

func (r *TenantRegistries) AddTenantRegistry(tenant string, reg *prometheus.Registry)

AddTenantRegistry adds a tenant registry. If tenant already has a registry, previous registry is removed, but latest metric values are preserved in order to avoid counter resets.

func (*TenantRegistries) BuildMetricFamiliesPerTenant

func (r *TenantRegistries) BuildMetricFamiliesPerTenant() MetricFamiliesPerTenant

func (*TenantRegistries) GetRegistryForTenant

func (r *TenantRegistries) GetRegistryForTenant(tenant string) *prometheus.Registry

GetRegistryForTenant returns currently active registry for given tenant, or nil, if there is no such registry.

func (*TenantRegistries) Registries

func (r *TenantRegistries) Registries() []TenantRegistry

Registries returns a copy of the tenant registries list.

func (*TenantRegistries) RemoveTenantRegistry

func (r *TenantRegistries) RemoveTenantRegistry(tenant string, hard bool)

RemoveTenantRegistry removes all Prometheus registries for a given tenant. If hard is true, registry is removed completely. If hard is false, the latest registry values are preserved for future aggregations.

type TenantRegistry

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

TenantRegistry holds a Prometheus registry associated to a specific tenant.

Jump to

Keyboard shortcuts

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