예제 #1
0
파일: helper.go 프로젝트: YaSuenag/hsbeat
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)
}
예제 #2
0
파일: helper.go 프로젝트: ChongFeng/beats
func (cpu *CPU) GetSystemStats() (common.MapStr, error) {
	loadStat, err := GetSystemLoad()
	if err != nil {
		logp.Warn("Getting load statistics: %v", err)
		return nil, err
	}
	cpuStat, err := GetCpuTimes()
	if err != nil {
		logp.Warn("Getting cpu times: %v", err)
		return nil, err
	}

	cpu.AddCpuPercentage(cpuStat)

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

	swapStat, err := memory.GetSwap()
	if err != nil {
		logp.Warn("Getting swap details: %v", err)
		return nil, err
	}
	memory.AddSwapPercentage(swapStat)

	event := common.MapStr{
		"@timestamp": common.Time(time.Now()),
		"type":       "system",
		"load":       loadStat,
		"cpu":        cpu.GetCpuStatEvent(cpuStat),
		"mem":        memory.GetMemoryEvent(memStat),
		"swap":       memory.GetSwapEvent(swapStat),
	}

	return event, nil
}