From 143c40959e2944d8a6b7a3cfd437389dcb1e5f98 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Jul 2024 10:35:58 +0300 Subject: [PATCH 1/2] Bump k8s.io/client-go from 0.30.2 to 0.30.3 in /src/go (#18208) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- src/go/go.mod | 6 +++--- src/go/go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/go/go.mod b/src/go/go.mod index b79dc8d6dfa2d2..0017f4d36cafc6 100644 --- a/src/go/go.mod +++ b/src/go/go.mod @@ -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 ) diff --git a/src/go/go.sum b/src/go/go.sum index 5c3ef54239ddbe..4380c17906213e 100644 --- a/src/go/go.sum +++ b/src/go/go.sum @@ -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= From 64a1c51d880a7ea058337548b9f080f71b14aecd Mon Sep 17 00:00:00 2001 From: Ilya Mashchenko Date: Mon, 22 Jul 2024 13:56:22 +0300 Subject: [PATCH 2/2] go.d megacli: add bbu capacity degradation % (#18211) --- src/go/plugin/go.d/modules/megacli/charts.go | 18 +++++++ .../go.d/modules/megacli/collect_bbu.go | 51 +++++++++++++++---- .../go.d/modules/megacli/megacli_test.go | 5 ++ .../plugin/go.d/modules/megacli/metadata.yaml | 8 ++- 4 files changed, 70 insertions(+), 12 deletions(-) diff --git a/src/go/plugin/go.d/modules/megacli/charts.go b/src/go/plugin/go.d/modules/megacli/charts.go index de0971bb083d64..c479d567770f48 100644 --- a/src/go/plugin/go.d/modules/megacli/charts.go +++ b/src/go/plugin/go.d/modules/megacli/charts.go @@ -16,6 +16,7 @@ const ( prioBBURelativeCharge prioBBURechargeCycles + prioBBUCapDegradationPerc prioBBUTemperature ) @@ -76,6 +77,7 @@ var ( var bbuChartsTmpl = module.Charts{ bbuRelativeChargeChartsTmpl.Copy(), bbuRechargeCyclesChartsTmpl.Copy(), + bbuCapacityDegradationChartsTmpl.Copy(), bbuTemperatureChartsTmpl.Copy(), } @@ -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", @@ -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{ diff --git a/src/go/plugin/go.d/modules/megacli/collect_bbu.go b/src/go/plugin/go.d/modules/megacli/collect_bbu.go index 900d93c7563e2f..33b048e64ced2d 100644 --- a/src/go/plugin/go.d/modules/megacli/collect_bbu.go +++ b/src/go/plugin/go.d/modules/megacli/collect_bbu.go @@ -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 { @@ -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)) @@ -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 @@ -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 +} diff --git a/src/go/plugin/go.d/modules/megacli/megacli_test.go b/src/go/plugin/go.d/modules/megacli/megacli_test.go index 8ab7ec4d56cc01..4991a28ce56069 100644 --- a/src/go/plugin/go.d/modules/megacli/megacli_test.go +++ b/src/go/plugin/go.d/modules/megacli/megacli_test.go @@ -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, @@ -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, @@ -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) + } }) } } diff --git a/src/go/plugin/go.d/modules/megacli/metadata.yaml b/src/go/plugin/go.d/modules/megacli/metadata.yaml index 5ede8f7e7010e3..da5f4fefa43a73 100644 --- a/src/go/plugin/go.d/modules/megacli/metadata.yaml +++ b/src/go/plugin/go.d/modules/megacli/metadata.yaml @@ -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 @@ -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