Files
troubleshoot/pkg/collect/host_cpu.go
Andrew Reed 10a34c2e58 Host preflight (#311)
* Add HostPreflight v1beta2

* Work on TCP Load Balancer

* Host disk usage collector and analyzer

* Host memory analyzer

* TCP port status

* TCP load balancer

* Review changes

Co-authored-by: Marc Campbell <marc.e.campbell@gmail.com>
2021-02-08 16:09:01 -05:00

39 lines
798 B
Go

package collect
import (
"encoding/json"
"github.com/pkg/errors"
"github.com/shirou/gopsutil/cpu"
)
type CPUInfo struct {
LogicalCount int `json:"logicalCount"`
PhysicalCount int `json:"physicalCount"`
}
func HostCPU(c *HostCollector) (map[string][]byte, error) {
cpuInfo := CPUInfo{}
logicalCount, err := cpu.Counts(true)
if err != nil {
return nil, errors.Wrap(err, "failed to count logical cpus")
}
cpuInfo.LogicalCount = logicalCount
physicalCount, err := cpu.Counts(false)
if err != nil {
return nil, errors.Wrap(err, "failed to count physical cpus")
}
cpuInfo.PhysicalCount = physicalCount
b, err := json.Marshal(cpuInfo)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal cpu info")
}
return map[string][]byte{
"system/cpu.json": b,
}, nil
}