Пример #1
0
// Fetch fetches memory metrics from the OS.
func (m *MetricSet) Fetch(host string) (event common.MapStr, err error) {
	memStat, err := system.GetMemory()
	if err != nil {
		return nil, errors.Wrap(err, "memory")
	}
	system.AddMemPercentage(memStat)

	swapStat, err := system.GetSwap()
	if err != nil {
		return nil, errors.Wrap(err, "swap")
	}
	system.AddSwapPercentage(swapStat)

	return common.MapStr{
		"mem":  system.GetMemoryEvent(memStat),
		"swap": system.GetSwapEvent(swapStat),
	}, nil
}
Пример #2
0
// Fetch fetches memory metrics from the OS.
func (m *MetricSet) Fetch() (event common.MapStr, err error) {
	memStat, err := system.GetMemory()
	if err != nil {
		return nil, errors.Wrap(err, "memory")
	}
	system.AddMemPercentage(memStat)

	swapStat, err := system.GetSwap()
	if err != nil {
		return nil, errors.Wrap(err, "swap")
	}
	system.AddSwapPercentage(swapStat)

	memory := common.MapStr{
		"total": memStat.Total,
		"used": common.MapStr{
			"bytes": memStat.Used,
			"pct":   memStat.UsedPercent,
		},
		"free": memStat.Free,
		"actual": common.MapStr{
			"free": memStat.ActualFree,
			"used": common.MapStr{
				"pct":   memStat.ActualUsedPercent,
				"bytes": memStat.ActualUsed,
			},
		},
	}

	swap := common.MapStr{
		"total": swapStat.Total,
		"used": common.MapStr{
			"bytes": swapStat.Used,
			"pct":   swapStat.UsedPercent,
		},
		"free": swapStat.Free,
	}

	memory["swap"] = swap
	return memory, nil
}