Skip to content

Commit

Permalink
fix: Count the number of vCPUs instead of the number of CPU cores
Browse files Browse the repository at this point in the history
Based on the available documents, the client should collect and export "a single
metric that counts the number of VCPUs on the system". Let's use a value that
can be calculated as: `cat /proc/cpuinfo | grep processor | wc -l`

There are several alternative options and methods to consider, but let's start
with the easist one that doesn't require any additional dependencies.

Use the metric name `system_cpu_logical_count` that follows semantic conventions
for OTEL: open-telemetry/semantic-conventions#99
  • Loading branch information
poncovka authored and pvoborni committed Sep 27, 2023
1 parent b552e01 commit 7af0f82
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
9 changes: 2 additions & 7 deletions hostinfo/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ func GetCPUCount() (uint, error) {
return 0, fmt.Errorf("GetCPUCount: failed to load CPUInfo: %w", err)
}

if len(info) == 0 {
return 0, fmt.Errorf("GetCPUCount: no value in CPUInfo")
}

cpuCores := info[0].CPUCores

return cpuCores, nil
cpuCount := uint(len(info))
return cpuCount, nil
}
20 changes: 10 additions & 10 deletions hostinfo/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

type HostInfo struct {
CpuCoreCount uint
HostId string
CertPath string
CertKeyPath string
CpuCount uint
HostId string
CertPath string
CertKeyPath string
}

func LoadHostInfo(c *config.Config) (*HostInfo, error) {

cpuCoreCount, err := GetCPUCount()
cpuCount, err := GetCPUCount()
if err != nil {
return nil, err
}
Expand All @@ -26,16 +26,16 @@ func LoadHostInfo(c *config.Config) (*HostInfo, error) {
}

return &HostInfo{
CpuCoreCount: cpuCoreCount,
HostId: hostId,
CertPath: GetCertPath(c),
CertKeyPath: GetCertKeyPath(c),
CpuCount: cpuCount,
HostId: hostId,
CertPath: GetCertPath(c),
CertKeyPath: GetCertKeyPath(c),
}, nil
}

func (hi *HostInfo) Print() {
fmt.Println("HostInfo:")
fmt.Println(" CpuCoreCount: ", hi.CpuCoreCount)
fmt.Println(" CpuCount: ", hi.CpuCount)
fmt.Println(" HostId: ", hi.HostId)
fmt.Println(" CertPath: ", hi.CertPath)
fmt.Println(" CertKeyPath: ", hi.CertKeyPath)
Expand Down
4 changes: 2 additions & 2 deletions notify/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func hostInfo2WriteRequest(hostinfo *hostinfo.HostInfo) *prompb.WriteRequest {
labels := []prompb.Label{
{
Name: "__name__",
Value: "cpu_core_count",
Value: "system_cpu_logical_count",
},
{
Name: "hostId",
Expand All @@ -101,7 +101,7 @@ func hostInfo2WriteRequest(hostinfo *hostinfo.HostInfo) *prompb.WriteRequest {

samples := []prompb.Sample{
{
Value: float64(hostinfo.CpuCoreCount),
Value: float64(hostinfo.CpuCount),
Timestamp: timestamp,
},
}
Expand Down

0 comments on commit 7af0f82

Please sign in to comment.