Пример #1
0
// Collect - XXX
func (c *Checks) Collect() (interface{}, error) {
	c.SetConfigDefaults()
	var wg sync.WaitGroup
	var result []util.CommandResult

	resultChan := make(chan util.CommandResult, len(c.Config.Commands))

	for _, v := range c.Config.Commands {
		wg.Add(1)

		go func(command util.Command) {

			CheckResult := util.ExecWithExitCode(command)

			resultChan <- CheckResult
			defer wg.Done()
		}(v)

	}
	wg.Wait()
	close(resultChan)

	for i := range resultChan {
		result = append(result, i)
	}

	return result, nil
}
Пример #2
0
// Collect - XXX
func (c *Custom) Collect() (interface{}, error) {
	c.SetConfigDefaults()

	var wg sync.WaitGroup
	results := make(PerformanceStructBlock, 0)

	resultChan := make(chan util.CommandResult, len(c.Config.Commands))

	for _, v := range c.Config.Commands {
		wg.Add(1)

		go func(v util.Command) {

			CheckResult := util.ExecWithExitCode(v)

			resultChan <- CheckResult
			defer wg.Done()
		}(v)

	}
	wg.Wait()
	close(resultChan)

	for i := range resultChan {

		PerformanceStruct := PerformanceStruct{}

		lines := strings.Split(i.Output, "\n")
		gauges := make(map[string]interface{})
		counters := make(map[string]interface{})

		for _, line := range lines {

			metric, _ := ParseLine(line)
			if metric.Type == "gauge" {
				gauges[metric.Name] = metric.Value
			}

			if metric.Type == "counter" {
				counters[metric.Name] = metric.Value
			}

			pluginName := i.Name
			if len(gauges) > 0 {

				PerformanceStruct.Gauges = gauges
			}
			if len(counters) > 0 {
				PerformanceStruct.Counters = counters
			}

			results[pluginName] = PerformanceStruct

		}

	}

	return results, nil
}
Пример #3
0
// Collect - XXX
// This should return the following: sensu.plugin_name: {"gauges": {}}, sensu.another_plugin :{"gauges":{}}
func (s *Sensu) Collect() (interface{}, error) {
	s.SetConfigDefaults()
	var wg sync.WaitGroup
	plugins := make(map[string]interface{})

	resultChan := make(chan util.CommandResult, len(s.Config.Commands))
	for _, command := range s.Config.Commands {
		wg.Add(1)

		go func(command util.Command) {

			CheckResult := util.ExecWithExitCode(command)

			resultChan <- CheckResult
			defer wg.Done()

		}(command)
	}

	wg.Wait()
	close(resultChan)

	for command := range resultChan {
		var result []Metric
		gauges := make(map[string]string)
		GaugesWrapper := make(map[string]map[string]string)
		plugin := ""
		lines := strings.Split(command.Output, "\n")

		for _, line := range lines {
			metric, _ := s.ParseLine(line)
			if len(metric.Gauge) > 0 {
				result = append(result, metric)
			}
		}

		for _, r := range result {
			gauges[r.Gauge] = r.Value
			plugin = r.Plugin
		}

		GaugesWrapper["gauges"] = gauges

		if len(plugin) > 0 {
			plugins[plugin] = GaugesWrapper
		}

	}

	return plugins, nil
}
Пример #4
0
// Collect - XXX
func (t *Telegraf) Collect() (interface{}, error) {
	t.SetConfigDefaults()

	CommandString := fmt.Sprintf("/usr/bin/telegraf -test -config %s", t.Config.Config)
	var command = util.Command{Command: CommandString}

	Commandresult := util.ExecWithExitCode(command)

	plugins := make(map[string]interface{})
	lines := strings.Split(Commandresult.Output, "\n")
	var result []Metric
	for _, line := range lines {
		metrics, _ := t.ParseLine(line)

		if len(metrics.Elements) > 0 {
			for _, m := range metrics.Elements {
				if len(m.Gauge) > 0 {
					result = append(result, m)
				}
			}
		}

	}
	// Filter unique plugins
	AllPlugins := []string{}
	for _, r := range result {
		if !contains(AllPlugins, r.Plugin) {
			AllPlugins = append(AllPlugins, r.Plugin)
		}
	}
	for _, p := range AllPlugins {
		plugins[p] = make(map[string]interface{})
		GaugesWrapper := make(map[string]map[string]string)
		gauges := make(map[string]string)
		for _, r := range result {

			if r.Plugin == p {
				gauges[r.Gauge] = r.Value
			}

		}

		GaugesWrapper["gauges"] = gauges

		plugins[p] = GaugesWrapper

	}

	return plugins, nil
}