Ejemplo n.º 1
0
func (_ *SystemStats) Gather(acc telegraf.Accumulator) error {
	loadavg, err := load.Avg()
	if err != nil {
		return err
	}

	hostinfo, err := host.Info()
	if err != nil {
		return err
	}

	users, err := host.Users()
	if err != nil {
		return err
	}

	fields := map[string]interface{}{
		"load1":         loadavg.Load1,
		"load5":         loadavg.Load5,
		"load15":        loadavg.Load15,
		"uptime":        hostinfo.Uptime,
		"n_users":       len(users),
		"uptime_format": format_uptime(hostinfo.Uptime),
		"n_cpus":        runtime.NumCPU(),
	}
	acc.AddFields("system", fields, nil)

	return nil
}
Ejemplo n.º 2
0
func (f *HostFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
	hostInfo, err := host.Info()
	if err != nil {
		f.logger.Println("[WARN] Error retrieving host information: ", err)
		return false, err
	}

	node.Attributes["os.name"] = hostInfo.Platform
	node.Attributes["os.version"] = hostInfo.PlatformVersion

	node.Attributes["kernel.name"] = runtime.GOOS
	node.Attributes["kernel.version"] = ""

	if runtime.GOOS != "windows" {
		out, err := exec.Command("uname", "-r").Output()
		if err != nil {
			return false, fmt.Errorf("Failed to run uname: %s", err)
		}
		node.Attributes["kernel.version"] = strings.Trim(string(out), "\n")
	}

	node.Attributes["unique.hostname"] = hostInfo.Hostname

	return true, nil
}
Ejemplo n.º 3
0
func GetHostStats() string {
	v, err := host.Info()
	format := "uptime=%d procs=%d os=%s platform=%s platform_family=%s platform_version=%s virtualization_system=%s virtualization_role=%s"
	if err == nil {
		return fmt.Sprintf(format, v.Uptime, v.Procs, v.OS, v.Platform, v.PlatformFamily, v.PlatformVersion, v.VirtualizationSystem, v.VirtualizationRole)
	} else {
		return fmt.Sprintf(format, 0, 0, 0, 0, 0, 0, 0, 0)
	}
}
Ejemplo n.º 4
0
// Distro - gets distro info
// {'version': '14.04', 'name': 'Ubuntu'}
func Distro() DistroStruct {
	host, _ := pshost.Info()

	d := DistroStruct{
		Version: host.PlatformVersion,
		Name:    host.Platform,
	}

	return d
}