Skip to content

Commit

Permalink
Merge pull request #393 from axw/cpu-metrics-no-scaling
Browse files Browse the repository at this point in the history
Don't scale CPU metrics
  • Loading branch information
axw authored Dec 14, 2018
2 parents 9abbae5 + 0a4779d commit 6973650
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ matrix:
- go: "1.x"

before_install:
- go get -v golang.org/x/tools/cmd/goimports
- if (go run scripts/mingoversion.go 1.10 &>/dev/null); then go get -v golang.org/x/lint/golint; fi
- |
if (go run scripts/mingoversion.go 1.10 &>/dev/null); then
go get -v golang.org/x/lint/golint;
go get -v golang.org/x/tools/cmd/goimports;
fi
script:
- make install check
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased](https://github.com/elastic/apm-agent-go/compare/v1.1.0...master)
## [Unreleased](https://github.com/elastic/apm-agent-go/compare/v1.1.1...master)

## [v1.1.1](https://github.com/elastic/apm-agent-go/releases/tag/v1.1.1)

- CPU% metrics are now correctly in the range [0,1]

## [v1.1.0](https://github.com/elastic/apm-agent-go/releases/tag/v1.1.0)

Expand Down
6 changes: 3 additions & 3 deletions builtin_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ func calculateCPUUsage(current, last cpuMetrics) (systemUsage, processUsage floa
return 0, 0
}

idlePercent := 100 * float64(idleDelta) / float64(systemTotalDelta)
systemUsage = 100 - idlePercent
idlePercent := float64(idleDelta) / float64(systemTotalDelta)
systemUsage = 1 - idlePercent

processTotalDelta := current.process.Total() - last.process.Total()
processUsage = 100 * float64(processTotalDelta) / float64(systemTotalDelta)
processUsage = float64(processTotalDelta) / float64(systemTotalDelta)

return systemUsage, processUsage
}
Expand Down
8 changes: 8 additions & 0 deletions metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ func TestTracerMetricsBuiltin(t *testing.T) {
}, "value: %v", gcPct.Value)
}

// CPU% should be in the range [0,1], not [0,100].
cpuTotalNormPct := builtinMetrics.Samples["system.cpu.total.norm.pct"]
if assert.NotNil(t, gcPct.Value) {
assert.Condition(t, func() bool {
return cpuTotalNormPct.Value >= 0 && cpuTotalNormPct.Value <= 1
}, "value: %v", cpuTotalNormPct.Value)
}

expected := []string{
"golang.goroutines",
"golang.heap.allocations.mallocs",
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package apm

const (
// AgentVersion is the Elastic APM Go Agent version.
AgentVersion = "1.1.0"
AgentVersion = "1.1.1"
)

0 comments on commit 6973650

Please sign in to comment.