mmetric

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

Package mmetric 提供指标收集和监控的抽象接口

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEnabled

func IsEnabled() bool

IsEnabled checks if metric collection is enabled

func SetEnabled

func SetEnabled(e bool)

SetEnabled sets whether metric collection is enabled

func SetProvider

func SetProvider(provider Provider)

SetProvider sets the active provider

func Shutdown

func Shutdown(ctx context.Context) error

Shutdown shuts down the provider

Types

type AttributeMap

type AttributeMap map[string]interface{}

AttributeMap is a map of attributes, supports multiple types of values

func (AttributeMap) Pick

func (m AttributeMap) Pick(keys ...string) AttributeMap

Pick picks specific attributes

func (AttributeMap) Sets

func (m AttributeMap) Sets(attrs AttributeMap)

Sets sets multiple attributes

type Attributes

type Attributes map[string]string

Attributes is a list of attributes, key-value pairs

type Counter

type Counter interface {
	Add(ctx context.Context, value float64, opts ...Option) // Add adds a specified value
	Inc(ctx context.Context, opts ...Option)                // Inc increments the counter by 1
}

Counter is the interface for counters

func NewCounter

func NewCounter(name string, option MetricOption) (Counter, error)

NewCounter creates a counter

func NewMustCounter

func NewMustCounter(name string, option MetricOption) Counter

NewMustCounter creates a counter, panics if it fails

type Histogram

type Histogram interface {
	Record(value float64, opts ...Option) // Record records a value
}

Histogram is the interface for histograms

func NewHistogram

func NewHistogram(name string, option MetricOption) (Histogram, error)

NewHistogram creates a histogram

func NewMustHistogram

func NewMustHistogram(name string, option MetricOption) Histogram

NewMustHistogram creates a histogram, panics if it fails

type Meter

type Meter interface {
	Counter(name string, option MetricOption) (Counter, error)             // Counter creates a counter
	MustCounter(name string, option MetricOption) Counter                  // MustCounter creates a counter, panics if creation fails
	UpDownCounter(name string, option MetricOption) (UpDownCounter, error) // UpDownCounter creates an up-down counter
	MustUpDownCounter(name string, option MetricOption) UpDownCounter      // MustUpDownCounter creates an up-down counter, panics if creation fails
	Histogram(name string, option MetricOption) (Histogram, error)         // Histogram creates a histogram
	MustHistogram(name string, option MetricOption) Histogram              // MustHistogram creates a histogram, panics if creation fails
}

Meter is the interface for meters

func GetMeter

func GetMeter(name string) Meter

GetMeter gets the meter with the specified name

type MeterOption

type MeterOption struct {
	Instrument        string     // Instrument name
	InstrumentVersion string     // Instrument version
	Attributes        Attributes // Attributes
}

MeterOption is the option for meters

func NewMeterOption

func NewMeterOption() MeterOption

NewMeterOption creates a new meter option

func (MeterOption) WithInstrument

func (o MeterOption) WithInstrument(instrument string) MeterOption

WithInstrument sets the instrument name

func (MeterOption) WithInstrumentVersion

func (o MeterOption) WithInstrumentVersion(version string) MeterOption

WithInstrumentVersion sets the instrument version

func (MeterOption) WithMeterAttributes

func (o MeterOption) WithMeterAttributes(attrs Attributes) MeterOption

WithMeterAttributes sets the attributes

type MetricOption

type MetricOption struct {
	Help       string     // Help information
	Unit       string     // Unit
	Attributes Attributes // Attributes
	Buckets    []float64  // Buckets (may not be supported by all implementations)
}

MetricOption is the option for metrics

func NewMetricOption

func NewMetricOption() MetricOption

NewMetricOption creates a new metric option

func (MetricOption) WithBuckets

func (o MetricOption) WithBuckets(buckets []float64) MetricOption

WithBuckets sets the histogram buckets

func (MetricOption) WithHelp

func (o MetricOption) WithHelp(help string) MetricOption

WithHelp sets the help information

func (MetricOption) WithMetricAttributes

func (o MetricOption) WithMetricAttributes(attrs Attributes) MetricOption

WithMetricAttributes sets the attributes

func (MetricOption) WithUnit

func (o MetricOption) WithUnit(unit string) MetricOption

WithUnit sets the unit

type Option

type Option struct {
	Attributes AttributeMap // Attributes map
}

Option is the option for recording metrics

func NewOption

func NewOption() Option

NewOption creates a new option

func (Option) WithOptionAttributes

func (o Option) WithOptionAttributes(attrs AttributeMap) Option

WithOptionAttributes sets the attributes

type Provider

type Provider interface {
	Meter(option MeterOption) Meter     // Meter creates a meter
	Shutdown(ctx context.Context) error // Shutdown shuts down the provider
}

Provider is the interface for metric providers

func GetProvider

func GetProvider() Provider

GetProvider gets the current active provider

func NewNoopProvider added in v0.1.2

func NewNoopProvider() Provider

NewNoopProvider creates a new noop provider

type UpDownCounter

type UpDownCounter interface {
	Add(ctx context.Context, value float64, opts ...Option) // Add adds a specified value (can be negative)
	Inc(ctx context.Context, opts ...Option)                // Inc increments the counter by 1
	Dec(ctx context.Context, opts ...Option)                // Dec decrements the counter by 1
}

UpDownCounter is the interface for up-down counters

func NewMustUpDownCounter

func NewMustUpDownCounter(name string, option MetricOption) UpDownCounter

NewMustUpDownCounter creates an up-down counter, panics if it fails

func NewUpDownCounter

func NewUpDownCounter(name string, option MetricOption) (UpDownCounter, error)

NewUpDownCounter creates an up-down counter

Jump to

Keyboard shortcuts

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