Skip to content

Commit

Permalink
fix: Harvest should collect power metrics from a1000 and a900 clusters (
Browse files Browse the repository at this point in the history
#3063)

Those platforms have sensors with slightly different names that Harvest needs to accommodate.

Fixes: #3062
  • Loading branch information
cgrinds authored Jul 24, 2024
1 parent c4dc19d commit 1c5f18e
Show file tree
Hide file tree
Showing 4 changed files with 550 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/collectors/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ type environmentMetric struct {

var ambientRegex = regexp.MustCompile(`^(Ambient Temp|Ambient Temp \d|PSU\d AmbTemp|PSU\d Inlet|PSU\d Inlet Temp|In Flow Temp|Front Temp|Bat_Ambient \d|Riser Inlet Temp)$`)

var powerInRegex = regexp.MustCompile(`^PSU\d (InPwr Monitor|InPower|PIN|Power In)$`)
var powerInRegex = regexp.MustCompile(`^PSU\d (InPwr Monitor|InPower|PIN|Power In|In Pwr)$`)

var voltageRegex = regexp.MustCompile(`^PSU\d (\d+V|InVoltage|VIN|AC In Volt)$`)
var voltageRegex = regexp.MustCompile(`^PSU\d (\d+V|InVoltage|VIN|AC In Volt|In Volt)$`)

var CurrentRegex = regexp.MustCompile(`^PSU\d (\d+V Curr|Curr|InCurrent|Curr IIN|AC In Curr)$`)
var currentRegex = regexp.MustCompile(`^PSU\d (\d+V Curr|Curr|InCurrent|Curr IIN|AC In Curr|In Curr)$`)

var eMetrics = []string{
"average_ambient_temperature",
Expand Down Expand Up @@ -128,7 +128,7 @@ func calculateEnvironmentMetrics(data *matrix.Matrix, logger *logging.Logger, va
isAmbientMatch := ambientRegex.MatchString(sensorName)
isPowerMatch := powerInRegex.MatchString(sensorName)
isVoltageMatch := voltageRegex.MatchString(sensorName)
isCurrentMatch := CurrentRegex.MatchString(sensorName)
isCurrentMatch := currentRegex.MatchString(sensorName)

if sensorType == "thermal" && isAmbientMatch {
if value, ok := metric.GetValueFloat64(instance); ok {
Expand Down
50 changes: 50 additions & 0 deletions cmd/collectors/sensor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/tree"
"github.com/netapp/harvest/v2/pkg/tree/node"
"github.com/tidwall/gjson"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
)
Expand Down Expand Up @@ -162,3 +164,51 @@ func TestSensor_Run(t *testing.T) {
}
}
}

func TestPowerRegex(t *testing.T) {
tests := []struct {
name string
path string
wantPower int
wantCurrent int
wantVoltage int
}{
{name: "a1000", path: "testdata/rest-sensors-a1000.json", wantPower: 4, wantCurrent: 4, wantVoltage: 4},
{name: "a900", path: "testdata/rest-sensors-a900.json", wantPower: 0, wantCurrent: 4, wantVoltage: 4},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
data, err := os.ReadFile(tt.path)
if err != nil {
panic(err)
}
powerMatches := countMatches(powerInRegex, data)
if powerMatches != tt.wantPower {
t.Errorf("power regex\ngot=%v\nwant=%v", powerMatches, tt.wantPower)
}

currentMatches := countMatches(currentRegex, data)
if currentMatches != tt.wantCurrent {
t.Errorf("current regex\ngot=%v\nwant=%v", currentMatches, tt.wantCurrent)
}

voltageMatches := countMatches(voltageRegex, data)
if voltageMatches != tt.wantVoltage {
t.Errorf("voltage regex\ngot=%v\nwant=%v", voltageMatches, tt.wantVoltage)
}
})
}
}

func countMatches(sensorRegex *regexp.Regexp, data []byte) int {
names := gjson.GetBytes(data, "records.#.name").Array()
matches := 0
for _, name := range names {
if sensorRegex.MatchString(name.String()) {
matches++
}
}

return matches
}
296 changes: 296 additions & 0 deletions cmd/collectors/testdata/rest-sensors-a1000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
{
"records": [
{
"node": {
"uuid": "52ad059c-349b-11ef-b340-d039eaa9ee10",
"name": "a1k-01",
"_links": {
"self": {
"href": "/api/cluster/nodes/52ad059c-349b-11ef-b340-d039eaa9ee10"
}
}
},
"index": 81,
"name": "PSU1 In Volt",
"type": "voltage",
"value": 210000,
"value_units": "mV",
"threshold_state": "normal",
"critical_low_threshold": 84000,
"warning_low_threshold": 90000,
"warning_high_threshold": 264000,
"critical_high_threshold": 276000,
"_links": {
"self": {
"href": "/api/cluster/sensors/52ad059c-349b-11ef-b340-d039eaa9ee10/81"
}
}
}
{
"node": {
"uuid": "52ad059c-349b-11ef-b340-d039eaa9ee10",
"name": "a1k-01",
"_links": {
"self": {
"href": "/api/cluster/nodes/52ad059c-349b-11ef-b340-d039eaa9ee10"
}
}
},
"index": 82,
"name": "PSU1 In Curr",
"type": "current",
"value": 2100,
"value_units": "mA",
"threshold_state": "normal",
"critical_low_threshold": 0,
"warning_high_threshold": 14100,
"critical_high_threshold": 15000,
"_links": {
"self": {
"href": "/api/cluster/sensors/52ad059c-349b-11ef-b340-d039eaa9ee10/82"
}
}
}
{
"node": {
"uuid": "52ad059c-349b-11ef-b340-d039eaa9ee10",
"name": "a1k-01",
"_links": {
"self": {
"href": "/api/cluster/nodes/52ad059c-349b-11ef-b340-d039eaa9ee10"
}
}
},
"index": 85,
"name": "PSU1 In Pwr",
"type": "unknown",
"value": 448,
"value_units": "W",
"threshold_state": "normal",
"_links": {
"self": {
"href": "/api/cluster/sensors/52ad059c-349b-11ef-b340-d039eaa9ee10/85"
}
}
}
{
"node": {
"uuid": "52ad059c-349b-11ef-b340-d039eaa9ee10",
"name": "a1k-01",
"_links": {
"self": {
"href": "/api/cluster/nodes/52ad059c-349b-11ef-b340-d039eaa9ee10"
}
}
},
"index": 91,
"name": "PSU2 In Volt",
"type": "voltage",
"value": 210000,
"value_units": "mV",
"threshold_state": "normal",
"critical_low_threshold": 84000,
"warning_low_threshold": 90000,
"warning_high_threshold": 264000,
"critical_high_threshold": 276000,
"_links": {
"self": {
"href": "/api/cluster/sensors/52ad059c-349b-11ef-b340-d039eaa9ee10/91"
}
}
}
{
"node": {
"uuid": "52ad059c-349b-11ef-b340-d039eaa9ee10",
"name": "a1k-01",
"_links": {
"self": {
"href": "/api/cluster/nodes/52ad059c-349b-11ef-b340-d039eaa9ee10"
}
}
},
"index": 92,
"name": "PSU2 In Curr",
"type": "current",
"value": 2100,
"value_units": "mA",
"threshold_state": "normal",
"critical_low_threshold": 0,
"warning_high_threshold": 14100,
"critical_high_threshold": 15000,
"_links": {
"self": {
"href": "/api/cluster/sensors/52ad059c-349b-11ef-b340-d039eaa9ee10/92"
}
}
}
{
"node": {
"uuid": "52ad059c-349b-11ef-b340-d039eaa9ee10",
"name": "a1k-01",
"_links": {
"self": {
"href": "/api/cluster/nodes/52ad059c-349b-11ef-b340-d039eaa9ee10"
}
}
},
"index": 95,
"name": "PSU2 In Pwr",
"type": "unknown",
"value": 456,
"value_units": "W",
"threshold_state": "normal",
"_links": {
"self": {
"href": "/api/cluster/sensors/52ad059c-349b-11ef-b340-d039eaa9ee10/95"
}
}
}
{
"node": {
"uuid": "800c0fcb-349b-11ef-8a0d-d039eaa9edb6",
"name": "a1k-02",
"_links": {
"self": {
"href": "/api/cluster/nodes/800c0fcb-349b-11ef-8a0d-d039eaa9edb6"
}
}
},
"index": 81,
"name": "PSU1 In Volt",
"type": "voltage",
"value": 212000,
"value_units": "mV",
"threshold_state": "normal",
"critical_low_threshold": 84000,
"warning_low_threshold": 90000,
"warning_high_threshold": 264000,
"critical_high_threshold": 276000,
"_links": {
"self": {
"href": "/api/cluster/sensors/800c0fcb-349b-11ef-8a0d-d039eaa9edb6/81"
}
}
}
{
"node": {
"uuid": "800c0fcb-349b-11ef-8a0d-d039eaa9edb6",
"name": "a1k-02",
"_links": {
"self": {
"href": "/api/cluster/nodes/800c0fcb-349b-11ef-8a0d-d039eaa9edb6"
}
}
},
"index": 82,
"name": "PSU1 In Curr",
"type": "current",
"value": 2100,
"value_units": "mA",
"threshold_state": "normal",
"critical_low_threshold": 0,
"warning_high_threshold": 14100,
"critical_high_threshold": 15000,
"_links": {
"self": {
"href": "/api/cluster/sensors/800c0fcb-349b-11ef-8a0d-d039eaa9edb6/82"
}
}
}
{
"node": {
"uuid": "800c0fcb-349b-11ef-8a0d-d039eaa9edb6",
"name": "a1k-02",
"_links": {
"self": {
"href": "/api/cluster/nodes/800c0fcb-349b-11ef-8a0d-d039eaa9edb6"
}
}
},
"index": 85,
"name": "PSU1 In Pwr",
"type": "unknown",
"value": 448,
"value_units": "W",
"threshold_state": "normal",
"_links": {
"self": {
"href": "/api/cluster/sensors/800c0fcb-349b-11ef-8a0d-d039eaa9edb6/85"
}
}
}
{
"node": {
"uuid": "800c0fcb-349b-11ef-8a0d-d039eaa9edb6",
"name": "a1k-02",
"_links": {
"self": {
"href": "/api/cluster/nodes/800c0fcb-349b-11ef-8a0d-d039eaa9edb6"
}
}
},
"index": 91,
"name": "PSU2 In Volt",
"type": "voltage",
"value": 210000,
"value_units": "mV",
"threshold_state": "normal",
"critical_low_threshold": 84000,
"warning_low_threshold": 90000,
"warning_high_threshold": 264000,
"critical_high_threshold": 276000,
"_links": {
"self": {
"href": "/api/cluster/sensors/800c0fcb-349b-11ef-8a0d-d039eaa9edb6/91"
}
}
}
{
"node": {
"uuid": "800c0fcb-349b-11ef-8a0d-d039eaa9edb6",
"name": "a1k-02",
"_links": {
"self": {
"href": "/api/cluster/nodes/800c0fcb-349b-11ef-8a0d-d039eaa9edb6"
}
}
},
"index": 92,
"name": "PSU2 In Curr",
"type": "current",
"value": 2100,
"value_units": "mA",
"threshold_state": "normal",
"critical_low_threshold": 0,
"warning_high_threshold": 14100,
"critical_high_threshold": 15000,
"_links": {
"self": {
"href": "/api/cluster/sensors/800c0fcb-349b-11ef-8a0d-d039eaa9edb6/92"
}
}
}
{
"node": {
"uuid": "800c0fcb-349b-11ef-8a0d-d039eaa9edb6",
"name": "a1k-02",
"_links": {
"self": {
"href": "/api/cluster/nodes/800c0fcb-349b-11ef-8a0d-d039eaa9edb6"
}
}
},
"index": 95,
"name": "PSU2 In Pwr",
"type": "unknown",
"value": 464,
"value_units": "W",
"threshold_state": "normal",
"_links": {
"self": {
"href": "/api/cluster/sensors/800c0fcb-349b-11ef-8a0d-d039eaa9edb6/95"
}
}
}
]
}
Loading

0 comments on commit 1c5f18e

Please sign in to comment.