Example #1
0
// Fetch fetches CPU core metrics from the OS.
func (m *MetricSet) Fetch() ([]common.MapStr, error) {

	cpuCoreStat, err := system.GetCpuTimesList()
	if err != nil {
		return nil, errors.Wrap(err, "cpu core times")
	}
	m.cpu.AddCpuPercentageList(cpuCoreStat)

	cores := []common.MapStr{}

	for core, stat := range cpuCoreStat {

		coreStat := common.MapStr{
			"user": common.MapStr{
				"pct": &stat.UserPercent,
			},
			"system": common.MapStr{
				"pct": &stat.SystemPercent,
			},
			"idle": common.MapStr{
				"pct": &stat.IdlePercent,
			},
			"iowait": common.MapStr{
				"pct": &stat.IOwaitPercent,
			},
			"irq": common.MapStr{
				"pct": &stat.IrqPercent,
			},
			"nice": common.MapStr{
				"pct": &stat.NicePercent,
			},
			"softirq": common.MapStr{
				"pct": &stat.SoftIrqPercent,
			},
			"steal": common.MapStr{
				"pct": &stat.StealPercent,
			},
		}

		if m.cpu.CpuTicks {
			coreStat["user"].(common.MapStr)["ticks"] = &stat.User
			coreStat["system"].(common.MapStr)["ticks"] = &stat.Sys
			coreStat["nice"].(common.MapStr)["ticks"] = &stat.Nice
			coreStat["idle"].(common.MapStr)["ticks"] = &stat.Idle
			coreStat["iowait"].(common.MapStr)["ticks"] = &stat.Wait
			coreStat["irq"].(common.MapStr)["ticks"] = &stat.Irq
			coreStat["softirq"].(common.MapStr)["ticks"] = &stat.SoftIrq
			coreStat["steal"].(common.MapStr)["ticks"] = &stat.Stolen
		}

		coreStat["id"] = core
		cores = append(cores, coreStat)
	}

	return cores, nil
}
Example #2
0
// Fetch fetches CPU core metrics from the OS.
func (m *MetricSet) Fetch() ([]common.MapStr, error) {

	cpuCoreStat, err := system.GetCpuTimesList()
	if err != nil {
		return nil, errors.Wrap(err, "cpu core times")
	}
	m.cpu.AddCpuPercentageList(cpuCoreStat)

	cores := []common.MapStr{}

	for core, stat := range cpuCoreStat {
		coreStat := system.GetCpuStatEvent(&stat)
		coreStat["core"] = core
		cores = append(cores, coreStat)

	}

	return cores, nil
}