mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-18 16:07:10 +00:00
Fix RAM Usage Get
This commit is contained in:
parent
2b90e9b580
commit
9ff39ee241
@ -44,7 +44,16 @@ type CPUResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MemoryResponse struct {
|
type MemoryResponse struct {
|
||||||
Percent float64 `json:"percent"`
|
Active int64 `json:"active"`
|
||||||
|
Available int64 `json:"available"`
|
||||||
|
Buffers int64 `json:"buffers"`
|
||||||
|
Cached int64 `json:"cached"`
|
||||||
|
Free int64 `json:"free"`
|
||||||
|
Inactive int64 `json:"inactive"`
|
||||||
|
Percent float64 `json:"percent"`
|
||||||
|
Shared int64 `json:"shared"`
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
Used int64 `json:"used"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FSResponse []struct {
|
type FSResponse []struct {
|
||||||
@ -447,7 +456,23 @@ func checkAndUpdateServerStatus(db *sql.DB, client *http.Client, servers []Serve
|
|||||||
updateServerStatus(db, server.ID, false, 0, 0, 0)
|
updateServerStatus(db, server.ID, false, 0, 0, 0)
|
||||||
online = false
|
online = false
|
||||||
} else {
|
} else {
|
||||||
ramUsage = memData.Percent
|
// Calculate actual RAM usage excluding swap, cache, and buffers
|
||||||
|
// Formula: (total - free - cached - buffers) / total * 100
|
||||||
|
// This is the most accurate representation of actual used RAM
|
||||||
|
actualUsedRam := memData.Total - memData.Free - memData.Cached - memData.Buffers
|
||||||
|
if actualUsedRam < 0 {
|
||||||
|
actualUsedRam = 0 // Safeguard against negative values
|
||||||
|
}
|
||||||
|
|
||||||
|
if memData.Total > 0 {
|
||||||
|
ramUsage = float64(actualUsedRam) / float64(memData.Total) * 100
|
||||||
|
fmt.Printf("%s Calculated RAM usage: %.2f%% (Used: %d MB, Total: %d MB)\n",
|
||||||
|
logPrefix, ramUsage, actualUsedRam/1024/1024, memData.Total/1024/1024)
|
||||||
|
} else {
|
||||||
|
// Fallback to the provided percentage if calculation fails
|
||||||
|
ramUsage = memData.Percent
|
||||||
|
fmt.Printf("%s Using provided memory percentage because total is zero\n", logPrefix)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user