Esempio n. 1
0
func AddMemPercentage(m *MemStat) {

	if m.Mem.Total == 0 {
		return
	}

	perc := float64(m.Mem.Used) / float64(m.Mem.Total)
	m.UsedPercent = system.Round(perc, .5, 4)

	actual_perc := float64(m.Mem.ActualUsed) / float64(m.Mem.Total)
	m.ActualUsedPercent = system.Round(actual_perc, .5, 4)
}
Esempio n. 2
0
func GetCpuPercentageList(last, current []CpuTimes) []CpuTimes {

	if last != nil && current != nil && len(last) == len(current) {

		calculate := func(field2 uint64, field1 uint64, all_delta uint64) float64 {

			perc := 0.0
			delta := int64(field2 - field1)
			perc = float64(delta) / float64(all_delta)
			return system.Round(perc, .5, 4)
		}

		for i := 0; i < len(last); i++ {
			allDelta := current[i].Cpu.Total() - last[i].Cpu.Total()
			current[i].UserPercent = calculate(current[i].Cpu.User, last[i].Cpu.User, allDelta)
			current[i].SystemPercent = calculate(current[i].Cpu.Sys, last[i].Cpu.Sys, allDelta)
			current[i].IdlePercent = calculate(current[i].Cpu.Idle, last[i].Cpu.Idle, allDelta)
			current[i].IOwaitPercent = calculate(current[i].Cpu.Wait, last[i].Cpu.Wait, allDelta)
			current[i].IrqPercent = calculate(current[i].Cpu.Irq, last[i].Cpu.Irq, allDelta)
			current[i].NicePercent = calculate(current[i].Cpu.Nice, last[i].Cpu.Nice, allDelta)
			current[i].SoftIrqPercent = calculate(current[i].Cpu.SoftIrq, last[i].Cpu.SoftIrq, allDelta)
			current[i].StealPercent = calculate(current[i].Cpu.Stolen, last[i].Cpu.Stolen, allDelta)

		}

	}

	return current
}
Esempio n. 3
0
func GetCpuPercentage(last *CpuTimes, current *CpuTimes) *CpuTimes {

	if last != nil && current != nil {
		allDelta := current.Cpu.Total() - last.Cpu.Total()

		if allDelta == 0 {
			// first inquiry
			return current
		}

		calculate := func(field2 uint64, field1 uint64) float64 {

			perc := 0.0
			delta := int64(field2 - field1)
			perc = float64(delta) / float64(allDelta)
			return system.Round(perc, .5, 4)
		}

		current.UserPercent = calculate(current.Cpu.User, last.Cpu.User)
		current.SystemPercent = calculate(current.Cpu.Sys, last.Cpu.Sys)
		current.IdlePercent = calculate(current.Cpu.Idle, last.Cpu.Idle)
		current.IOwaitPercent = calculate(current.Cpu.Wait, last.Cpu.Wait)
		current.IrqPercent = calculate(current.Cpu.Irq, last.Cpu.Irq)
		current.NicePercent = calculate(current.Cpu.Nice, last.Cpu.Nice)
		current.SoftIrqPercent = calculate(current.Cpu.SoftIrq, last.Cpu.SoftIrq)
		current.StealPercent = calculate(current.Cpu.Stolen, last.Cpu.Stolen)
	}

	return current
}
Esempio n. 4
0
func AddFileSystemUsedPercentage(f *FileSystemStat) {
	if f.Total == 0 {
		return
	}

	perc := float64(f.Used) / float64(f.Total)
	f.UsedPercent = system.Round(perc, .5, 4)
}
Esempio n. 5
0
func AddSwapPercentage(s *SwapStat) {
	if s.Swap.Total == 0 {
		return
	}

	perc := float64(s.Swap.Used) / float64(s.Swap.Total)
	s.UsedPercent = system.Round(perc, .5, 4)
}
Esempio n. 6
0
func GetProcCpuPercentage(last *Process, current *Process) float64 {

	if last != nil && current != nil {

		delta_proc := int64(current.Cpu.Total - last.Cpu.Total)
		delta_time := float64(current.Ctime.Sub(last.Ctime).Nanoseconds()) / float64(1e6) // in milliseconds
		perc := float64(delta_proc) / delta_time

		return system.Round(perc, .5, 4)
	}
	return 0
}
Esempio n. 7
0
func GetProcMemPercentage(proc *Process, total_phymem uint64) float64 {

	// in unit tests, total_phymem is set to a value greater than zero

	if total_phymem == 0 {
		memStat, err := memory.GetMemory()
		if err != nil {
			logp.Warn("Getting memory details: %v", err)
			return 0
		}
		total_phymem = memStat.Mem.Total
	}

	perc := (float64(proc.Mem.Resident) / float64(total_phymem))

	return system.Round(perc, .5, 4)
}
Esempio n. 8
0
File: load.go Progetto: ruflin/beats
// Fetch methods implements the data gathering and data conversion to the right format
// It returns the event which is then forward to the output. In case of an error, a
// descriptive error must be returned.
func (m *MetricSet) Fetch() (common.MapStr, error) {

	loadStat, err := GetSystemLoad()
	if err != nil {
		return nil, errors.Wrap(err, "load statistics")
	}

	event := common.MapStr{
		"1":  system.Round(loadStat.Load1, .5, 4),
		"5":  system.Round(loadStat.Load5, .5, 4),
		"15": system.Round(loadStat.Load15, .5, 4),
		"norm": common.MapStr{
			"1":  system.Round(loadStat.LoadNorm1, .5, 4),
			"5":  system.Round(loadStat.LoadNorm5, .5, 4),
			"15": system.Round(loadStat.LoadNorm15, .5, 4),
		},
	}

	return event, nil
}