mirror of
https://github.com/datarhei/core.git
synced 2025-10-05 16:07:07 +08:00
Fix wrong memory limit, add total memory, add cpu and memory consumed by core itself to node resources
This commit is contained in:
@@ -22,8 +22,11 @@ type ClusterNodeResources struct {
|
|||||||
NCPU float64 // Number of CPU on this node
|
NCPU float64 // Number of CPU on this node
|
||||||
CPU float64 // Current CPU load, 0-100*ncpu
|
CPU float64 // Current CPU load, 0-100*ncpu
|
||||||
CPULimit float64 // Defined CPU load limit, 0-100*ncpu
|
CPULimit float64 // Defined CPU load limit, 0-100*ncpu
|
||||||
|
CPUCore float64 // Current CPU load of the core itself, 0-100*ncpu
|
||||||
Mem uint64 // Currently used memory in bytes
|
Mem uint64 // Currently used memory in bytes
|
||||||
MemLimit uint64 // Defined memory limit in bytes
|
MemLimit uint64 // Defined memory limit in bytes
|
||||||
|
MemTotal uint64 // Total available memory in bytes
|
||||||
|
MemCore uint64 // Current used memory of the core itself in bytes
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,8 +148,11 @@ func (c *cluster) About() (ClusterAbout, error) {
|
|||||||
NCPU: nodeAbout.Resources.NCPU,
|
NCPU: nodeAbout.Resources.NCPU,
|
||||||
CPU: nodeAbout.Resources.CPU,
|
CPU: nodeAbout.Resources.CPU,
|
||||||
CPULimit: nodeAbout.Resources.CPULimit,
|
CPULimit: nodeAbout.Resources.CPULimit,
|
||||||
|
CPUCore: nodeAbout.Resources.CPUCore,
|
||||||
Mem: nodeAbout.Resources.Mem,
|
Mem: nodeAbout.Resources.Mem,
|
||||||
MemLimit: nodeAbout.Resources.MemLimit,
|
MemLimit: nodeAbout.Resources.MemLimit,
|
||||||
|
MemTotal: nodeAbout.Resources.MemTotal,
|
||||||
|
MemCore: nodeAbout.Resources.MemCore,
|
||||||
Error: nodeAbout.Resources.Error,
|
Error: nodeAbout.Resources.Error,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -187,8 +187,11 @@ func (a *api) About(c echo.Context) error {
|
|||||||
NCPU: resources.CPU.NCPU,
|
NCPU: resources.CPU.NCPU,
|
||||||
CPU: (100 - resources.CPU.Idle) * resources.CPU.NCPU,
|
CPU: (100 - resources.CPU.Idle) * resources.CPU.NCPU,
|
||||||
CPULimit: resources.CPU.Limit * resources.CPU.NCPU,
|
CPULimit: resources.CPU.Limit * resources.CPU.NCPU,
|
||||||
|
CPUCore: resources.CPU.Core * resources.CPU.NCPU,
|
||||||
Mem: resources.Mem.Total - resources.Mem.Available,
|
Mem: resources.Mem.Total - resources.Mem.Available,
|
||||||
MemLimit: resources.Mem.Total,
|
MemLimit: resources.Mem.Limit,
|
||||||
|
MemTotal: resources.Mem.Total,
|
||||||
|
MemCore: resources.Mem.Core,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -88,8 +88,11 @@ type AboutResponseResources struct {
|
|||||||
NCPU float64 `json:"ncpu"` // Number of CPU on this node
|
NCPU float64 `json:"ncpu"` // Number of CPU on this node
|
||||||
CPU float64 `json:"cpu"` // Current CPU load, 0-100*ncpu
|
CPU float64 `json:"cpu"` // Current CPU load, 0-100*ncpu
|
||||||
CPULimit float64 `json:"cpu_limit"` // Defined CPU load limit, 0-100*ncpu
|
CPULimit float64 `json:"cpu_limit"` // Defined CPU load limit, 0-100*ncpu
|
||||||
|
CPUCore float64 `json:"cpu_core"` // Current CPU load of the core itself, 0-100*ncpu
|
||||||
Mem uint64 `json:"memory_bytes"` // Currently used memory in bytes
|
Mem uint64 `json:"memory_bytes"` // Currently used memory in bytes
|
||||||
MemLimit uint64 `json:"memory_limit_bytes"` // Defined memory limit in bytes
|
MemLimit uint64 `json:"memory_limit_bytes"` // Defined memory limit in bytes
|
||||||
|
MemTotal uint64 `json:"memory_total_bytes"` // Total available memory in bytes
|
||||||
|
MemCore uint64 `json:"memory_core_bytes"` // Current used memory of the core itself in bytes
|
||||||
Error string `json:"error"` // Last error
|
Error string `json:"error"` // Last error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -143,8 +143,11 @@ type Resources struct {
|
|||||||
NCPU float64 // Number of CPU on this node
|
NCPU float64 // Number of CPU on this node
|
||||||
CPU float64 // Current CPU load, 0-100*ncpu
|
CPU float64 // Current CPU load, 0-100*ncpu
|
||||||
CPULimit float64 // Defined CPU load limit, 0-100*ncpu
|
CPULimit float64 // Defined CPU load limit, 0-100*ncpu
|
||||||
|
CPUCore float64 // Current CPU load of the core itself, 0-100*ncpu
|
||||||
Mem uint64 // Currently used memory in bytes
|
Mem uint64 // Currently used memory in bytes
|
||||||
MemLimit uint64 // Defined memory limit in bytes
|
MemLimit uint64 // Defined memory limit in bytes
|
||||||
|
MemTotal uint64 // Total available memory in bytes
|
||||||
|
MemCore uint64 // Current used memory of the core itself in bytes
|
||||||
Error error // Last error
|
Error error // Last error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,8 +506,11 @@ func (n *Node) ping(ctx context.Context, interval time.Duration) {
|
|||||||
NCPU: about.Resources.NCPU,
|
NCPU: about.Resources.NCPU,
|
||||||
CPU: about.Resources.CPU,
|
CPU: about.Resources.CPU,
|
||||||
CPULimit: about.Resources.CPULimit,
|
CPULimit: about.Resources.CPULimit,
|
||||||
|
CPUCore: about.Resources.CPUCore,
|
||||||
Mem: about.Resources.Mem,
|
Mem: about.Resources.Mem,
|
||||||
MemLimit: about.Resources.MemLimit,
|
MemLimit: about.Resources.MemLimit,
|
||||||
|
MemTotal: about.Resources.MemTotal,
|
||||||
|
MemCore: about.Resources.MemCore,
|
||||||
Error: nil,
|
Error: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -43,8 +43,11 @@ type ClusterNodeResources struct {
|
|||||||
NCPU float64 `json:"ncpu"`
|
NCPU float64 `json:"ncpu"`
|
||||||
CPU float64 `json:"cpu_used"` // percent 0-100*npcu
|
CPU float64 `json:"cpu_used"` // percent 0-100*npcu
|
||||||
CPULimit float64 `json:"cpu_limit"` // percent 0-100*npcu
|
CPULimit float64 `json:"cpu_limit"` // percent 0-100*npcu
|
||||||
|
CPUCore float64 `json:"cpu_core"` // percent 0-100*ncpu
|
||||||
Mem uint64 `json:"memory_used_bytes"` // bytes
|
Mem uint64 `json:"memory_used_bytes"` // bytes
|
||||||
MemLimit uint64 `json:"memory_limit_bytes"` // bytes
|
MemLimit uint64 `json:"memory_limit_bytes"` // bytes
|
||||||
|
MemTotal uint64 `json:"memory_total_bytes"` // bytes
|
||||||
|
MemCore uint64 `json:"memory_core_bytes"` // bytes
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -118,8 +118,11 @@ func (h *ClusterHandler) marshalClusterNode(node cluster.ClusterNode) api.Cluste
|
|||||||
NCPU: node.Resources.NCPU,
|
NCPU: node.Resources.NCPU,
|
||||||
CPU: node.Resources.CPU,
|
CPU: node.Resources.CPU,
|
||||||
CPULimit: node.Resources.CPULimit,
|
CPULimit: node.Resources.CPULimit,
|
||||||
|
CPUCore: node.Resources.CPUCore,
|
||||||
Mem: node.Resources.Mem,
|
Mem: node.Resources.Mem,
|
||||||
MemLimit: node.Resources.MemLimit,
|
MemLimit: node.Resources.MemLimit,
|
||||||
|
MemTotal: node.Resources.MemTotal,
|
||||||
|
MemCore: node.Resources.MemCore,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ package resources
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ type MemoryInfo struct {
|
|||||||
Available uint64 // bytes
|
Available uint64 // bytes
|
||||||
Used uint64 // bytes
|
Used uint64 // bytes
|
||||||
Limit uint64 // bytes
|
Limit uint64 // bytes
|
||||||
|
Core uint64 // bytes
|
||||||
Throttling bool
|
Throttling bool
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
@@ -31,6 +33,7 @@ type CPUInfo struct {
|
|||||||
Idle float64 // percent 0-100
|
Idle float64 // percent 0-100
|
||||||
Other float64 // percent 0-100
|
Other float64 // percent 0-100
|
||||||
Limit float64 // percent 0-100
|
Limit float64 // percent 0-100
|
||||||
|
Core float64 // percent 0-100
|
||||||
Throttling bool
|
Throttling bool
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
@@ -46,6 +49,8 @@ type resources struct {
|
|||||||
isCPULimiting bool
|
isCPULimiting bool
|
||||||
isMemoryLimiting bool
|
isMemoryLimiting bool
|
||||||
|
|
||||||
|
self psutil.Process
|
||||||
|
|
||||||
cancelObserver context.CancelFunc
|
cancelObserver context.CancelFunc
|
||||||
|
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
@@ -137,6 +142,11 @@ func New(config Config) (Resources, error) {
|
|||||||
"max_memory": r.maxMemory,
|
"max_memory": r.maxMemory,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
r.self, err = psutil.NewProcess(int32(os.Getpid()), false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to create process observer for self: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
r.logger.Debug().Log("Created")
|
r.logger.Debug().Log("Created")
|
||||||
|
|
||||||
r.stopOnce.Do(func() {})
|
r.stopOnce.Do(func() {})
|
||||||
@@ -160,6 +170,7 @@ func (r *resources) Start() {
|
|||||||
func (r *resources) Stop() {
|
func (r *resources) Stop() {
|
||||||
r.stopOnce.Do(func() {
|
r.stopOnce.Do(func() {
|
||||||
r.cancelObserver()
|
r.cancelObserver()
|
||||||
|
r.self.Stop()
|
||||||
|
|
||||||
r.startOnce = sync.Once{}
|
r.startOnce = sync.Once{}
|
||||||
|
|
||||||
@@ -326,6 +337,8 @@ func (r *resources) Info() Info {
|
|||||||
|
|
||||||
cpustat, cpuerr := r.psutil.CPUPercent()
|
cpustat, cpuerr := r.psutil.CPUPercent()
|
||||||
memstat, memerr := r.psutil.VirtualMemory()
|
memstat, memerr := r.psutil.VirtualMemory()
|
||||||
|
selfcpu, _ := r.self.CPUPercent()
|
||||||
|
selfmem, _ := r.self.VirtualMemory()
|
||||||
|
|
||||||
cpuinfo := CPUInfo{
|
cpuinfo := CPUInfo{
|
||||||
NCPU: r.ncpu,
|
NCPU: r.ncpu,
|
||||||
@@ -334,6 +347,7 @@ func (r *resources) Info() Info {
|
|||||||
Idle: cpustat.Idle,
|
Idle: cpustat.Idle,
|
||||||
Other: cpustat.Other,
|
Other: cpustat.Other,
|
||||||
Limit: cpulimit,
|
Limit: cpulimit,
|
||||||
|
Core: selfcpu.System + selfcpu.User + selfcpu.Other,
|
||||||
Throttling: cputhrottling,
|
Throttling: cputhrottling,
|
||||||
Error: cpuerr,
|
Error: cpuerr,
|
||||||
}
|
}
|
||||||
@@ -343,6 +357,7 @@ func (r *resources) Info() Info {
|
|||||||
Available: memstat.Available,
|
Available: memstat.Available,
|
||||||
Used: memstat.Used,
|
Used: memstat.Used,
|
||||||
Limit: memlimit,
|
Limit: memlimit,
|
||||||
|
Core: selfmem,
|
||||||
Throttling: memthrottling,
|
Throttling: memthrottling,
|
||||||
Error: memerr,
|
Error: memerr,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user