Skip to content

Commit 098b9ac

Browse files
author
Douglas Paz
committed
feat: add support to os cpu percent es v2.x
Signed-off-by: Douglas Paz <[email protected]>
1 parent 52f4ec3 commit 098b9ac

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

collector/nodes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ func NewNodes(logger log.Logger, client *http.Client, url *url.URL, all bool, no
249249
defaultNodeLabels, nil,
250250
),
251251
Value: func(node NodeStatsNodeResponse) float64 {
252+
if node.OS.CPUPercent != nil {
253+
return float64(*node.OS.CPUPercent)
254+
}
252255
return float64(node.OS.CPU.Percent)
253256
},
254257
Labels: defaultNodeLabelValues,

collector/nodes_response.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,11 @@ type NodeStatsOSResponse struct {
283283
Uptime int64 `json:"uptime_in_millis"`
284284
// LoadAvg was an array of per-cpu values pre-2.0, and is a string in 2.0
285285
// Leaving this here in case we want to implement parsing logic later
286-
LoadAvg json.RawMessage `json:"load_average"`
287-
CPU NodeStatsOSCPUResponse `json:"cpu"`
288-
Mem NodeStatsOSMemResponse `json:"mem"`
289-
Swap NodeStatsOSSwapResponse `json:"swap"`
286+
LoadAvg json.RawMessage `json:"load_average"`
287+
CPU NodeStatsOSCPUResponse `json:"cpu"`
288+
CPUPercent *int64 `json:"cpu_percent"`
289+
Mem NodeStatsOSMemResponse `json:"mem"`
290+
Swap NodeStatsOSSwapResponse `json:"swap"`
290291
}
291292

292293
// NodeStatsOSMemResponse defines node stats operating system memory usage structure

0 commit comments

Comments
 (0)