Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from netdata:master #134

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ require (
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20220504211119-3d4a969bb56b
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.30.2
k8s.io/apimachinery v0.30.2
k8s.io/client-go v0.30.2
k8s.io/api v0.30.3
k8s.io/apimachinery v0.30.3
k8s.io/client-go v0.30.3
layeh.com/radius v0.0.0-20190322222518-890bc1058917
)

Expand Down
12 changes: 6 additions & 6 deletions src/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,12 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
k8s.io/api v0.30.2 h1:+ZhRj+28QT4UOH+BKznu4CBgPWgkXO7XAvMcMl0qKvI=
k8s.io/api v0.30.2/go.mod h1:ULg5g9JvOev2dG0u2hig4Z7tQ2hHIuS+m8MNZ+X6EmI=
k8s.io/apimachinery v0.30.2 h1:fEMcnBj6qkzzPGSVsAZtQThU62SmQ4ZymlXRC5yFSCg=
k8s.io/apimachinery v0.30.2/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
k8s.io/client-go v0.30.2 h1:sBIVJdojUNPDU/jObC+18tXWcTJVcwyqS9diGdWHk50=
k8s.io/client-go v0.30.2/go.mod h1:JglKSWULm9xlJLx4KCkfLLQ7XwtlbflV6uFFSHTMgVs=
k8s.io/api v0.30.3 h1:ImHwK9DCsPA9uoU3rVh4QHAHHK5dTSv1nxJUapx8hoQ=
k8s.io/api v0.30.3/go.mod h1:GPc8jlzoe5JG3pb0KJCSLX5oAFIW3/qNJITlDj8BH04=
k8s.io/apimachinery v0.30.3 h1:q1laaWCmrszyQuSQCfNB8cFgCuDAoPszKY4ucAjDwHc=
k8s.io/apimachinery v0.30.3/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
k8s.io/client-go v0.30.3 h1:bHrJu3xQZNXIi8/MoxYtZBBWQQXwy16zqJwloXXfD3k=
k8s.io/client-go v0.30.3/go.mod h1:8d4pf8vYu665/kUbsxWAQ/JDBNWqfFeZnvFiVdmx89U=
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
Expand Down
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
Loading