Fix swap metrics

This commit is contained in:
Trey Dockendorf 2020-02-14 12:01:24 -05:00
parent ffc560b3af
commit a40dc18d63
2 changed files with 8 additions and 8 deletions

View File

@ -277,8 +277,8 @@ func (e *Exporter) collect() ([]CgroupMetric, error) {
metric.cpuTotal = float64(stats.CPU.Usage.Total) / 1000000000.0
metric.memoryUsed = float64(stats.Memory.Usage.Usage)
metric.memoryTotal = float64(stats.Memory.Usage.Limit)
metric.swapUsed = float64(stats.Memory.Swap.Usage)
metric.swapTotal = float64(stats.Memory.Swap.Limit)
metric.swapUsed = float64(stats.Memory.Swap.Usage) - metric.memoryUsed
metric.swapTotal = float64(stats.Memory.Swap.Limit) - metric.memoryTotal
if cpus, err := getCPUs(name); err == nil {
metric.cpus = cpus
}

View File

@ -76,10 +76,10 @@ func TestCollectUserSlice(t *testing.T) {
if val := metrics[0].memoryTotal; val != 68719476736 {
t.Errorf("Unexpected value for memoryTotal, got %v", val)
}
if val := metrics[0].swapUsed; val != 8081408 {
if val := metrics[0].swapUsed; val != 0 {
t.Errorf("Unexpected value for swapUsed, got %v", val)
}
if val := metrics[0].swapTotal; val != 9223372036854771712 {
if val := metrics[0].swapTotal; val != 9223371968135295000 {
t.Errorf("Unexpected value for swapTotal, got %v", val)
}
if val := metrics[0].uid; val != "20821" {
@ -125,10 +125,10 @@ func TestCollectSLURM(t *testing.T) {
if val := metrics[0].memoryTotal; val != 2147483648 {
t.Errorf("Unexpected value for memoryTotal, got %v", val)
}
if val := metrics[0].swapUsed; val != 356352 {
if val := metrics[0].swapUsed; val != 0 {
t.Errorf("Unexpected value for swapUsed, got %v", val)
}
if val := metrics[0].swapTotal; val != 2147483648 {
if val := metrics[0].swapTotal; val != 0 {
t.Errorf("Unexpected value for swapTotal, got %v", val)
}
if val := metrics[0].uid; val != "20821" {
@ -177,10 +177,10 @@ func TestCollectTorque(t *testing.T) {
if val := metrics[0].memoryTotal; val != 196755132416 {
t.Errorf("Unexpected value for memoryTotal, got %v", val)
}
if val := metrics[0].swapUsed; val != 82553999360 {
if val := metrics[0].swapUsed; val != 0 {
t.Errorf("Unexpected value for swapUsed, got %v", val)
}
if val := metrics[0].swapTotal; val != 196755132416 {
if val := metrics[0].swapTotal; val != 0 {
t.Errorf("Unexpected value for swapTotal, got %v", val)
}
if val := metrics[0].uid; val != "" {