Skip to content

Commit

Permalink
[hostmetricsreceiver]: support reporting amount of available logical …
Browse files Browse the repository at this point in the history
…and physical CPUs (#23231)

**Link to tracking Issue:** #22099 

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
  • Loading branch information
frzifus and mx-psi authored Aug 2, 2023
1 parent 8dc9eaf commit 6d208cf
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 32 deletions.
21 changes: 21 additions & 0 deletions .chloggen/hostmetricsreceiver_support_cpu_count.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# 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: hostmetricsreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Report logical and physical number of CPUs as metric.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [22099]

# (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: |
Use the `system.cpu.logical.count::enabled` and `system.cpu.physical.count::enabled` flags to enable them
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,17 @@ func (s *scraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
return pmetric.NewMetrics(), scrapererror.NewPartialScrapeError(err, metricsLen)
}

numCPU, err := cpu.Counts(false)
if err != nil {
return pmetric.NewMetrics(), scrapererror.NewPartialScrapeError(err, metricsLen)
}
s.mb.RecordSystemCPUPhysicalCountDataPoint(now, int64(numCPU))

numCPU, err = cpu.Counts(true)
if err != nil {
return pmetric.NewMetrics(), scrapererror.NewPartialScrapeError(err, metricsLen)
}
s.mb.RecordSystemCPULogicalCountDataPoint(now, int64(numCPU))

return s.mb.Emit(), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func assertDatapointValueAndStringAttributes(t *testing.T, dp pmetric.NumberData
func assertCPUMetricValid(t *testing.T, metric pmetric.Metric, startTime pcommon.Timestamp) {
expected := pmetric.NewMetric()
expected.SetName("system.cpu.time")
expected.SetDescription("Total CPU seconds broken down by different states.")
expected.SetDescription("Total seconds each logical CPU spent on each mode.")
expected.SetUnit("s")
expected.SetEmptySum()
internal.AssertDescriptorEqual(t, expected, metric)
Expand Down Expand Up @@ -368,7 +368,7 @@ func assertCPUMetricHasLinuxSpecificStateLabels(t *testing.T, metric pmetric.Met
func assertCPUUtilizationMetricValid(t *testing.T, metric pmetric.Metric, startTime pcommon.Timestamp) {
expected := pmetric.NewMetric()
expected.SetName("system.cpu.utilization")
expected.SetDescription("Percentage of CPU time broken down by different states.")
expected.SetDescription("Difference in system.cpu.time since the last measurement, divided by the elapsed time and number of logical CPUs.")
expected.SetUnit("1")
expected.SetEmptyGauge()
internal.AssertDescriptorEqual(t, expected, metric)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metrics:
### system.cpu.time
Total CPU seconds broken down by different states.
Total seconds each logical CPU spent on each mode.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
Expand All @@ -26,7 +26,7 @@ Total CPU seconds broken down by different states.
| Name | Description | Values |
| ---- | ----------- | ------ |
| cpu | CPU number starting at 0. | Any Str |
| cpu | Logical CPU number starting at 0. | Any Str |
| state | Breakdown of CPU usage by type. | Str: ``idle``, ``interrupt``, ``nice``, ``softirq``, ``steal``, ``system``, ``user``, ``wait`` |
## Optional Metrics
Expand All @@ -39,9 +39,25 @@ metrics:
enabled: true
```
### system.cpu.logical.count
Number of available logical CPUs.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {cpu} | Sum | Int | Cumulative | false |
### system.cpu.physical.count
Number of available physical CPUs.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {cpu} | Sum | Int | Cumulative | false |
### system.cpu.utilization
Percentage of CPU time broken down by different states.
Difference in system.cpu.time since the last measurement, divided by the elapsed time and number of logical CPUs.
| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
Expand All @@ -51,5 +67,5 @@ Percentage of CPU time broken down by different states.
| Name | Description | Values |
| ---- | ----------- | ------ |
| cpu | CPU number starting at 0. | Any Str |
| cpu | Logical CPU number starting at 0. | Any Str |
| state | Breakdown of CPU usage by type. | Str: ``idle``, ``interrupt``, ``nice``, ``softirq``, ``steal``, ``system``, ``user``, ``wait`` |

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.

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

Loading

0 comments on commit 6d208cf

Please sign in to comment.