mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-06 21:11:50 +08:00
fix: cap ARTEX container and tool resource use
This commit is contained in:
1 parent
253a8eeac3
commit
ea4377ef9a
36 files changed
+1869
-64
No files matched your search
@@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/Autumn-27/artex/internal/toolguard"
|
||||
)
|
||||
|
||||
type metricValue struct {
|
||||
@@ -12,15 +14,38 @@ type metricValue struct {
|
||||
Percent float64 `json:"percent"`
|
||||
}
|
||||
|
||||
type resourceLimitsInfo struct {
|
||||
ContainerMemoryLimitBytes uint64 `json:"container_memory_limit_bytes"`
|
||||
ContainerMemoryBounded bool `json:"container_memory_bounded"`
|
||||
ContainerPidsLimit uint64 `json:"container_pids_limit"`
|
||||
ToolMemoryLimitMB int `json:"tool_memory_limit_mb"`
|
||||
ToolTimeoutSeconds int `json:"tool_timeout_seconds"`
|
||||
ToolPidsLimit int `json:"tool_pids_limit"`
|
||||
ToolCgroupAvailable bool `json:"tool_cgroup_available"`
|
||||
ToolRSSWatchdogAvailable bool `json:"tool_rss_watchdog_available"`
|
||||
}
|
||||
|
||||
type systemMetricsResponse struct {
|
||||
Scope string `json:"scope"`
|
||||
Supported bool `json:"supported"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
CPU metricValue `json:"cpu"`
|
||||
Memory metricValue `json:"memory"`
|
||||
Disk metricValue `json:"disk"`
|
||||
DataDisk metricValue `json:"data_disk"`
|
||||
Container bool `json:"container_metrics"`
|
||||
Scope string `json:"scope"`
|
||||
Supported bool `json:"supported"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
CPU metricValue `json:"cpu"`
|
||||
Memory metricValue `json:"memory"`
|
||||
Disk metricValue `json:"disk"`
|
||||
DataDisk metricValue `json:"data_disk"`
|
||||
Container bool `json:"container_metrics"`
|
||||
Limits resourceLimitsInfo `json:"limits"`
|
||||
}
|
||||
|
||||
func toolResourceLimits() resourceLimitsInfo {
|
||||
cfg := toolguard.FromEnv()
|
||||
return resourceLimitsInfo{
|
||||
ToolMemoryLimitMB: cfg.MemoryLimitMB,
|
||||
ToolTimeoutSeconds: int(cfg.Timeout / time.Second),
|
||||
ToolPidsLimit: cfg.PidsLimit,
|
||||
ToolCgroupAvailable: toolguard.CgroupV2Available(),
|
||||
ToolRSSWatchdogAvailable: cfg.RSSWatchdogAvailable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) systemMetrics(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in new issue
Block a user