Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 3
0
func (m *MetricSeter) Fetch(ms *helper.MetricSet, host string) (event common.MapStr, err error) {

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

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

	event = common.MapStr{
		"mem":  system.GetMemoryEvent(memStat),
		"swap": system.GetSwapEvent(swapStat),
	}

	return event, nil
}