go.d megacli: add bbu capacity degradation % (#18211)
Ilya Mashchenko committed
Jul 22, 2024 at 13:56 UTC
64a1c51d880a7ea058337548b9f080f71b14aecd
4 files changed
+70
-12
src/go/plugin/go.d/modules/megacli/charts.go
+18
@@ -16,6 +16,7 @@ const (
16
17
prioBBURelativeCharge
18
prioBBURechargeCycles
19
+ prioBBUCapDegradationPerc
20
prioBBUTemperature
21
)
22
@@ -76,6 +77,7 @@ var (
77
var bbuChartsTmpl = module.Charts{
78
bbuRelativeChargeChartsTmpl.Copy(),
79
bbuRechargeCyclesChartsTmpl.Copy(),
80
+ bbuCapacityDegradationChartsTmpl.Copy(),
81
bbuTemperatureChartsTmpl.Copy(),
82
}
83
@@ -104,6 +106,18 @@ var (
106
{ID: "bbu_adapter_%s_cycle_count", Name: "recharge"},
107
},
108
}
109
+ bbuCapacityDegradationChartsTmpl = module.Chart{
110
+ ID: "bbu_adapter_%s_capacity_degradation",
111
+ Title: "BBU capacity degradation",
112
+ Units: "percent",
113
+ Fam: "bbu charge",
114
+ Ctx: "megacli.bbu_capacity_degradation",
115
+ Type: module.Line,
116
+ Priority: prioBBUCapDegradationPerc,
117
+ Dims: module.Dims{
118
+ {ID: "bbu_adapter_%s_capacity_degradation_perc", Name: "cap_degradation"},
119
+ },
120
+ }
121
bbuTemperatureChartsTmpl = module.Chart{
122
ID: "bbu_adapter_%s_temperature",
123
Title: "BBU temperature",
@@ -161,6 +175,10 @@ func (m *MegaCli) addPhysDriveCharts(pd *megaPhysDrive) {
175
func (m *MegaCli) addBBUCharts(bbu *megaBBU) {
176
charts := bbuChartsTmpl.Copy()
177
178
+ if _, ok := calcCapDegradationPerc(bbu); !ok {
179
+ _ = charts.Remove(bbuCapacityDegradationChartsTmpl.ID)
180
+ }
181
+
182
for _, chart := range *charts {
183
chart.ID = fmt.Sprintf(chart.ID, bbu.adapterNumber)
184
chart.Labels = []module.Label{
src/go/plugin/go.d/modules/megacli/collect_bbu.go
+40
-11
@@ -6,16 +6,19 @@ import (
6
"bufio"
7
"bytes"
8
"fmt"
9
+ "strconv"
10
"strings"
11
)
12
13
type megaBBU struct {
13
- adapterNumber string
14
- batteryType string
15
- temperature string
16
- relativeStateOfCharge string
17
- absoluteStateOfCharge string // apparently can be 0 while relative > 0 (e.g. relative 91%, absolute 0%)
18
- cycleCount string
14
+ adapterNumber string
15
+ batteryType string
16
+ temperature string
17
+ rsoc string
18
+ asoc string // apparently can be 0 while relative > 0 (e.g. relative 91%, absolute 0%)
19
+ cycleCount string
20
+ fullChargeCap string
21
+ designCap string
22
}
23
24
func (m *MegaCli) collectBBU(mx map[string]int64) error {
@@ -43,9 +46,12 @@ func (m *MegaCli) collectBBU(mx map[string]int64) error {
46
px := fmt.Sprintf("bbu_adapter_%s_", bbu.adapterNumber)
47
48
writeInt(mx, px+"temperature", bbu.temperature)
46
- writeInt(mx, px+"relative_state_of_charge", bbu.relativeStateOfCharge)
47
- writeInt(mx, px+"absolute_state_of_charge", bbu.absoluteStateOfCharge)
49
+ writeInt(mx, px+"relative_state_of_charge", bbu.rsoc)
50
+ writeInt(mx, px+"absolute_state_of_charge", bbu.asoc)
51
writeInt(mx, px+"cycle_count", bbu.cycleCount)
52
+ if v, ok := calcCapDegradationPerc(bbu); ok {
53
+ mx[px+"capacity_degradation_perc"] = v
54
+ }
55
}
56
57
m.Debugf("found %d BBUs", len(m.bbu))
@@ -76,9 +82,11 @@ func parseBBUInfo(bs []byte) (map[string]*megaBBU, error) {
82
case strings.HasPrefix(line, "BBU Capacity Info for Adapter"):
83
section = "capacity"
84
continue
85
+ case strings.HasPrefix(line, "BBU Design Info for Adapter"):
86
+ section = "design"
87
+ continue
88
case strings.HasPrefix(line, "BBU Firmware Status"),
89
strings.HasPrefix(line, "BBU GasGauge Status"),
81
- strings.HasPrefix(line, "BBU Design Info for Adapter"),
90
strings.HasPrefix(line, "BBU Properties for Adapter"):
91
section = ""
92
continue
@@ -99,14 +107,35 @@ func parseBBUInfo(bs []byte) (map[string]*megaBBU, error) {
107
case "capacity":
108
switch {
109
case strings.HasPrefix(line, "Relative State of Charge:"):
102
- bbu.relativeStateOfCharge = getColonSepNumValue(line)
110
+ bbu.rsoc = getColonSepNumValue(line)
111
case strings.HasPrefix(line, "Absolute State of charge:"):
104
- bbu.absoluteStateOfCharge = getColonSepNumValue(line)
112
+ bbu.asoc = getColonSepNumValue(line)
113
+ case strings.HasPrefix(line, "Full Charge Capacity:"):
114
+ bbu.fullChargeCap = getColonSepNumValue(line)
115
case strings.HasPrefix(line, "Cycle Count:"):
116
bbu.cycleCount = getColonSepNumValue(line)
117
}
118
+ case "design":
119
+ if strings.HasPrefix(line, "Design Capacity:") {
120
+ bbu.designCap = getColonSepNumValue(line)
121
+ }
122
}
123
}
124
125
return bbus, nil
126
}
127
+
128
+func calcCapDegradationPerc(bbu *megaBBU) (int64, bool) {
129
+ full, err := strconv.ParseInt(bbu.fullChargeCap, 10, 64)
130
+ if err != nil || full == 0 {
131
+ return 0, false
132
+ }
133
+ design, err := strconv.ParseInt(bbu.designCap, 10, 64)
134
+ if err != nil || design == 0 {
135
+ return 0, false
136
+ }
137
+
138
+ v := 100 - float64(full)/float64(design)*100
139
+
140
+ return int64(v), true
141
+}
src/go/plugin/go.d/modules/megacli/megacli_test.go
+5
@@ -160,6 +160,7 @@ func TestMegaCli_Collect(t *testing.T) {
160
"adapter_0_health_state_optimal": 1,
161
"adapter_0_health_state_partially_degraded": 0,
162
"bbu_adapter_0_absolute_state_of_charge": 63,
163
+ "bbu_adapter_0_capacity_degradation_perc": 10,
164
"bbu_adapter_0_cycle_count": 4,
165
"bbu_adapter_0_relative_state_of_charge": 71,
166
"bbu_adapter_0_temperature": 33,
@@ -190,6 +191,7 @@ func TestMegaCli_Collect(t *testing.T) {
191
"adapter_0_health_state_optimal": 1,
192
"adapter_0_health_state_partially_degraded": 0,
193
"bbu_adapter_0_absolute_state_of_charge": 83,
194
+ "bbu_adapter_0_capacity_degradation_perc": 17,
195
"bbu_adapter_0_cycle_count": 61,
196
"bbu_adapter_0_relative_state_of_charge": 100,
197
"bbu_adapter_0_temperature": 31,
@@ -235,6 +237,9 @@ func TestMegaCli_Collect(t *testing.T) {
237
238
assert.Equal(t, test.wantMetrics, mx)
239
assert.Len(t, *mega.Charts(), test.wantCharts)
240
+ if len(test.wantMetrics) > 0 {
241
+ module.TestMetricsHasAllChartsDims(t, mega.Charts(), mx)
242
+ }
243
})
244
}
245
}
src/go/plugin/go.d/modules/megacli/metadata.yaml
+7
-1
@@ -157,7 +157,7 @@ modules:
157
- name: battery_type
158
description: Battery type (e.g. BBU)
159
metrics:
160
- - name: megacli.bbu_relative_charge
160
+ - name: megacli.bbu_charge
161
description: BBU relative charge
162
unit: percentage
163
chart_type: area
@@ -169,6 +169,12 @@ modules:
169
chart_type: line
170
dimensions:
171
- name: recharge
172
+ - name: megacli.bbu_capacity_degradation
173
+ description: BBU capacity degradation
174
+ unit: percent
175
+ chart_type: area
176
+ dimensions:
177
+ - name: cap_degradation
178
- name: megacli.bbu_temperature
179
description: BBU bbu_temperature
180
unit: Celsius