Exemple #1
0
func Poll() DataPoint {
	loadAvg, err := linux.ReadLoadAvg("/proc/loadavg")
	if err != nil {
		log.Fatal(err)
	}
	return DataPoint{int(loadAvg.Last1Min * 100), int(loadAvg.Last5Min * 100), int(loadAvg.Last15Min * 100)}
}
Exemple #2
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
}
Exemple #3
0
func (p *ProcLoadAvg) Run() error {
	loadavg, err := linuxproc.ReadLoadAvg("/proc/loadavg")
	if err != nil {
		return err
	}

	p.Data["last1min"] = loadavg.Last1Min
	p.Data["last5min"] = loadavg.Last5Min
	p.Data["last15min"] = loadavg.Last15Min

	return nil
}
Exemple #4
0
//Initalisiert Dynamischen Pc
func (y *PCDynamic) PCInitDynamic(s *SSH) error {
	/*
		Id int						`id`

		MemFree string				`memfree`
		MemAvailable string			`memavail`
		MemUsed uint64				`memused`
		MemUsedProzent float64		`memusedprozent`

		LoadAvg float64				`loadavg`
		NumProcess uint64			`numprocess`
	*/
	loadavg := &linuxproc.LoadAvg{}
	meminfo := &linuxproc.MemInfo{}
	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/loadavg", tempDir+"/loadavg"+strconv.Itoa(y.Id))
		loadavg, err = linuxproc.ReadLoadAvg("/proc/loadavg")
		if err != nil {
			revel.ERROR.Print(err)
			return err
		}

		y.LoadAvg = loadavg.Last1Min
		y.NumProcess = loadavg.ProcessRunning

		s.Download("/proc/meminfo", tempDir+"/meminfo"+strconv.Itoa(y.Id))
		meminfo, err = linuxproc.ReadMemInfo("/home/pr0gramming/Dokumente/meminfo" + strconv.Itoa(y.Id))
		if err != nil {
			revel.ERROR.Print(err)
			return err
		}

	}

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

	a := float64(meminfo.MemTotal)
	b := float64(meminfo.MemFree)
	y.MemUsedProzent = strconv.FormatFloat(float64(((a-b)/a)*100), 'f', -1, 64)

	//println("test: " + (y.MemUsedProzent))
	return nil
}
func main() {
	uaid := os.Getenv("UAID")

	if uaid == "" {
		panic("UAID environment required. Example: UAID=UA-XXXXXX-Y ./server-analytics")
	}

	client, err := ga.NewClient(uaid)

	if err != nil {
		panic(err)
	}

	ticker := time.NewTicker(15 * time.Second)
	quit := make(chan struct{})
	stop := false

	for !stop {
		select {
		case <-ticker.C:
			diskInfo, err := linuxproc.ReadDisk("/")
			_ = err

			client.Send(ga.NewEvent("Disk", "All").Label("Total Disk Space").Value(int64(diskInfo.All)))
			client.Send(ga.NewEvent("Disk", "Used").Label("Used Disk Space").Value(int64(diskInfo.Used)))
			client.Send(ga.NewEvent("Disk", "Free").Label("Free Disk Space").Value(int64(diskInfo.Free)))

			loadAvg, err := linuxproc.ReadLoadAvg("/proc/loadavg")
			_ = err

			client.Send(ga.NewEvent("Load Average", "1m").Label("1m").Value(int64(loadAvg.Last1Min)))
			client.Send(ga.NewEvent("Load Average", "5m").Label("5m").Value(int64(loadAvg.Last5Min)))
			client.Send(ga.NewEvent("Load Average", "15m").Label("15m").Value(int64(loadAvg.Last15Min)))
			client.Send(ga.NewEvent("Load Average", "Running").Label("Process Running").Value(int64(loadAvg.ProcessRunning)))
			client.Send(ga.NewEvent("Load Average", "Total").Label("Process Total").Value(int64(loadAvg.ProcessTotal)))

			meminfo, err := linuxproc.ReadMemInfo("/proc/meminfo")
			_ = err

			client.Send(ga.NewEvent("Memory", "Total").Label("Memory Total").Value(int64(meminfo.MemTotal)))
			client.Send(ga.NewEvent("Memory", "Free").Label("Memory Free").Value(int64(meminfo.MemFree)))

		case <-quit:
			ticker.Stop()
			return
		}
	}
}
Exemple #6
0
func ProducerRunFuction(producer *producers.GenericProducer) events.Event {

	uptime, err := linuxproc.ReadUptime("/proc/uptime")
	if err != nil {
		log.Fatal("Failed while getting uptime")
	}

	load, err := linuxproc.ReadLoadAvg("/proc/loadavg")
	if err != nil {
		log.Fatal("Failed while getting uptime")
	}

	uptimeStr := fmt.Sprintf("Up:%v ", time.Duration(time.Duration(int64(uptime.Total))*time.Second).String())
	loadStr := fmt.Sprintf("Load:%v %v %v", load.Last1Min, load.Last5Min, load.Last15Min)
	return events.Event{uptimeStr + loadStr, producer.Name, time.Now(), events.PRIORITY_LOW}

}
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
}