schema

package
v1.5.17 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// https://github.com/prometheus/OpenMetrics/blob/main/specification/OpenMetrics.md
	ContentTypeMetrics = "application/openmetrics-text; version=1.0.0; charset=utf-8"
)
View Source
const (
	SchemaName = "metrics"
)

Variables

This section is empty.

Functions

func LabelSet added in v1.5.15

func LabelSet(labels ...any) ([]string, error)

Types

type Family

type Family struct {
	// Name of the family
	Name string `json:"name,omitempty"`

	// Help text
	Help string `json:"help,omitempty"`

	// Valid values are "gauge", "counter", "stateset", "info", "histogram", "gaugehistogram", and "summary".
	// If not set, "unknown" is assumed.
	Type string `json:"type"`

	// Unit of measurement, ie "seconds". This is optional.
	Unit string `json:"unit,omitempty"`

	// Samples
	Samples []*Sample `json:"samples,omitempty"`
}

func NewMetricFamily

func NewMetricFamily(name string, opts ...Opt) (*Family, error)

NewMetricFamily returns a new, empty metric family

func (*Family) Write

func (f *Family) Write(w io.Writer, labels ...string) error

type Opt

type Opt func(*opt) error

func WithCounter

func WithCounter(total float64, labels ...any) Opt

Counter type provides a steadily increasing value

func WithFloat

func WithFloat(name string, value float64, labels ...any) Opt

With a float64 value

func WithGauge

func WithGauge(value float64, labels ...any) Opt

Gauge type provides a changeable value

func WithHelp

func WithHelp(help string) Opt

func WithInfo

func WithInfo(labels ...any) Opt

Info type

func WithInt

func WithInt(name string, value int64, labels ...any) Opt

With an integer value

func WithState

func WithState(value bool, labels ...any) Opt

State type provides an on/off value

func WithType

func WithType(v string) Opt

func WithUnit

func WithUnit(unit string) Opt

type Sample

type Sample struct {
	// Name of the sample
	Name string `json:"suffix,omitempty"`

	// Labels are key-value pairs
	Labels []string `json:"labels,omitempty"`

	// Metric value
	Float *float64 `json:"float,omitempty"`
	Int   *int64   `json:"int,omitempty"`

	// Timestamp in seconds since epoch
	Timestamp *float64 `json:"timestamp,omitempty"`
}

func NewCounter

func NewCounter(total float64, labels ...any) (*Sample, error)

Counter type provides a steadily increasing value

func NewFloat

func NewFloat(name string, value float64, labels ...any) (*Sample, error)

Create a new float sample with no timestamp

func NewGauge

func NewGauge(value float64, labels ...any) (*Sample, error)

Gauge type provides a changeable value

func NewInfo

func NewInfo(labels ...any) (*Sample, error)

Info type

func NewInt

func NewInt(name string, value int64, labels ...any) (*Sample, error)

Create a new integer sample with no timestamp

func NewState

func NewState(value bool, labels ...any) (*Sample, error)

State type provides an on/off value

func (*Sample) Write

func (s *Sample) Write(w io.Writer, prefix string) error

Jump to

Keyboard shortcuts

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