github.com/netdata/go.d.plugin@v0.58.1/modules/supervisord/supervisord.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package supervisord 4 5 import ( 6 _ "embed" 7 "time" 8 9 "github.com/netdata/go.d.plugin/agent/module" 10 "github.com/netdata/go.d.plugin/pkg/web" 11 ) 12 13 //go:embed "config_schema.json" 14 var configSchema string 15 16 func init() { 17 module.Register("supervisord", module.Creator{ 18 JobConfigSchema: configSchema, 19 Create: func() module.Module { return New() }, 20 }) 21 } 22 23 func New() *Supervisord { 24 return &Supervisord{ 25 Config: Config{ 26 URL: "http://127.0.0.1:9001/RPC2", 27 Client: web.Client{ 28 Timeout: web.Duration{Duration: time.Second}, 29 }, 30 }, 31 32 charts: summaryCharts.Copy(), 33 cache: make(map[string]map[string]bool), 34 } 35 } 36 37 type Config struct { 38 URL string `yaml:"url"` 39 web.Client `yaml:",inline"` 40 } 41 42 type ( 43 Supervisord struct { 44 module.Base 45 Config `yaml:",inline"` 46 47 client supervisorClient 48 charts *module.Charts 49 50 cache map[string]map[string]bool // map[group][procName]collected 51 } 52 supervisorClient interface { 53 getAllProcessInfo() ([]processStatus, error) 54 closeIdleConnections() 55 } 56 ) 57 58 func (s *Supervisord) Init() bool { 59 err := s.verifyConfig() 60 if err != nil { 61 s.Errorf("verify config: %v", err) 62 return false 63 } 64 65 client, err := s.initSupervisorClient() 66 if err != nil { 67 s.Errorf("init supervisord client: %v", err) 68 return false 69 } 70 s.client = client 71 72 return true 73 } 74 75 func (s *Supervisord) Check() bool { 76 return len(s.Collect()) > 0 77 } 78 79 func (s *Supervisord) Charts() *module.Charts { 80 return s.charts 81 } 82 83 func (s *Supervisord) Collect() map[string]int64 { 84 ms, err := s.collect() 85 if err != nil { 86 s.Error(err) 87 } 88 89 if len(ms) == 0 { 90 return nil 91 } 92 return ms 93 } 94 95 func (s *Supervisord) Cleanup() { 96 if s.client != nil { 97 s.client.closeIdleConnections() 98 } 99 }