Skip to content

Commit

Permalink
Average memory metrics instead of summing (#362)
Browse files Browse the repository at this point in the history
* Average RSS and VMS memory metrics and update unit tests for average mem metrics

---------

Co-authored-by: Oliver O'Mahony <[email protected]>
  • Loading branch information
Giners and oliveromahony authored Jul 3, 2023
1 parent 62e480f commit b88e571
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/core/metrics/metrics_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ func GetCalculationMap() map[string]string {
"nginx.workers.cpu.system": "sum",
"nginx.workers.cpu.total": "sum",
"nginx.workers.fds_count": "avg",
"nginx.workers.mem.vms": "sum",
"nginx.workers.mem.rss": "sum",
"nginx.workers.mem.vms": "avg",
"nginx.workers.mem.rss": "avg",
"nginx.workers.mem.rss_pct": "avg",
"nginx.workers.io.kbs_r": "sum",
"nginx.workers.io.kbs_w": "sum",
Expand Down
14 changes: 2 additions & 12 deletions src/core/metrics/sources/nginx_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,6 @@ func (c *NginxWorker) Collect(ctx context.Context, wg *sync.WaitGroup, m chan<-
cpuSystem = stats.Workers.CPUSystem
}

memRss := stats.Workers.MemRss - c.prevStats[pid].Workers.MemRss
if stats.Workers.MemRss < c.prevStats[pid].Workers.MemRss {
memRss = stats.Workers.MemRss
}

memVms := stats.Workers.MemVms - c.prevStats[pid].Workers.MemVms
if stats.Workers.MemVms < c.prevStats[pid].Workers.MemVms {
memVms = stats.Workers.MemVms
}

KbsR := stats.Workers.KbsR - c.prevStats[pid].Workers.KbsR
if stats.Workers.KbsR < c.prevStats[pid].Workers.KbsR {
KbsR = stats.Workers.KbsR
Expand All @@ -113,8 +103,8 @@ func (c *NginxWorker) Collect(ctx context.Context, wg *sync.WaitGroup, m chan<-
"cpu.system": float64(cpuSystem),
"cpu.total": float64(cpuSystem + cpuUser),
"fds_count": float64(stats.Workers.FdsCount),
"mem.vms": float64(memVms),
"mem.rss": float64(memRss),
"mem.vms": float64(stats.Workers.MemVms),
"mem.rss": float64(stats.Workers.MemRss),
"mem.rss_pct": float64(stats.Workers.MemRssPct),
"io.kbs_r": float64(KbsR),
"io.kbs_w": float64(KbsW),
Expand Down
8 changes: 4 additions & 4 deletions src/core/metrics/sources/nginx_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ func TestNginxWorkerCollector(t *testing.T) {
case "nginx.workers.io.kbs_r":
assert.Equal(t, float64(0), metric.Value)
case "nginx.workers.mem.rss":
assert.Equal(t, float64(0), metric.Value)
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.mem.rss_pct":
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.rlimit_nofile":
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.count":
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.mem.vms":
assert.Equal(t, float64(0), metric.Value)
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.fds_count":
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.cpu.user":
Expand Down Expand Up @@ -148,15 +148,15 @@ func TestNginxWorkerCollector(t *testing.T) {
case "nginx.workers.io.kbs_r":
assert.Equal(t, float64(0), metric.Value)
case "nginx.workers.mem.rss":
assert.Equal(t, float64(0), metric.Value)
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.mem.rss_pct":
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.rlimit_nofile":
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.count":
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.mem.vms":
assert.Equal(t, float64(0), metric.Value)
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.fds_count":
assert.Equal(t, float64(1), metric.Value)
case "nginx.workers.cpu.user":
Expand Down

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.

0 comments on commit b88e571

Please sign in to comment.