histogram

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package histogram provides primitives for working with histograms, particularly towards building Prometheus exporters.

Example
// Create a new descriptor.
desc := prometheus.NewDesc(
	"foo_bar_metric",
	"The number of foos that have been bared",
	nil,
	nil,
)

// Create a Histogram.
c := Config{
	BucketLimits: []float64{0, 1, 5},
}
h, _ := New(c)

// Add entries to the Histogram as part of the exporter,
// e.g: latency of network connections.
h.Add(0.2)

// Convert the Histogram into a metric.
metric := prometheus.MustNewConstHistogram(
	desc, h.Count(), h.Sum(), h.Buckets(),
)

fmt.Println(metric)

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

Types

type Config

type Config struct {
	// BucketLimits is the upper limit of each bucket in the histogram.
	// See https://godoc.org/github.com/prometheus/client_golang/prometheus#HistogramOpts.
	BucketLimits []float64
}

type Histogram

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

Histogram is a data structure suitable for providing the inputs to a Prometheus Histogram. See https://godoc.org/github.com/prometheus/client_golang/prometheus#MustNewConstHistogram.

func New

func New(config Config) (*Histogram, error)

func (*Histogram) Add

func (h *Histogram) Add(x float64)

Add saves an entry to the Histogram.

func (*Histogram) Buckets

func (h *Histogram) Buckets() map[float64]uint64

Buckets returns a copy of the current buckets with their counts.

func (*Histogram) Copy added in v0.2.0

func (h *Histogram) Copy() *Histogram

func (*Histogram) Count

func (h *Histogram) Count() uint64

Count returns the number of samples recorded.

func (*Histogram) Sum

func (h *Histogram) Sum() float64

Buckets returns the sum of all samples recorded.

Jump to

Keyboard shortcuts

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