Esempio n. 1
0
// CollectPluginsData - XXX
func CollectPluginsData() (interface{}, interface{}) {
	PluginResults := make(map[string]interface{})
	var CheckResults interface{}
	var wg sync.WaitGroup
	EnabledPlugins, _ := plugins.GetAllEnabledPlugins()
	for _, p := range EnabledPlugins {
		creator, ok := plugins.Plugins[p.Name]
		if ok {
			wg.Add(1)
			plugin := creator()

			go func(p plugins.PluginConfig) {
				defer wg.Done()
				PluginResult, err := plugin.Collect(p.Path)
				if err != nil {
					CollectorLogger.Errorf("Can't get stats for plugin: %s", err)

				}
				if p.Name == "checks" {
					CheckResults = PluginResult
				} else {
					PluginResults[p.Name] = PluginResult
				}
			}(p)

		} else {
			CollectorLogger.Errorf("Non existing plugin: %s", p.Name)
		}
	}
	wg.Wait()

	return PluginResults, CheckResults
}
Esempio n. 2
0
// NewAgent - XXX
func NewAgent(config settings.Struct) (*Agent, error) {

	var configuredPlugins = []plugins.ConfiguredPlugin{}

	EnabledPlugins, _ := plugins.GetAllEnabledPlugins()
	for _, p := range EnabledPlugins {
		creator, _ := plugins.Plugins[p.Name]
		plugin := creator()

		t := plugins.ConfiguredPlugin{Name: p.Name, Plugin: plugin}
		configuredPlugins = append(configuredPlugins, t)

	}

	agent := &Agent{
		Interval:          time.Duration(config.Interval) * time.Second,
		ConfiguredPlugins: configuredPlugins,
	}

	return agent, nil
}