Skip to content

Commit

Permalink
[receiver/vcenter] add vcenter vm cpu usage metrics (open-telemetry#2…
Browse files Browse the repository at this point in the history
…0894)

* add vcenter vm cpu usage metrics
  • Loading branch information
schmikei committed Apr 24, 2023
1 parent 93027c2 commit 91fb064
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 10 deletions.
16 changes: 16 additions & 0 deletions .chloggen/vm_cpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: vcenterreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Adds VM CPU usage and utilization metrics

# One or more tracking issues related to the change
issues: [20895]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
16 changes: 16 additions & 0 deletions receiver/vcenterreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ The usage of the memory by the resource pool.
| ---- | ----------- | ---------- | ----------------------- | --------- |
| MiBy | Sum | Int | Cumulative | false |

### vcenter.vm.cpu.usage

The amount of CPU used by the VM.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| MHz | Sum | Int | Cumulative | false |

### vcenter.vm.cpu.utilization

The CPU utilization of the VM.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| % | Gauge | Double |

### vcenter.vm.disk.latency.avg

The latency of operations to the virtual machine's disk.
Expand Down
124 changes: 124 additions & 0 deletions receiver/vcenterreceiver/internal/metadata/generated_metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ all_set:
enabled: true
vcenter.resource_pool.memory.usage:
enabled: true
vcenter.vm.cpu.usage:
enabled: true
vcenter.vm.cpu.utilization:
enabled: true
vcenter.vm.disk.latency.avg:
enabled: true
vcenter.vm.disk.latency.max:
Expand Down Expand Up @@ -136,6 +140,10 @@ none_set:
enabled: false
vcenter.resource_pool.memory.usage:
enabled: false
vcenter.vm.cpu.usage:
enabled: false
vcenter.vm.cpu.utilization:
enabled: false
vcenter.vm.disk.latency.avg:
enabled: false
vcenter.vm.disk.latency.max:
Expand Down
13 changes: 6 additions & 7 deletions receiver/vcenterreceiver/internal/mockserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ And then running the receiver against the proxy.
```yaml
receivers:
vcenter:
metrics:
endpoint: https://localhost:56626
username: "otelu"
password: "otelp"
tls:
insecure: false
insecure_skip_verify: true
endpoint: https://localhost:56626
username: "otelu"
password: "otelp"
tls:
insecure: false
insecure_skip_verify: true

service:
pipelines:
Expand Down
3 changes: 3 additions & 0 deletions receiver/vcenterreceiver/internal/mockserver/client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ func routeRetreiveProperties(t *testing.T, body map[string]interface{}) ([]byte,
if ps == "name" {
return loadResponse("host-names.xml")
}
if ps == "summary.hardware" {
return loadResponse("host-properties.xml")
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@
<timestamp>2022-05-17T14:28:26.159606Z</timestamp>
</storage>
<quickStats>
<overallCpuUsage>0</overallCpuUsage>
<overallCpuUsage>12</overallCpuUsage>
<overallCpuDemand>0</overallCpuDemand>
<overallCpuReadiness>0</overallCpuReadiness>
<guestMemoryUsage>163</guestMemoryUsage>
Expand Down
16 changes: 16 additions & 0 deletions receiver/vcenterreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,19 @@ metrics:
aggregation: cumulative
attributes: []
extended_documentation: As measured over the most recent 20s interval.
vcenter.vm.cpu.utilization:
enabled: true
description: The CPU utilization of the VM.
unit: "%"
gauge:
value_type: double
attributes: []
vcenter.vm.cpu.usage:
enabled: true
description: The amount of CPU used by the VM.
unit: "MHz"
sum:
monotonic: false
value_type: int
aggregation: cumulative
attributes: []
28 changes: 28 additions & 0 deletions receiver/vcenterreceiver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (v *vcenterMetricScraper) recordHostSystemMemoryUsage(
func (v *vcenterMetricScraper) recordVMUsages(
now pcommon.Timestamp,
vm mo.VirtualMachine,
hs mo.HostSystem,
) {
memUsage := vm.Summary.QuickStats.GuestMemoryUsage
balloonedMem := vm.Summary.QuickStats.BalloonedMemory
Expand All @@ -71,6 +72,33 @@ func (v *vcenterMetricScraper) recordVMUsages(
diskUtilization := float64(diskUsed) / float64(diskFree+diskUsed) * 100
v.mb.RecordVcenterVMDiskUtilizationDataPoint(now, diskUtilization)
}

s := vm.Summary
z := s.QuickStats

cpuUsage := z.OverallCpuUsage
ncpu := vm.Config.Hardware.NumCPU

// if no cpu usage, we probably shouldn't return a value. Most likely the VM is unavailable
// or is unreachable.
if cpuUsage == 0 {
return
}

// https://communities.vmware.com/t5/VMware-code-Documents/Resource-Management/ta-p/2783456
// VirtualMachine.runtime.maxCpuUsage is a property of the virtual machine, indicating the limit value.
// This value is always equal to the limit value set for that virtual machine.
// If no limit, it has full host mhz * vm.Config.Hardware.NumCPU.
var cpuUtil float64
if vm.Runtime.MaxCpuUsage != 0 {
cpuUtil = 100 * float64(cpuUsage) / float64(vm.Runtime.MaxCpuUsage)
} else {
cpuUtil = 100 * float64(cpuUsage) / float64(ncpu*hs.Summary.Hardware.CpuMhz)
}

v.mb.RecordVcenterVMCPUUsageDataPoint(now, int64(cpuUsage))
v.mb.RecordVcenterVMCPUUtilizationDataPoint(now, cpuUtil)

}

func (v *vcenterMetricScraper) recordDatastoreProperties(
Expand Down
Loading

0 comments on commit 91fb064

Please sign in to comment.