Skip to content

Commit

Permalink
only publish measured metrics (#10376)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmood Ali authored and schmichael committed May 14, 2021
1 parent bcb3a9e commit 7387bd5
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions client/allocrunner/taskrunner/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/client/vaultclient"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/pluginutils/hclspecutils"
"github.com/hashicorp/nomad/helper/pluginutils/hclutils"
"github.com/hashicorp/nomad/helper/uuid"
Expand Down Expand Up @@ -1315,20 +1316,22 @@ func (tr *TaskRunner) setGaugeForMemory(ru *cstructs.TaskResourceUsage) {
allocatedMem = float32(taskRes.Memory.MemoryMB) * 1024 * 1024
}

metrics.SetGaugeWithLabels([]string{"client", "allocs", "memory", "rss"},
float32(ru.ResourceUsage.MemoryStats.RSS), tr.baseLabels)
metrics.SetGaugeWithLabels([]string{"client", "allocs", "memory", "cache"},
float32(ru.ResourceUsage.MemoryStats.Cache), tr.baseLabels)
metrics.SetGaugeWithLabels([]string{"client", "allocs", "memory", "swap"},
float32(ru.ResourceUsage.MemoryStats.Swap), tr.baseLabels)
metrics.SetGaugeWithLabels([]string{"client", "allocs", "memory", "usage"},
float32(ru.ResourceUsage.MemoryStats.Usage), tr.baseLabels)
metrics.SetGaugeWithLabels([]string{"client", "allocs", "memory", "max_usage"},
float32(ru.ResourceUsage.MemoryStats.MaxUsage), tr.baseLabels)
metrics.SetGaugeWithLabels([]string{"client", "allocs", "memory", "kernel_usage"},
float32(ru.ResourceUsage.MemoryStats.KernelUsage), tr.baseLabels)
metrics.SetGaugeWithLabels([]string{"client", "allocs", "memory", "kernel_max_usage"},
float32(ru.ResourceUsage.MemoryStats.KernelMaxUsage), tr.baseLabels)
ms := ru.ResourceUsage.MemoryStats

publishMetric := func(v uint64, reported, measured string) {
if v != 0 || helper.SliceStringContains(ms.Measured, measured) {
metrics.SetGaugeWithLabels([]string{"client", "allocs", "memory", reported},
float32(v), tr.baseLabels)
}
}

publishMetric(ms.RSS, "rss", "RSS")
publishMetric(ms.Cache, "cache", "Cache")
publishMetric(ms.Swap, "swap", "Swap")
publishMetric(ms.Usage, "usage", "Usage")
publishMetric(ms.MaxUsage, "max_usage", "Max Usage")
publishMetric(ms.KernelUsage, "kernel_usage", "Kernel Usage")
publishMetric(ms.KernelMaxUsage, "kernel_max_usage", "Kernel Max Usage")
if allocatedMem > 0 {
metrics.SetGaugeWithLabels([]string{"client", "allocs", "memory", "allocated"},
allocatedMem, tr.baseLabels)
Expand Down

0 comments on commit 7387bd5

Please sign in to comment.