mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
* 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>
39 lines
798 B
Go
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
|
|
}
|