Skip to content

Commit 22a8dbc

Browse files
author
Douglas Paz
committed
feat: add support to os load average 1m v2.x
Signed-off-by: Douglas Paz <[email protected]>
1 parent 098b9ac commit 22a8dbc

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

collector/nodes.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ func NewNodes(logger log.Logger, client *http.Client, url *url.URL, all bool, no
213213
defaultNodeLabels, nil,
214214
),
215215
Value: func(node NodeStatsNodeResponse) float64 {
216+
// LoadAvg was an array of per-cpu values pre-2.0, and is a float in 2.x
217+
if node.OS.LoadAvg != nil {
218+
// trying parse as float
219+
var loadAvgAsFloat float64
220+
if json.Unmarshal(*node.OS.LoadAvg, &loadAvgAsFloat) == nil {
221+
return loadAvgAsFloat
222+
}
223+
}
216224
return node.OS.CPU.LoadAvg.Load1
217225
},
218226
Labels: defaultNodeLabelValues,

collector/nodes_response.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,9 @@ type NodeStatsIndicesCacheResponse struct {
279279

280280
// NodeStatsOSResponse is a representation of a operating system stats, load average, mem, swap
281281
type NodeStatsOSResponse struct {
282-
Timestamp int64 `json:"timestamp"`
283-
Uptime int64 `json:"uptime_in_millis"`
284-
// LoadAvg was an array of per-cpu values pre-2.0, and is a string in 2.0
285-
// Leaving this here in case we want to implement parsing logic later
286-
LoadAvg json.RawMessage `json:"load_average"`
282+
Timestamp int64 `json:"timestamp"`
283+
Uptime int64 `json:"uptime_in_millis"`
284+
LoadAvg *json.RawMessage `json:"load_average"`
287285
CPU NodeStatsOSCPUResponse `json:"cpu"`
288286
CPUPercent *int64 `json:"cpu_percent"`
289287
Mem NodeStatsOSMemResponse `json:"mem"`

0 commit comments

Comments
 (0)