// Fetch fetches CPU metrics from the OS. func (m *MetricSet) Fetch() (common.MapStr, error) { stat, err := system.GetCpuTimes() if err != nil { return nil, errors.Wrap(err, "cpu times") } m.cpu.AddCpuPercentage(stat) loadStat, err := system.GetSystemLoad() if err != nil { return nil, errors.Wrap(err, "load statistics") } cpuStat := 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 { cpuStat["user"].(common.MapStr)["ticks"] = stat.User cpuStat["system"].(common.MapStr)["ticks"] = stat.Sys cpuStat["nice"].(common.MapStr)["ticks"] = stat.Nice cpuStat["idle"].(common.MapStr)["ticks"] = stat.Idle cpuStat["iowait"].(common.MapStr)["ticks"] = stat.Wait cpuStat["irq"].(common.MapStr)["ticks"] = stat.Irq cpuStat["softirq"].(common.MapStr)["ticks"] = stat.SoftIrq cpuStat["steal"].(common.MapStr)["ticks"] = stat.Stolen } cpuStat["load"] = common.MapStr{ "1": loadStat.Load1, "5": loadStat.Load5, "15": loadStat.Load15, } return cpuStat, nil }
// Fetch fetches CPU metrics from the OS. func (m *MetricSet) Fetch(host string) (common.MapStr, error) { cpuStat, err := system.GetCpuTimes() if err != nil { return nil, errors.Wrap(err, "cpu times") } return system.GetCpuStatEvent(cpuStat), nil }
func (m *MetricSeter) Fetch(ms *helper.MetricSet, host string) (event common.MapStr, err error) { cpuStat, err := system.GetCpuTimes() if err != nil { logp.Warn("Getting cpu times: %v", err) return nil, err } event = system.GetCpuStatEvent(cpuStat) return event, nil }
// Fetch fetches CPU metrics from the OS. func (m *MetricSet) Fetch() (common.MapStr, error) { cpuStat, err := system.GetCpuTimes() if err != nil { return nil, errors.Wrap(err, "cpu times") } m.cpu.AddCpuPercentage(cpuStat) loadStat, err := system.GetSystemLoad() if err != nil { return nil, errors.Wrap(err, "load statistics") } event := system.GetCpuStatEvent(cpuStat) event["load"] = loadStat return event, nil }