metrics

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package metrics provides in-memory metrics collection for cloudemu services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector collects in-memory metrics.

func NewCollector

func NewCollector() *Collector

NewCollector creates a new Collector.

func (*Collector) All

func (c *Collector) All() []Metric

All returns a copy of all metrics.

func (*Collector) Counter

func (c *Collector) Counter(name string, value float64, labels map[string]string)

Counter increments a counter metric.

func (*Collector) Gauge

func (c *Collector) Gauge(name string, value float64, labels map[string]string)

Gauge records a gauge metric.

func (*Collector) Histogram

func (c *Collector) Histogram(name string, duration time.Duration, labels map[string]string)

Histogram records a duration metric.

func (*Collector) Reset

func (c *Collector) Reset()

Reset clears all collected metrics.

type Metric

type Metric struct {
	Name      string
	Type      MetricType
	Value     float64
	Labels    map[string]string
	Timestamp time.Time
}

Metric is a recorded metric data point.

type MetricType

type MetricType int

MetricType identifies the type of metric.

const (
	CounterType MetricType = iota
	GaugeType
	HistogramType
)

type Query

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

Query provides filtering over collected metrics.

func NewQuery

func NewQuery(c *Collector) *Query

NewQuery creates a Query from a collector.

func (*Query) ByLabel

func (q *Query) ByLabel(key, value string) *Query

ByLabel filters metrics that have the given label key=value.

func (*Query) ByName

func (q *Query) ByName(name string) *Query

ByName filters metrics by name.

func (*Query) ByType

func (q *Query) ByType(t MetricType) *Query

ByType filters metrics by type.

func (*Query) Count

func (q *Query) Count() int

Count returns the number of matching metrics.

func (*Query) Results

func (q *Query) Results() []Metric

Results returns all matching metrics.

func (*Query) Sum

func (q *Query) Sum() float64

Sum returns the sum of all matching metric values.

Jump to

Keyboard shortcuts

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