Exemplo n.º 1
0
func CPUInfo() ([]CPUInfoStat, error) {
	var ret []CPUInfoStat
	var dst []Win32_Processor
	q := wmi.CreateQuery(&dst, "")
	err := wmi.Query(q, &dst)
	if err != nil {
		return ret, err
	}

	var procID string
	for i, l := range dst {
		procID = ""
		if l.ProcessorId != nil {
			procID = *l.ProcessorId
		}

		cpu := CPUInfoStat{
			CPU:        int32(i),
			Family:     fmt.Sprintf("%d", l.Family),
			VendorID:   l.Manufacturer,
			ModelName:  l.Name,
			Cores:      int32(l.NumberOfLogicalProcessors),
			PhysicalID: procID,
			Mhz:        float64(l.MaxClockSpeed),
			Flags:      []string{},
		}
		ret = append(ret, cpu)
	}

	return ret, nil
}
Exemplo n.º 2
0
func CPUPercent(interval time.Duration, percpu bool) ([]float64, error) {
	var ret []float64
	var dst []Win32_Processor
	q := wmi.CreateQuery(&dst, "")
	err := wmi.Query(q, &dst)
	if err != nil {
		return ret, err
	}
	for _, l := range dst {
		// use range but windows can only get one percent.
		if l.LoadPercentage == nil {
			continue
		}
		ret = append(ret, float64(*l.LoadPercentage))
	}
	return ret, nil
}