Documentation
¶
Index ¶
- Variables
- func GetMetrics() map[string]*Metric
- func RecordDuration(name string, duration time.Duration)
- func StartMonitor()
- func StopMonitor()
- func TimerFunc(name string, fn func() error) error
- func TimerFuncWithContext(ctx context.Context, name string, fn func(context.Context) error) error
- type Metric
- type PerformanceMonitor
- func (pm *PerformanceMonitor) GetMetrics() map[string]*Metric
- func (pm *PerformanceMonitor) RecordDuration(name string, duration time.Duration)
- func (pm *PerformanceMonitor) Start()
- func (pm *PerformanceMonitor) Stop()
- func (pm *PerformanceMonitor) TimerFunc(name string, fn func() error) error
- func (pm *PerformanceMonitor) TimerFuncWithContext(ctx context.Context, name string, fn func(context.Context) error) error
Constants ¶
This section is empty.
Variables ¶
View Source
var GlobalMonitor = NewPerformanceMonitor(30 * time.Second)
GlobalMonitor 全局性能监控器实例
Functions ¶
func GetMetrics ¶
func StartMonitor ¶
func StartMonitor()
func StopMonitor ¶
func StopMonitor()
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) 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 带上下文的计时器函数装饰器
Click to show internal directories.
Click to hide internal directories.