Exemple #1
0
// Get information about system memory.
func Get() (Memory, error) {
	m := Memory{}

	o, err := common.ExecCmdFields("/usr/sbin/sysctl", []string{"-a"}, ":", []string{
		"hw.memsize",
	})
	if err != nil {
		return Memory{}, err
	}

	m.TotalGB, err = strconv.Atoi(o["hw.memsize"])
	if err != nil {
		return Memory{}, err
	}
	m.TotalGB = m.TotalGB / 1024 / 1024 / 1024

	return m, nil
}
func (m *memory) ForceUpdate() error {
	m.cache.LastUpdated = time.Now()
	m.cache.FromCache = false

	o, err := common.ExecCmdFields("/usr/sbin/sysctl", []string{"-a"}, ":", []string{
		"hw.memsize",
	})
	if err != nil {
		return err
	}

	m.data.TotalKB, err = strconv.Atoi(o["hw.memsize"])
	if err != nil {
		return err
	}
	m.data.TotalKB = m.data.TotalKB / 1024
	m.data.TotalGB = m.data.TotalKB / 1024 / 1024

	return nil
}
Exemple #3
0
// Get information about the operating system.
func Get() (OpSys, error) {
	opsys := OpSys{}

	o, err := common.ExecCmdFields("lsb_release", []string{"-a"}, ":", []string{
		"Distributor ID",
		"Release",
	})
	if err != nil {
		return OpSys{}, err
	}

	opsys.Kernel = runtime.GOOS
	opsys.Product = o["Distributor ID"]
	opsys.ProductVersion = o["Release"]

	opsys.KernelVersion, err = common.ExecCmd("uname", []string{"-r"})
	if err != nil {
		return OpSys{}, err
	}

	return opsys, nil
}
Exemple #4
0
// Get information about the operating system.
func Get() (OpSys, error) {
	opsys := OpSys{}

	o, err := common.ExecCmdFields("/usr/bin/sw_vers", []string{}, ":", []string{
		"ProductName",
		"ProductVersion",
	})
	if err != nil {
		return OpSys{}, err
	}

	opsys.Kernel = runtime.GOOS
	opsys.Product = o["ProductName"]
	opsys.ProductVersion = o["ProductVersion"]

	opsys.KernelVersion, err = common.ExecCmd("uname", []string{"-r"})
	if err != nil {
		return OpSys{}, err
	}

	return opsys, nil
}
Exemple #5
0
// Get information about a system.
func Get() (System, error) {
	s := System{}
	s.Manufacturer = "Apple Inc."

	o, err := common.ExecCmdFields("/usr/sbin/system_profiler", []string{"SPHardwareDataType"}, ":", []string{
		"Model Name",
		"Model Identifier",
		"Serial Number",
		"Boot ROM Version",
		"SMC Version",
	})
	if err != nil {
		return System{}, err
	}

	s.Product = o["Model Name"]
	s.ProductVersion = o["Model Identifier"]
	s.SerialNumber = o["Serial Number"]
	s.BootROMVersion = o["Boot ROM Version"]
	s.SMCVersion = o["SMC Version"]

	return s, nil
}
func (op *opSys) ForceUpdate() error {
	op.cache.LastUpdated = time.Now()
	op.cache.FromCache = false

	o, err := common.ExecCmdFields("lsb_release", []string{"-a"}, ":", []string{
		"Distributor ID",
		"Release",
	})
	if err != nil {
		return err
	}

	op.data.Kernel = runtime.GOOS
	op.data.Product = o["Distributor ID"]
	op.data.ProductVersion = o["Release"]

	op.data.KernelVersion, err = common.ExecCmd("uname", []string{"-r"})
	if err != nil {
		return err
	}

	return nil
}
func (op *opSys) ForceUpdate() error {
	op.cache.LastUpdated = time.Now()
	op.cache.FromCache = false

	o, err := common.ExecCmdFields("/usr/bin/sw_vers", []string{}, ":", []string{
		"ProductName",
		"ProductVersion",
	})
	if err != nil {
		return err
	}

	op.data.Kernel = runtime.GOOS
	op.data.Product = o["ProductName"]
	op.data.ProductVersion = o["ProductVersion"]

	op.data.KernelVersion, err = common.ExecCmd("uname", []string{"-r"})
	if err != nil {
		return err
	}

	return nil
}
func (c *cpu) ForceUpdate() error {
	c.cache.LastUpdated = time.Now()
	c.cache.FromCache = false

	o, err := common.ExecCmdFields("/usr/sbin/sysctl", []string{"-a"}, ":", []string{
		"machdep.cpu.core_count",
		"hw.physicalcpu_max",
		"hw.logicalcpu_max",
		"machdep.cpu.brand_string",
		"machdep.cpu.features",
	})
	if err != nil {
		return err
	}

	c.data.CoresPerSocket, err = strconv.Atoi(o["machdep.cpu.core_count"])
	if err != nil {
		return err
	}

	c.data.Physical, err = strconv.Atoi(o["hw.physicalcpu_max"])
	if err != nil {
		return err
	}

	c.data.Logical, err = strconv.Atoi(o["hw.logicalcpu_max"])
	if err != nil {
		return err
	}

	c.data.Sockets = c.data.Physical / c.data.CoresPerSocket
	c.data.ThreadsPerCore = c.data.Logical / c.data.Sockets / c.data.CoresPerSocket
	c.data.Model = o["machdep.cpu.brand_string"]
	c.data.Flags = strings.ToLower(o["machdep.cpu.features"])

	return nil
}
func (s *system) ForceUpdate() error {
	s.cache.LastUpdated = time.Now()
	s.cache.FromCache = false
	s.data.Manufacturer = "Apple Inc."

	o, err := common.ExecCmdFields("/usr/sbin/system_profiler", []string{"SPHardwareDataType"}, ":", []string{
		"Model Name",
		"Model Identifier",
		"Serial Number",
		"Boot ROM Version",
		"SMC Version",
	})
	if err != nil {
		return err
	}

	s.data.Product = o["Model Name"]
	s.data.ProductVersion = o["Model Identifier"]
	s.data.SerialNumber = o["Serial Number"]
	s.data.BootROMVersion = o["Boot ROM Version"]
	s.data.SMCVersion = o["SMC Version"]

	return nil
}
Exemple #10
0
// Get information about system CPU(s).
func Get() (CPU, error) {
	c := CPU{}

	o, err := common.ExecCmdFields("/usr/sbin/sysctl", []string{"-a"}, ":", []string{
		"machdep.cpu.core_count",
		"hw.physicalcpu_max",
		"hw.logicalcpu_max",
		"machdep.cpu.brand_string",
		"machdep.cpu.features",
	})
	if err != nil {
		return CPU{}, err
	}

	c.CoresPerSocket, err = strconv.Atoi(o["machdep.cpu.core_count"])
	if err != nil {
		return CPU{}, err
	}

	c.Physical, err = strconv.Atoi(o["hw.physicalcpu_max"])
	if err != nil {
		return CPU{}, err
	}

	c.Logical, err = strconv.Atoi(o["hw.logicalcpu_max"])
	if err != nil {
		return CPU{}, err
	}

	c.Sockets = c.Physical / c.CoresPerSocket
	c.ThreadsPerCore = c.Logical / c.Sockets / c.CoresPerSocket
	c.Model = o["machdep.cpu.brand_string"]
	c.Flags = strings.ToLower(o["machdep.cpu.features"])

	return c, nil
}
func (i *interfaces) ForceUpdate() error {
	i.cache.LastUpdated = time.Now()
	i.cache.FromCache = false

	rIntfs, err := net.Interfaces()
	if err != nil {
		return err
	}

	for _, rIntf := range rIntfs {
		// Skip loopback interfaces
		if rIntf.Flags&net.FlagLoopback != 0 {
			continue
		}

		addrs, err := rIntf.Addrs()
		if err != nil {
			return err
		}

		sIntf := DataItem{
			Name:   rIntf.Name,
			HWAddr: rIntf.HardwareAddr.String(),
			MTU:    rIntf.MTU,
		}

		for _, addr := range addrs {
			sIntf.IPAddr = append(sIntf.IPAddr, addr.String())
		}

		if rIntf.Flags&net.FlagUp != 0 {
			sIntf.Flags = append(sIntf.Flags, "up")
		}
		if rIntf.Flags&net.FlagBroadcast != 0 {
			sIntf.Flags = append(sIntf.Flags, "broadcast")
		}
		if rIntf.Flags&net.FlagPointToPoint != 0 {
			sIntf.Flags = append(sIntf.Flags, "pointtopoint")
		}
		if rIntf.Flags&net.FlagMulticast != 0 {
			sIntf.Flags = append(sIntf.Flags, "multicast")
		}

		switch runtime.GOOS {
		case "linux":
			o, err := common.ExecCmdFields("/usr/sbin/ethtool", []string{"-i", rIntf.Name}, ":", []string{
				"driver",
				"version",
				"firmware-version",
				"bus-info",
			})
			if err != nil {
				return err
			}

			sIntf.Driver = o["driver"]
			sIntf.DriverVersion = o["version"]
			sIntf.FirmwareVersion = o["firmware-version"]
			if strings.HasPrefix(o["bus-info"], "0000:") {
				sIntf.PCIBus = o["bus-info"]
				sIntf.PCIBusURL = fmt.Sprintf("/pci/%v", o["bus-info"])
			}

			o2, err := common.ExecCmdFields("/usr/sbin/lldpctl", []string{rIntf.Name}, ":", []string{
				"ChassisID",
				"SysName",
				"SysDescr",
				"PortID",
				"PortDescr",
				"VLAN",
			})
			if err != nil {
				return err
			}

			sIntf.SwChassisID = o2["ChassisID"]
			sIntf.SwName = o2["SysName"]
			sIntf.SwDescr = o2["SysDescr"]
			sIntf.SwPortID = o2["PortID"]
			sIntf.SwPortDescr = o2["PortDescr"]
			sIntf.SwVLAN = o2["VLAN"]
		}

		*i.data = append(*i.data, sIntf)
	}

	return nil
}
Exemple #12
0
// GetInfo return information about a systems memory.
func Get() (Network, error) {
	network := Network{}

	intfs, err := net.Interfaces()
	if err != nil {
		return Network{}, err
	}

	for _, intf := range intfs {
		// Skip loopback interfaces
		if intf.Flags&net.FlagLoopback != 0 {
			continue
		}
		/*
			// Skip interfaces that are down
			if intf.Flags&net.FlagUp == 0 {
				continue
			}
		*/

		addrs, err := intf.Addrs()
		if err != nil {
			return Network{}, err
		}

		nintf := Interface{
			Name:   intf.Name,
			HWAddr: intf.HardwareAddr.String(),
			MTU:    intf.MTU,
		}

		for _, addr := range addrs {
			nintf.IPAddr = append(nintf.IPAddr, addr.String())
		}

		if intf.Flags&net.FlagUp != 0 {
			nintf.Flags = append(nintf.Flags, "up")
		}
		if intf.Flags&net.FlagBroadcast != 0 {
			nintf.Flags = append(nintf.Flags, "broadcast")
		}
		if intf.Flags&net.FlagPointToPoint != 0 {
			nintf.Flags = append(nintf.Flags, "pointtopoint")
		}
		if intf.Flags&net.FlagMulticast != 0 {
			nintf.Flags = append(nintf.Flags, "multicast")
		}

		switch runtime.GOOS {
		case "linux":
			o, err := common.ExecCmdFields("/usr/sbin/ethtool", []string{"-i", intf.Name}, ":", []string{
				"driver",
				"version",
				"firmware-version",
				"bus-info",
			})
			if err != nil {
				return Network{}, err
			}

			nintf.Driver = o["driver"]
			nintf.DriverVersion = o["version"]
			nintf.FirmwareVersion = o["firmware-version"]
			if strings.HasPrefix(o["bus-info"], "0000:") {
				nintf.PCIBus = o["bus-info"]
				nintf.PCIBusURL = fmt.Sprintf("/pci/%v", o["bus-info"])
			}

			o2, err := common.ExecCmdFields("/usr/sbin/lldpctl", []string{intf.Name}, ":", []string{
				"ChassisID",
				"SysName",
				"SysDescr",
				"PortID",
				"PortDescr",
				"VLAN",
			})
			if err != nil {
				return Network{}, err
			}

			nintf.SwChassisID = o2["ChassisID"]
			nintf.SwName = o2["SysName"]
			nintf.SwDescr = o2["SysDescr"]
			nintf.SwPortID = o2["PortID"]
			nintf.SwPortDescr = o2["PortDescr"]
			nintf.SwVLAN = o2["VLAN"]
		}

		network.Interfaces = append(network.Interfaces, nintf)
	}

	switch runtime.GOOS {
	case "linux":
		_, err := exec.LookPath("onload")
		if err == nil {
			o, _ := common.ExecCmdFields("onload", []string{"--version"}, ":", []string{"Kernel module"})
			if err != nil {
				return Network{}, err
			}
			network.OnloadVersion = o["Kernel module"]
		}
	}

	return network, nil
}