Skip to content

Commit

Permalink
set percentage node used instead of available (#95)
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Minář <michal.minar@id.ethz.ch>
  • Loading branch information
miminar authored Jul 1, 2024
1 parent 4bff489 commit cd185cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pkg/node/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package node

import (
"fmt"
"math"

"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
)
Expand Down Expand Up @@ -79,7 +81,10 @@ func (n *Node) SetMetrics(nodeName string, availableBytes float64, capacityBytes
}

if n.nodePercentage {
setValue := (availableBytes / capacityBytes) * 100.0
setValue := math.NaN()
if capacityBytes > 0. {
setValue = math.Max(capacityBytes-availableBytes, 0.) * 100.0 / capacityBytes
}
nodePercentageGaugeVec.With(prometheus.Labels{"node_name": nodeName}).Set(setValue)
log.Debug().Msg(fmt.Sprintf("Node: %s percentage used: %f", nodeName, setValue))
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/pod/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package pod

import (
"fmt"
"math"

"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -166,9 +168,11 @@ func (cr Collector) SetMetrics(podName string, podNamespace string, nodeName str
if c.limit != 0 {
// Use Limit from Container
setValue = (usedBytes / c.limit) * 100.0
} else if capacityBytes > 0. {
// Default to Node Used Ephemeral Storage
setValue = math.Max(capacityBytes-availableBytes, 0.) * 100.0 / capacityBytes
} else {
// Default to Node Available Ephemeral Storage
setValue = (availableBytes / capacityBytes) * 100.0
setValue = math.NaN()
}
containerPercentageLimitsVec.With(labels).Set(setValue)
}
Expand Down

0 comments on commit cd185cd

Please sign in to comment.