diff options
author | Austin S. Hemmelgarn <austin@netdata.cloud> | 2024-02-13 06:56:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-13 06:56:20 -0500 |
commit | 3a29b66132f561c910d827e8c7ae82997f7c1f30 (patch) | |
tree | a9306156631b6b188de8877f7c1dbdbe8b067804 /src/go/collectors/go.d.plugin/modules/supervisord/supervisord.go | |
parent | 57eec3da0e51baa400037ccc4b547cb839ab6ffa (diff) |
Include Go plugin sources in main repository. (#16997)
* Include Go plugin sources in main repository.
* Fix CI issues.
* Rename source tree.
Diffstat (limited to 'src/go/collectors/go.d.plugin/modules/supervisord/supervisord.go')
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/supervisord/supervisord.go | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/supervisord/supervisord.go b/src/go/collectors/go.d.plugin/modules/supervisord/supervisord.go new file mode 100644 index 0000000000..1c99947109 --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/supervisord/supervisord.go @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package supervisord + +import ( + _ "embed" + "time" + + "github.com/netdata/go.d.plugin/agent/module" + "github.com/netdata/go.d.plugin/pkg/web" +) + +//go:embed "config_schema.json" +var configSchema string + +func init() { + module.Register("supervisord", module.Creator{ + JobConfigSchema: configSchema, + Create: func() module.Module { return New() }, + }) +} + +func New() *Supervisord { + return &Supervisord{ + Config: Config{ + URL: "http://127.0.0.1:9001/RPC2", + Client: web.Client{ + Timeout: web.Duration{Duration: time.Second}, + }, + }, + + charts: summaryCharts.Copy(), + cache: make(map[string]map[string]bool), + } +} + +type Config struct { + URL string `yaml:"url"` + web.Client `yaml:",inline"` +} + +type ( + Supervisord struct { + module.Base + Config `yaml:",inline"` + + client supervisorClient + charts *module.Charts + + cache map[string]map[string]bool // map[group][procName]collected + } + supervisorClient interface { + getAllProcessInfo() ([]processStatus, error) + closeIdleConnections() + } +) + +func (s *Supervisord) Init() bool { + err := s.verifyConfig() + if err != nil { + s.Errorf("verify config: %v", err) + return false + } + + client, err := s.initSupervisorClient() + if err != nil { + s.Errorf("init supervisord client: %v", err) + return false + } + s.client = client + + return true +} + +func (s *Supervisord) Check() bool { + return len(s.Collect()) > 0 +} + +func (s *Supervisord) Charts() *module.Charts { + return s.charts +} + +func (s *Supervisord) Collect() map[string]int64 { + ms, err := s.collect() + if err != nil { + s.Error(err) + } + + if len(ms) == 0 { + return nil + } + return ms +} + +func (s *Supervisord) Cleanup() { + if s.client != nil { + s.client.closeIdleConnections() + } +} |