Пример #1
0
func (p *ProcNetDev) Run() error {
	data, err := linuxproc.ReadNetworkStat("/proc/net/dev")
	if err != nil {
		return err
	}

	for _, perIface := range data {
		p.Data[perIface.Iface] = perIface
	}

	return nil
}
Пример #2
0
func (n *NetStats) Store() {

	n.lastTime = n.actualTime

	// no copy for map on "=" with GO
	for k, v := range n.actual {
		n.last[k] = v
	}

	netStat, _ := linuxproc.ReadNetworkStat("/proc/net/dev")

	for _, ifaceStat := range netStat {

		ifaceName := ifaceStat.Iface

		// store new value
		n.actual[ifaceName] = ifaceStat
	}

	n.actualTime = time.Now()

}
// Run gathers cgroup memory information from cgroup itself.
// If you use container via systemd.slice, you could use
// containerid = docker-<container id>.scope and base=/sys/fs/cgroup/memory/system.slice/
func (m *DockerContainersNetDev) Run() error {
	containers, err := libdocker.AllInspectedContainers(m.DockerHost)
	if err != nil {
		return nil
	}

	for _, container := range containers {
		if container.ID != "" && container.State.Running {
			pid := container.State.Pid

			data, err := linuxproc.ReadNetworkStat(fmt.Sprintf("/proc/%v/net/dev", pid))
			if err == nil {
				m.Data[container.NiceImageName+"-"+container.ID] = make(map[string]linuxproc.NetworkStat)

				for _, perIface := range data {
					m.Data[container.NiceImageName+"-"+container.ID][perIface.Iface] = perIface
				}
			}
		}
	}

	return nil
}
Пример #4
0
Файл: pc.go Проект: FloydZ/xengo
//Initalisiert Pc
func (x *PCAll) Pc_Init_All() error {
	cpuinfo, err := linuxproc.ReadCPUInfo("/proc/cpuinfo")
	if err != nil {
		revel.ERROR.Print(err)
		return err
	}
	meminfo, err := linuxproc.ReadMemInfo("/proc/meminfo")
	if err != nil {
		revel.ERROR.Print(err)
		return err
	}
	diskinfo, err := linuxproc.ReadDiskStats("/proc/diskstats")
	if err != nil {
		revel.ERROR.Print(err)
		return err
	}

	netstat, err := linuxproc.ReadNetStat("/proc/net/netstat")
	if err != nil {
		revel.ERROR.Print(err)
		return err
	}

	netdev, err := linuxproc.ReadNetworkStat("/proc/net/dev")
	if err != nil {
		revel.ERROR.Print(err)
		return err
	}

	x.Cpuinfo = cpuinfo
	x.Meminfo = meminfo
	x.Diskstat = diskinfo
	x.Netstat = netstat
	x.Netdev = netdev

	return nil
}
Пример #5
0
func (p *ProcNetDevPid) Run() error {
	pids := sigar.ProcList{}
	err := pids.Get()
	if err != nil {
		return err
	}

	for _, pid := range pids.List {
		data, err := linuxproc.ReadNetworkStat(fmt.Sprintf("/proc/%v/net/dev", pid))
		if err != nil {
			return err
		}

		pidString := fmt.Sprintf("%v", pid)

		p.Data[pidString] = make(map[string]linuxproc.NetworkStat)

		for _, perIface := range data {
			p.Data[pidString][perIface.Iface] = perIface
		}
	}

	return nil
}
Пример #6
0
Файл: pc.go Проект: FloydZ/xengo
//Initalisiert Statischen Pc
func (y *PCStatic) PCInitStatic(s *SSH) error {
	/*
		NumCPUS	int
		NumVCORES int
		NumVCORESUsed int
		NumPhysicalCores int
		NumVCORESUsedProzent float64

		MemTotal string
		MemUsed string

		NetDevices string
	*/

	cpuinfo := &linuxproc.CPUInfo{}
	meminfo := &linuxproc.MemInfo{}
	netdev := []linuxproc.NetworkStat{}

	err := errors.New("")

	if s.Client == nil {
		err := errors.New("Could not find a ssh Client ")
		revel.ERROR.Print(err)
		return err
	} else {
		s.Download("/proc/cpuinfo", tempDir+"/cpuinfo"+strconv.Itoa(y.Id))
		cpuinfo, err = linuxproc.ReadCPUInfo(tempDir + "/cpuinfo" + strconv.Itoa(y.Id))
		if err != nil {
			revel.ERROR.Print(err)
			return err
		}
		s.Download("/proc/meminfo", tempDir+"/meminfo"+strconv.Itoa(y.Id))
		meminfo, err = linuxproc.ReadMemInfo(tempDir + "/meminfo" + strconv.Itoa(y.Id))
		if err != nil {
			revel.ERROR.Print(err)
			return err
		}
		s.Download("/proc/net/dev", tempDir+"/net"+strconv.Itoa(y.Id))
		netdev, err = linuxproc.ReadNetworkStat(tempDir + "/net" + strconv.Itoa(y.Id))
		if err != nil {
			revel.ERROR.Print(err)
			return err
		}
	}

	y.NumCPUS = cpuinfo.NumCPU()
	y.NumPhysicalCores = cpuinfo.NumPhysicalCPU()
	y.NumVCORES = (cpuinfo.NumCore() + 1) * 2
	y.NumVCORESUsed = y.NumVCORES / 2 //%TODO fake und so

	a := float64(y.NumVCORESUsed)
	b := float64(y.NumVCORES)
	y.NumVCORESUsedProzent = strconv.FormatFloat(float64(a/b)*100, 'f', -1, 64)

	y.NetDevices = netdev[0].Iface

	y.MemTotal = bytefmt.ByteSize(meminfo.MemTotal * 1024)
	y.MemUsed = bytefmt.ByteSize((meminfo.MemTotal - meminfo.MemFree) * 1024)

	return nil
}