Skip to content

Commit

Permalink
Rework collector registration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Harvey committed Oct 8, 2015
1 parent 1450df8 commit b35c862
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
5 changes: 0 additions & 5 deletions cmd/scollector/collectors/collectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ var (
}
WatchProcessesDotNet = func() {}

AddSystemdServiceConfig = func(params conf.ServiceParams) error {
return fmt.Errorf("systemd service watching not implemented on this platform")
}
WatchSystemd = func() {}

KeepalivedCommunity = ""
)

Expand Down
31 changes: 16 additions & 15 deletions cmd/scollector/collectors/systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,30 @@ type systemdServiceConfig struct {
var systemdServices []*systemdServiceConfig

func init() {
// The following two func defs have no-op stubs in collectors.go, as they are
// called by main.go, but only functional on Linux environments.
WatchSystemd = func() {
registerInit(func(c *conf.Conf) {
for _, s := range c.SystemdService {
AddSystemdServiceConfig(s)
}
collectors = append(collectors, &IntervalCollector{
F: func() (opentsdb.MultiDataPoint, error) {
return c_systemd()
},
name: "c_systemd",
})
}
})
}

AddSystemdServiceConfig = func(params conf.ServiceParams) error {
if params.Name == "" {
return fmt.Errorf("empty service Name")
}
reg, err := regexp.Compile(params.Name)
if err != nil {
return err
}
serviceConfig := systemdServiceConfig{regex: reg, watch: params.WatchProc}
systemdServices = append(systemdServices, &serviceConfig)
return nil
func AddSystemdServiceConfig(params conf.ServiceParams) error {
if params.Name == "" {
return fmt.Errorf("empty service Name")
}
reg, err := regexp.Compile(params.Name)
if err != nil {
return err
}
serviceConfig := systemdServiceConfig{regex: reg, watch: params.WatchProc}
systemdServices = append(systemdServices, &serviceConfig)
return nil
}

// c_systemd() iterates through all units provided by systemd's dbus info.
Expand Down
5 changes: 0 additions & 5 deletions cmd/scollector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ func main() {
for _, p := range conf.Process {
check(collectors.AddProcessConfig(p))
}
for _, p := range conf.SystemdService {
check(collectors.AddSystemdServiceConfig(p))
}
for _, p := range conf.ProcessDotNet {
check(collectors.AddProcessDotNetConfig(p))
}
Expand All @@ -145,8 +142,6 @@ func main() {
collectors.WatchProcesses()
collectors.WatchProcessesDotNet()

collectors.WatchSystemd()

if *flagFake > 0 {
collectors.InitFake(*flagFake)
}
Expand Down

0 comments on commit b35c862

Please sign in to comment.