| package performance_setting |
|
|
| import ( |
| "github.com/QuantumNous/new-api/common" |
| "github.com/QuantumNous/new-api/setting/config" |
| ) |
|
|
| |
| type PerformanceSetting struct { |
| |
| DiskCacheEnabled bool `json:"disk_cache_enabled"` |
| |
| DiskCacheThresholdMB int `json:"disk_cache_threshold_mb"` |
| |
| DiskCacheMaxSizeMB int `json:"disk_cache_max_size_mb"` |
| |
| DiskCachePath string `json:"disk_cache_path"` |
|
|
| |
| MonitorEnabled bool `json:"monitor_enabled"` |
| |
| MonitorCPUThreshold int `json:"monitor_cpu_threshold"` |
| |
| MonitorMemoryThreshold int `json:"monitor_memory_threshold"` |
| |
| MonitorDiskThreshold int `json:"monitor_disk_threshold"` |
| } |
|
|
| |
| var performanceSetting = PerformanceSetting{ |
| DiskCacheEnabled: false, |
| DiskCacheThresholdMB: 10, |
| DiskCacheMaxSizeMB: 1024, |
| DiskCachePath: "", |
|
|
| MonitorEnabled: true, |
| MonitorCPUThreshold: 90, |
| MonitorMemoryThreshold: 90, |
| MonitorDiskThreshold: 90, |
| } |
|
|
| func init() { |
| |
| config.GlobalConfig.Register("performance_setting", &performanceSetting) |
| |
| syncToCommon() |
| } |
|
|
| |
| func syncToCommon() { |
| common.SetDiskCacheConfig(common.DiskCacheConfig{ |
| Enabled: performanceSetting.DiskCacheEnabled, |
| ThresholdMB: performanceSetting.DiskCacheThresholdMB, |
| MaxSizeMB: performanceSetting.DiskCacheMaxSizeMB, |
| Path: performanceSetting.DiskCachePath, |
| }) |
|
|
| common.SetPerformanceMonitorConfig(common.PerformanceMonitorConfig{ |
| Enabled: performanceSetting.MonitorEnabled, |
| CPUThreshold: performanceSetting.MonitorCPUThreshold, |
| MemoryThreshold: performanceSetting.MonitorMemoryThreshold, |
| DiskThreshold: performanceSetting.MonitorDiskThreshold, |
| }) |
| } |
|
|
| |
| func GetPerformanceSetting() *PerformanceSetting { |
| return &performanceSetting |
| } |
|
|
| |
| |
| func UpdateAndSync() { |
| syncToCommon() |
| } |
|
|
| |
| func GetCacheStats() common.DiskCacheStats { |
| return common.GetDiskCacheStats() |
| } |
|
|
| |
| func ResetStats() { |
| common.ResetDiskCacheStats() |
| } |
|
|