coreMonitor

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalMonitor = NewPerformanceMonitor(30 * time.Second)

GlobalMonitor 全局性能监控器实例

Functions

func GetMetrics

func GetMetrics() map[string]*Metric

func RecordDuration

func RecordDuration(name string, duration time.Duration)

RecordDuration 便捷函数

func StartMonitor

func StartMonitor()

func StopMonitor

func StopMonitor()

func TimerFunc

func TimerFunc(name string, fn func() error) error

func TimerFuncWithContext

func TimerFuncWithContext(ctx context.Context, name string, fn func(context.Context) error) error

Types

type Metric

type Metric struct {
	Name      string        `json:"name"`
	Count     int64         `json:"count"`
	TotalTime time.Duration `json:"total_time"`
	AvgTime   time.Duration `json:"avg_time"`
	MaxTime   time.Duration `json:"max_time"`
	MinTime   time.Duration `json:"min_time"`
	LastTime  time.Time     `json:"last_time"`
}

Metric 性能指标

type PerformanceMonitor

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

PerformanceMonitor 性能监控器

func NewPerformanceMonitor

func NewPerformanceMonitor(interval time.Duration) *PerformanceMonitor

NewPerformanceMonitor 创建性能监控器

func (*PerformanceMonitor) GetMetrics

func (pm *PerformanceMonitor) GetMetrics() map[string]*Metric

GetMetrics 获取所有指标

func (*PerformanceMonitor) RecordDuration

func (pm *PerformanceMonitor) RecordDuration(name string, duration time.Duration)

RecordDuration 记录执行时间

func (*PerformanceMonitor) Start

func (pm *PerformanceMonitor) Start()

Start 启动监控

func (*PerformanceMonitor) Stop

func (pm *PerformanceMonitor) Stop()

Stop 停止监控

func (*PerformanceMonitor) TimerFunc

func (pm *PerformanceMonitor) TimerFunc(name string, fn func() error) error

TimerFunc 计时器函数装饰器

func (*PerformanceMonitor) TimerFuncWithContext

func (pm *PerformanceMonitor) TimerFuncWithContext(ctx context.Context, name string, fn func(context.Context) error) error

TimerFuncWithContext 带上下文的计时器函数装饰器

Jump to

Keyboard shortcuts

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