diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 11:19:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-24 09:53:24 +0000 |
commit | b5f8ee61a7f7e9bd291dd26b0585d03eb686c941 (patch) | |
tree | d4d31289c39fc00da064a825df13a0b98ce95b10 /src/go/collectors/go.d.plugin/agent/config.go | |
parent | Adding upstream version 1.44.3. (diff) | |
download | netdata-b5f8ee61a7f7e9bd291dd26b0585d03eb686c941.tar.xz netdata-b5f8ee61a7f7e9bd291dd26b0585d03eb686c941.zip |
Adding upstream version 1.46.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/go/collectors/go.d.plugin/agent/config.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/agent/config.go b/src/go/collectors/go.d.plugin/agent/config.go new file mode 100644 index 000000000..fef68c7e0 --- /dev/null +++ b/src/go/collectors/go.d.plugin/agent/config.go @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package agent + +import ( + "fmt" + + "gopkg.in/yaml.v2" +) + +func defaultConfig() config { + return config{ + Enabled: true, + DefaultRun: true, + MaxProcs: 0, + Modules: nil, + } +} + +type config struct { + Enabled bool `yaml:"enabled"` + DefaultRun bool `yaml:"default_run"` + MaxProcs int `yaml:"max_procs"` + Modules map[string]bool `yaml:"modules"` +} + +func (c *config) String() string { + return fmt.Sprintf("enabled '%v', default_run '%v', max_procs '%d'", + c.Enabled, c.DefaultRun, c.MaxProcs) +} + +func (c *config) isExplicitlyEnabled(moduleName string) bool { + return c.isEnabled(moduleName, true) +} + +func (c *config) isImplicitlyEnabled(moduleName string) bool { + return c.isEnabled(moduleName, false) +} + +func (c *config) isEnabled(moduleName string, explicit bool) bool { + if enabled, ok := c.Modules[moduleName]; ok { + return enabled + } + if explicit { + return false + } + return c.DefaultRun +} + +func (c *config) UnmarshalYAML(unmarshal func(interface{}) error) error { + type plain config + if err := unmarshal((*plain)(c)); err != nil { + return err + } + + var m map[string]interface{} + if err := unmarshal(&m); err != nil { + return err + } + + for key, value := range m { + switch key { + case "enabled", "default_run", "max_procs", "modules": + continue + } + var b bool + if in, err := yaml.Marshal(value); err != nil || yaml.Unmarshal(in, &b) != nil { + continue + } + if c.Modules == nil { + c.Modules = make(map[string]bool) + } + c.Modules[key] = b + } + return nil +} |