Skip to content

Commit

Permalink
fix: don't collect system.cpu.utilization per-cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
antonblock committed Apr 23, 2024
1 parent e833bc5 commit b246ba2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func (s *scraper) start(ctx context.Context, _ component.Host) error {
func (s *scraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
ctx = context.WithValue(ctx, common.EnvKey, s.config.EnvMap)
now := pcommon.NewTimestampFromTime(s.now())
cpuTimes, err := s.times(ctx, true /*percpu=*/)
// set percpu=false to support Windows 7
cpuTimes, err := s.times(ctx, false /*percpu=*/)
if err != nil {
return pmetric.NewMetrics(), scrapererror.NewPartialScrapeError(err, metricsLen)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@ func assertCPUMetricValid(t *testing.T, metric pmetric.Metric, startTime pcommon
if startTime != 0 {
internal.AssertSumMetricStartTimeEquals(t, metric, startTime)
}
assert.GreaterOrEqual(t, metric.Sum().DataPoints().Len(), 4*runtime.NumCPU())
cpuUtilizationStates := []string{"user", "system", "idle", "interrupt"}

// CPU time is not per-CPU, just assert we collected at least one metric for each state
assert.GreaterOrEqual(t, metric.Sum().DataPoints().Len(), len(cpuUtilizationStates))
internal.AssertSumMetricHasAttribute(t, metric, 0, "cpu")
internal.AssertSumMetricHasAttributeValue(t, metric, 0, "state",
pcommon.NewValueStr(metadata.AttributeStateUser.String()))
Expand Down

0 comments on commit b246ba2

Please sign in to comment.