Esempio 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
}
Esempio n. 2
0
// Run gathers user information from gopsutil.
func (h *HostUsers) Run() error {
	dataSlice, err := gopsutil_host.Users()
	if err != nil {
		return err
	}

	for _, data := range dataSlice {
		h.Data[data.User] = data
	}
	return nil
}