예제 #1
0
// Debug - XXX
func Debug() {
	result := collectors.CollectProcessData()

	fmt.Println(result)
}
예제 #2
0
파일: agent.go 프로젝트: amonapp/amonagent
// Test - XXX
func (a *Agent) Test(config settings.Struct) error {

	allMetrics := collectors.CollectAllData(a.ConfiguredPlugins)

	ProcessesData := collectors.CollectProcessData()
	SystemData := collectors.CollectSystemData()
	HostData := collectors.CollectHostData()

	fmt.Println("\n------------------")
	fmt.Println("\033[92mSystem Metrics: \033[0m")
	fmt.Println("")
	fmt.Println(SystemData)
	fmt.Println("\n------------------")

	fmt.Println("\n------------------")
	fmt.Println("\033[92mProcess Metrics: \033[0m")
	fmt.Println("")
	fmt.Println(ProcessesData)
	fmt.Println("\n------------------")

	fmt.Println("\n------------------")
	fmt.Println("\033[92mPlugins: \033[0m")
	fmt.Println("")

	for _, p := range a.ConfiguredPlugins {
		start := time.Now()
		PluginResult, err := p.Plugin.Collect()
		if err != nil {
			log.Errorf("Can't get stats for plugin: %s", err)
		}

		fmt.Println("\n------------------")
		fmt.Print("\033[92mPlugin: ")
		fmt.Print(p.Name)
		fmt.Print("\033[0m \n")
		fmt.Println(PluginResult)

		elapsed := time.Since(start)
		fmt.Printf("\n Executed in %s", elapsed)

	}

	fmt.Println("\n------------------")
	fmt.Println("\033[92mHost Data: \033[0m")
	fmt.Println("")
	fmt.Println(HostData)
	fmt.Println("\n------------------")

	fmt.Println("\033[92mTesting settings: \033[0m")
	fmt.Println("")
	machineID := collectors.GetOrCreateMachineID()

	if len(machineID) == 0 && len(config.ServerKey) == 0 {
		fmt.Println("Can't find Machine ID (looking in /etc/opt/amonagent/machine-id).")
		fmt.Println("To solve this problem, run the following command:")
		fmt.Println("---")
		fmt.Println("amonagent -machineid")
		fmt.Println("---")

	} else {
		fmt.Println("Settings OK")
	}

	fmt.Println("\n------------------")

	err := remote.SendData(allMetrics, true)
	if err != nil {
		return fmt.Errorf("%s\n", err.Error())
	}

	return nil
}