Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IHOST-2496] Added memoryUsageLimitPercent and changed memorySizeLimitBytes #20

Merged
merged 2 commits into from Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Next (TBD)

### Added
* Metric `memoryUsageLimitPercent` that reports the usage of the container memory as
a percentage of the limit. If there is no limit defined, this metric is not reported.

### Changed
* Metric `memorySizeLimitBytes` is not reported anymore when there is no such limit
(before it was reported as `0`)

## 1.1.1 (2020-02-07)
### Changed

Expand Down
7 changes: 7 additions & 0 deletions src/biz/metrics.go
Expand Up @@ -56,6 +56,7 @@ type Memory struct {
CacheUsageBytes uint64
RSSUsageBytes uint64
MemLimitBytes uint64
UsagePercent float64 // Usage percent from the limit, if any
}

// Processer defines the most essential interface of an exportable container Processer
Expand Down Expand Up @@ -191,11 +192,17 @@ func (mc *MetricsFetcher) memory(mem raw.Memory) Memory {
usage = mem.RSS + mem.SwapUsage - mem.FuzzUsage
}

usagePercent := float64(0)
if memLimits > 0 {
usagePercent = 100 * float64(usage) / float64(memLimits)
}

return Memory{
MemLimitBytes: memLimits,
CacheUsageBytes: mem.Cache,
RSSUsageBytes: mem.RSS,
UsageBytes: usage,
UsagePercent: usagePercent,
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/biz/metrics_test.go
Expand Up @@ -125,6 +125,9 @@ func TestMemory(t *testing.T) {
"reported usage %v should be >= 60MB (%v)", mem.UsageBytes, expectedUsage)
assert.Truef(t, mem.RSSUsageBytes >= expectedUsage,
"reported RSS %v should be >= 60MB (%v)", mem.RSSUsageBytes, expectedUsage)
expectedPercent := float64(expectedUsage) * 100 / memLimit
assert.Truef(t, mem.UsagePercent >= expectedPercent,
"reported Usage Percent %v should be >= %v", mem.RSSUsageBytes, expectedPercent)
// todo: test cachebytes against a fixed value
assert.True(t, mem.CacheUsageBytes > 0, "reported cache bytes %v should not be zero")

Expand Down
1 change: 1 addition & 0 deletions src/nri/metrics.go
Expand Up @@ -24,6 +24,7 @@ var (
metricMemoryCacheBytes = metricFunc("memoryCacheBytes", metric.GAUGE)
metricMemoryResidentSizeBytes = metricFunc("memoryResidentSizeBytes", metric.GAUGE)
metricMemorySizeLimitBytes = metricFunc("memorySizeLimitBytes", metric.GAUGE)
metricMemoryUsageLimitPercent = metricFunc("memoryUsageLimitPercent", metric.GAUGE)
metricIOReadCountPerSecond = metricFunc("ioReadCountPerSecond", metric.RATE)
metricIOWriteCountPerSecond = metricFunc("ioWriteCountPerSecond", metric.RATE)
metricIOReadBytesPerSecond = metricFunc("ioReadBytesPerSecond", metric.RATE)
Expand Down
10 changes: 8 additions & 2 deletions src/nri/sampler.go
Expand Up @@ -152,12 +152,18 @@ func labels(container types.Container) []entry {
}

func memory(mem *biz.Memory) []entry {
return []entry{
metrics := []entry{
metricMemoryCacheBytes(mem.CacheUsageBytes),
metricMemoryUsageBytes(mem.UsageBytes),
metricMemoryResidentSizeBytes(mem.RSSUsageBytes),
metricMemorySizeLimitBytes(mem.MemLimitBytes),
}
if mem.MemLimitBytes > 0 {
metrics = append(metrics,
metricMemorySizeLimitBytes(mem.MemLimitBytes),
metricMemoryUsageLimitPercent(mem.UsagePercent),
)
}
return metrics
}

func pids(pids *biz.Pids) []entry {
Expand Down