File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ AWS_PROFILE=myprofile AWS_REGION=us-west-2
63
63
` eks-node-viewer` supports some custom label names that can be passed to the ` --extra-labels` to display additional node information.
64
64
65
65
- ` eks-node-viewer/node-age` - Age of the node
66
+ - ` eks-node-viewer/node-cpu-usage` - CPU usage (requests)
67
+ - ` eks-node-viewer/node-memory-usage` - Memory usage (requests)
68
+ - ` eks-node-viewer/node-pods-usage` - Pod usage (requests)
69
+ - ` eks-node-viewer/node-ephemeral-storage-usage` - Ephemeral Storage usage (requests)
66
70
67
71
# ## Default Options
68
72
You can supply default options to ` eks-node-viewer` by creating a file named ` .eks-node-viewer` in your home directory and specifying
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package model
17
17
import (
18
18
"fmt"
19
19
"math"
20
+ "regexp"
20
21
"sync"
21
22
"time"
22
23
@@ -233,11 +234,33 @@ func (n *Node) UpdatePrice(pricing *pricing.Provider) {
233
234
}
234
235
}
235
236
237
+ var resourceLabelRe = regexp .MustCompile ("eks-node-viewer/node-(.*?)-usage" )
238
+
236
239
// ComputeLabel computes dynamic labels
237
240
func (n * Node ) ComputeLabel (labelName string ) string {
238
241
switch labelName {
239
242
case "eks-node-viewer/node-age" :
240
243
return duration .HumanDuration (time .Since (n .Created ()))
241
244
}
245
+ // resource based custom labels
246
+ if match := resourceLabelRe .FindStringSubmatch (labelName ); len (match ) > 0 {
247
+ return pctUsage (n .Allocatable (), n .Used (), match [1 ])
248
+ }
242
249
return labelName
243
250
}
251
+
252
+ func pctUsage (allocatable v1.ResourceList , used v1.ResourceList , resource string ) string {
253
+ allocRes , hasAlloc := allocatable [v1 .ResourceName (resource )]
254
+ if ! hasAlloc {
255
+ return "N/A"
256
+ }
257
+ usedRes , hasUsed := used [v1 .ResourceName (resource )]
258
+ if ! hasUsed || usedRes .AsApproximateFloat64 () == 0 {
259
+ return "0%"
260
+ }
261
+ pctUsed := 0.0
262
+ if allocRes .AsApproximateFloat64 () != 0 {
263
+ pctUsed = 100 * (usedRes .AsApproximateFloat64 () / allocRes .AsApproximateFloat64 ())
264
+ }
265
+ return fmt .Sprintf ("%.0f%%" , pctUsed )
266
+ }
You can’t perform that action at this time.
0 commit comments