metrics

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client(opts ...Option) middleware.Middleware

Client 返回一个客户端指标中间件

func Server

func Server(opts ...Option) middleware.Middleware

Server 返回一个服务端指标中间件

Types

type Counter added in v0.1.0

type Counter interface {
	// Inc 增加1
	Inc()
	// Add 增加给定值
	Add(float64)
}

Counter 计数器接口

type CounterOptions added in v0.1.0

type CounterOptions struct {
	Name   string            // 指标名称
	Help   string            // 指标帮助信息
	Labels map[string]string // 指标标签
}

CounterOptions 计数器选项

type CounterVec added in v0.1.0

type CounterVec interface {
	// With 使用标签获取Counter
	With(map[string]string) Counter
}

CounterVec 带标签的计数器接口

type Gauge added in v0.1.0

type Gauge interface {
	// Set 设置值
	Set(float64)
	// Inc 增加1
	Inc()
	// Dec 减少1
	Dec()
	// Add 增加给定值
	Add(float64)
	// Sub 减少给定值
	Sub(float64)
	// SetToCurrentTime 设置为当前时间戳
	SetToCurrentTime()
}

Gauge 仪表盘接口

type GaugeOptions added in v0.1.0

type GaugeOptions struct {
	Name   string            // 指标名称
	Help   string            // 指标帮助信息
	Labels map[string]string // 指标标签
}

GaugeOptions 仪表盘选项

type GaugeVec added in v0.1.0

type GaugeVec interface {
	// With 使用标签获取Gauge
	With(map[string]string) Gauge
}

GaugeVec 带标签的仪表盘接口

type Histogram added in v0.1.0

type Histogram interface {
	// Observe 观察值
	Observe(float64)
}

Histogram 直方图接口

type HistogramOptions added in v0.1.0

type HistogramOptions struct {
	Name    string            // 指标名称
	Help    string            // 指标帮助信息
	Labels  map[string]string // 指标标签
	Buckets []float64         // 桶数组
}

HistogramOptions 直方图选项

type HistogramVec added in v0.1.0

type HistogramVec interface {
	// With 使用标签获取Histogram
	With(map[string]string) Histogram
}

HistogramVec 带标签的直方图接口

type Metrics

type Metrics interface {
	// Counter 计数器
	Counter(name string, value float64, labels map[string]string)
	// Gauge 仪表
	Gauge(name string, value float64, labels map[string]string)
	// Histogram 直方图
	Histogram(name string, value float64, labels map[string]string)

	// CreateCounter 创建计数器
	CreateCounter(opts CounterOptions) Counter
	// CreateCounterVec 创建带标签的计数器
	CreateCounterVec(opts CounterOptions, labelNames []string) CounterVec
	// CreateGauge 创建仪表盘
	CreateGauge(opts GaugeOptions) Gauge
	// CreateGaugeVec 创建带标签的仪表盘
	CreateGaugeVec(opts GaugeOptions, labelNames []string) GaugeVec
	// CreateHistogram 创建直方图
	CreateHistogram(opts HistogramOptions) Histogram
	// CreateHistogramVec 创建带标签的直方图
	CreateHistogramVec(opts HistogramOptions, labelNames []string) HistogramVec
	// CreateSummary 创建摘要
	CreateSummary(opts SummaryOptions) Summary
	// CreateSummaryVec 创建带标签的摘要
	CreateSummaryVec(opts SummaryOptions, labelNames []string) SummaryVec
}

Metrics 是指标收集接口

type Option

type Option func(*options)

Option 是指标中间件的选项

func WithMetrics

func WithMetrics(metrics Metrics) Option

WithMetrics 设置指标收集器

type Summary added in v0.1.0

type Summary interface {
	// Observe 观察值
	Observe(float64)
}

Summary 摘要接口

type SummaryOptions added in v0.1.0

type SummaryOptions struct {
	Name       string              // 指标名称
	Help       string              // 指标帮助信息
	Labels     map[string]string   // 指标标签
	Objectives map[float64]float64 // 分位数
	MaxAge     time.Duration       // 最大存活时间
	AgeBuckets uint32              // 年龄桶数量
	BufCap     uint32              // 缓冲区容量
}

SummaryOptions 摘要选项

type SummaryVec added in v0.1.0

type SummaryVec interface {
	// With 使用标签获取Summary
	With(map[string]string) Summary
}

SummaryVec 带标签的摘要接口

Jump to

Keyboard shortcuts

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