Пример #1
0
func (l *LoadAverage) Usage() float64 {
	loadAverage, _ := linuxproc.ReadLoadAvg("/proc/loadavg")
	cpuInfo, _ := linuxproc.ReadCPUInfo("/proc/cpuinfo")

	l.last1m = loadAverage.Last1Min / float64(cpuInfo.NumCore())
	l.last5m = loadAverage.Last5Min / float64(cpuInfo.NumCore())
	l.last15m = loadAverage.Last15Min / float64(cpuInfo.NumCore())

	return l.last1m
}
func (lac loadAverageChecker) doCheck() (string, error) {
	l, err := linuxproc.ReadLoadAvg(*hostPath + "/proc/loadavg")

	if err != nil {
		return "", fmt.Errorf("Couldn't read loadavg data")
	}

	cpuInfo, err := linuxproc.ReadCPUInfo(*hostPath + "/proc/cpuinfo")

	if err != nil {
		return "", fmt.Errorf("Couldn't read cpuinfo data")
	}

	fiveMinLimit := (1.5 * float64(cpuInfo.NumCPU()))
	fifteenMinLimit := (0.9 * float64(cpuInfo.NumCPU()))

	if l.Last5Min > fiveMinLimit || l.Last15Min > fifteenMinLimit {
		return fmt.Sprintf("Last5Min: %2.2f, Last15Min: %2.2f", l.Last5Min, l.Last15Min), fmt.Errorf("Load avg is above the recommended threshold: Last5Min: %2.2f, Last15Min: %2.2f", l.Last5Min, l.Last15Min)
	}

	return fmt.Sprintf("Last5Min: %2.2f, Last15Min: %2.2f", l.Last5Min, l.Last15Min), nil
}
Пример #3
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
}
Пример #4
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
}