Skip to content

Commit

Permalink
go.d megacli: add bbu capacity degradation % (netdata#18211)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Jul 22, 2024
1 parent 143c409 commit 64a1c51
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 12 deletions.
18 changes: 18 additions & 0 deletions src/go/plugin/go.d/modules/megacli/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (

prioBBURelativeCharge
prioBBURechargeCycles
prioBBUCapDegradationPerc
prioBBUTemperature
)

Expand Down Expand Up @@ -76,6 +77,7 @@ var (
var bbuChartsTmpl = module.Charts{
bbuRelativeChargeChartsTmpl.Copy(),
bbuRechargeCyclesChartsTmpl.Copy(),
bbuCapacityDegradationChartsTmpl.Copy(),
bbuTemperatureChartsTmpl.Copy(),
}

Expand Down Expand Up @@ -104,6 +106,18 @@ var (
{ID: "bbu_adapter_%s_cycle_count", Name: "recharge"},
},
}
bbuCapacityDegradationChartsTmpl = module.Chart{
ID: "bbu_adapter_%s_capacity_degradation",
Title: "BBU capacity degradation",
Units: "percent",
Fam: "bbu charge",
Ctx: "megacli.bbu_capacity_degradation",
Type: module.Line,
Priority: prioBBUCapDegradationPerc,
Dims: module.Dims{
{ID: "bbu_adapter_%s_capacity_degradation_perc", Name: "cap_degradation"},
},
}
bbuTemperatureChartsTmpl = module.Chart{
ID: "bbu_adapter_%s_temperature",
Title: "BBU temperature",
Expand Down Expand Up @@ -161,6 +175,10 @@ func (m *MegaCli) addPhysDriveCharts(pd *megaPhysDrive) {
func (m *MegaCli) addBBUCharts(bbu *megaBBU) {
charts := bbuChartsTmpl.Copy()

if _, ok := calcCapDegradationPerc(bbu); !ok {
_ = charts.Remove(bbuCapacityDegradationChartsTmpl.ID)
}

for _, chart := range *charts {
chart.ID = fmt.Sprintf(chart.ID, bbu.adapterNumber)
chart.Labels = []module.Label{
Expand Down
51 changes: 40 additions & 11 deletions src/go/plugin/go.d/modules/megacli/collect_bbu.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import (
"bufio"
"bytes"
"fmt"
"strconv"
"strings"
)

type megaBBU struct {
adapterNumber string
batteryType string
temperature string
relativeStateOfCharge string
absoluteStateOfCharge string // apparently can be 0 while relative > 0 (e.g. relative 91%, absolute 0%)
cycleCount string
adapterNumber string
batteryType string
temperature string
rsoc string
asoc string // apparently can be 0 while relative > 0 (e.g. relative 91%, absolute 0%)
cycleCount string
fullChargeCap string
designCap string
}

func (m *MegaCli) collectBBU(mx map[string]int64) error {
Expand Down Expand Up @@ -43,9 +46,12 @@ func (m *MegaCli) collectBBU(mx map[string]int64) error {
px := fmt.Sprintf("bbu_adapter_%s_", bbu.adapterNumber)

writeInt(mx, px+"temperature", bbu.temperature)
writeInt(mx, px+"relative_state_of_charge", bbu.relativeStateOfCharge)
writeInt(mx, px+"absolute_state_of_charge", bbu.absoluteStateOfCharge)
writeInt(mx, px+"relative_state_of_charge", bbu.rsoc)
writeInt(mx, px+"absolute_state_of_charge", bbu.asoc)
writeInt(mx, px+"cycle_count", bbu.cycleCount)
if v, ok := calcCapDegradationPerc(bbu); ok {
mx[px+"capacity_degradation_perc"] = v
}
}

m.Debugf("found %d BBUs", len(m.bbu))
Expand Down Expand Up @@ -76,9 +82,11 @@ func parseBBUInfo(bs []byte) (map[string]*megaBBU, error) {
case strings.HasPrefix(line, "BBU Capacity Info for Adapter"):
section = "capacity"
continue
case strings.HasPrefix(line, "BBU Design Info for Adapter"):
section = "design"
continue
case strings.HasPrefix(line, "BBU Firmware Status"),
strings.HasPrefix(line, "BBU GasGauge Status"),
strings.HasPrefix(line, "BBU Design Info for Adapter"),
strings.HasPrefix(line, "BBU Properties for Adapter"):
section = ""
continue
Expand All @@ -99,14 +107,35 @@ func parseBBUInfo(bs []byte) (map[string]*megaBBU, error) {
case "capacity":
switch {
case strings.HasPrefix(line, "Relative State of Charge:"):
bbu.relativeStateOfCharge = getColonSepNumValue(line)
bbu.rsoc = getColonSepNumValue(line)
case strings.HasPrefix(line, "Absolute State of charge:"):
bbu.absoluteStateOfCharge = getColonSepNumValue(line)
bbu.asoc = getColonSepNumValue(line)
case strings.HasPrefix(line, "Full Charge Capacity:"):
bbu.fullChargeCap = getColonSepNumValue(line)
case strings.HasPrefix(line, "Cycle Count:"):
bbu.cycleCount = getColonSepNumValue(line)
}
case "design":
if strings.HasPrefix(line, "Design Capacity:") {
bbu.designCap = getColonSepNumValue(line)
}
}
}

return bbus, nil
}

func calcCapDegradationPerc(bbu *megaBBU) (int64, bool) {
full, err := strconv.ParseInt(bbu.fullChargeCap, 10, 64)
if err != nil || full == 0 {
return 0, false
}
design, err := strconv.ParseInt(bbu.designCap, 10, 64)
if err != nil || design == 0 {
return 0, false
}

v := 100 - float64(full)/float64(design)*100

return int64(v), true
}
5 changes: 5 additions & 0 deletions src/go/plugin/go.d/modules/megacli/megacli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func TestMegaCli_Collect(t *testing.T) {
"adapter_0_health_state_optimal": 1,
"adapter_0_health_state_partially_degraded": 0,
"bbu_adapter_0_absolute_state_of_charge": 63,
"bbu_adapter_0_capacity_degradation_perc": 10,
"bbu_adapter_0_cycle_count": 4,
"bbu_adapter_0_relative_state_of_charge": 71,
"bbu_adapter_0_temperature": 33,
Expand Down Expand Up @@ -190,6 +191,7 @@ func TestMegaCli_Collect(t *testing.T) {
"adapter_0_health_state_optimal": 1,
"adapter_0_health_state_partially_degraded": 0,
"bbu_adapter_0_absolute_state_of_charge": 83,
"bbu_adapter_0_capacity_degradation_perc": 17,
"bbu_adapter_0_cycle_count": 61,
"bbu_adapter_0_relative_state_of_charge": 100,
"bbu_adapter_0_temperature": 31,
Expand Down Expand Up @@ -235,6 +237,9 @@ func TestMegaCli_Collect(t *testing.T) {

assert.Equal(t, test.wantMetrics, mx)
assert.Len(t, *mega.Charts(), test.wantCharts)
if len(test.wantMetrics) > 0 {
module.TestMetricsHasAllChartsDims(t, mega.Charts(), mx)
}
})
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/go/plugin/go.d/modules/megacli/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ modules:
- name: battery_type
description: Battery type (e.g. BBU)
metrics:
- name: megacli.bbu_relative_charge
- name: megacli.bbu_charge
description: BBU relative charge
unit: percentage
chart_type: area
Expand All @@ -169,6 +169,12 @@ modules:
chart_type: line
dimensions:
- name: recharge
- name: megacli.bbu_capacity_degradation
description: BBU capacity degradation
unit: percent
chart_type: area
dimensions:
- name: cap_degradation
- name: megacli.bbu_temperature
description: BBU bbu_temperature
unit: Celsius
Expand Down

0 comments on commit 64a1c51

Please sign in to comment.