performance_config.go 808 B

123456789101112131415161718192021222324252627282930313233
  1. package common
  2. import "sync/atomic"
  3. // PerformanceMonitorConfig 性能监控配置
  4. type PerformanceMonitorConfig struct {
  5. Enabled bool
  6. CPUThreshold int
  7. MemoryThreshold int
  8. DiskThreshold int
  9. }
  10. var performanceMonitorConfig atomic.Value
  11. func init() {
  12. // 初始化默认配置
  13. performanceMonitorConfig.Store(PerformanceMonitorConfig{
  14. Enabled: true,
  15. CPUThreshold: 90,
  16. MemoryThreshold: 90,
  17. DiskThreshold: 90,
  18. })
  19. }
  20. // GetPerformanceMonitorConfig 获取性能监控配置
  21. func GetPerformanceMonitorConfig() PerformanceMonitorConfig {
  22. return performanceMonitorConfig.Load().(PerformanceMonitorConfig)
  23. }
  24. // SetPerformanceMonitorConfig 设置性能监控配置
  25. func SetPerformanceMonitorConfig(config PerformanceMonitorConfig) {
  26. performanceMonitorConfig.Store(config)
  27. }