Set default for topprocs collector to Top2 processes if no config is given

This commit is contained in:
Thomas Roehl 2021-11-26 18:19:26 +01:00
parent f5b7da5046
commit 8d643bb5e8

View File

@ -12,6 +12,7 @@ import (
) )
const MAX_NUM_PROCS = 10 const MAX_NUM_PROCS = 10
const DEFAULT_NUM_PROCS = 2
type TopProcsCollectorConfig struct { type TopProcsCollectorConfig struct {
num_procs int `json:"num_procs"` num_procs int `json:"num_procs"`
@ -32,6 +33,8 @@ func (m *TopProcsCollector) Init(config []byte) error {
if err != nil { if err != nil {
return err return err
} }
} else {
m.config.num_procs = int(DEFAULT_NUM_PROCS)
} }
if m.config.num_procs <= 0 || m.config.num_procs > MAX_NUM_PROCS { if m.config.num_procs <= 0 || m.config.num_procs > MAX_NUM_PROCS {
return errors.New(fmt.Sprintf("num_procs option must be set in 'topprocs' config (range: 1-%d)", MAX_NUM_PROCS)) return errors.New(fmt.Sprintf("num_procs option must be set in 'topprocs' config (range: 1-%d)", MAX_NUM_PROCS))