Add resource manager

This commit is contained in:
Ingo Oppermann
2023-04-27 17:02:20 +02:00
parent b723f4e5fd
commit 7527f7833b
8 changed files with 274 additions and 48 deletions

View File

@@ -271,7 +271,12 @@ func New(config Config) (Process, error) {
Memory: config.LimitMemory,
WaitFor: config.LimitDuration,
Mode: config.LimitMode,
Logger: p.logger.WithComponent("ProcessLimiter"),
OnLimit: func(cpu float64, memory uint64) {
if !p.isRunning() {
return
}
p.logger.WithFields(log.Fields{
"cpu": cpu,
"memory": memory,
@@ -455,6 +460,16 @@ func (p *process) IsRunning() bool {
}
func (p *process) Limit(enable bool) error {
if !p.isRunning() {
return nil
}
if p.limits == nil {
return nil
}
p.logger.Warn().WithField("limit", enable).Log("Limiter triggered")
return p.limits.Limit(enable)
}