Allow hard and soft limiting a process

A hard limit will kill the process as soon as either CPU or memory
consumption are above a defined limit for a certain amount of time.

A soft limit will throttle the CPU usage if above a defined limit and
kill the process if memory consumption is above a defined limit. The
soft limit can be enabled/disabled on demand.

The default is hard limit.
This commit is contained in:
Ingo Oppermann
2023-04-26 16:01:50 +02:00
parent d73d915e89
commit d59158de03
10 changed files with 344 additions and 159 deletions

View File

@@ -52,3 +52,29 @@ func (p *nullParser) Stop(string, Usage) {}
func (p *nullParser) ResetStats() {}
func (p *nullParser) ResetLog() {}
func (p *nullParser) Log() []Line { return []Line{} }
type bufferParser struct {
log []Line
}
// NewBufferParser returns a dummy parser that is just storing
// the lines and returns progress.
func NewBufferParser() Parser {
return &bufferParser{}
}
var _ Parser = &bufferParser{}
func (p *bufferParser) Parse(line string) uint64 {
p.log = append(p.log, Line{
Timestamp: time.Now(),
Data: line,
})
return 1
}
func (p *bufferParser) Stop(string, Usage) {}
func (p *bufferParser) ResetStats() {}
func (p *bufferParser) ResetLog() {
p.log = []Line{}
}
func (p *bufferParser) Log() []Line { return p.log }