| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package megacli |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | |
| 8 | "github.com/netdata/netdata/go/plugins/plugin/framework/collectorapi" |
| 9 | ) |
| 10 | |
| 11 | const ( |
| 12 | prioAdapterHealthState = collectorapi.Priority + iota |
| 13 | |
| 14 | prioPhysDriveMediaErrorsRate |
| 15 | prioPhysDrivePredictiveFailuresRate |
| 16 | |
| 17 | prioBBURelativeCharge |
| 18 | prioBBURechargeCycles |
| 19 | prioBBUCapDegradationPerc |
| 20 | prioBBUTemperature |
| 21 | ) |
| 22 | |
| 23 | var adapterChartsTmpl = collectorapi.Charts{ |
| 24 | adapterHealthStateChartTmpl.Copy(), |
| 25 | } |
| 26 | |
| 27 | var ( |
| 28 | adapterHealthStateChartTmpl = collectorapi.Chart{ |
| 29 | ID: "adapter_%s_health_state", |
| 30 | Title: "Adapter health state", |
| 31 | Units: "state", |
| 32 | Fam: "adapter health", |
| 33 | Ctx: "megacli.adapter_health_state", |
| 34 | Type: collectorapi.Line, |
| 35 | Priority: prioAdapterHealthState, |
| 36 | Dims: collectorapi.Dims{ |
| 37 | {ID: "adapter_%s_health_state_optimal", Name: "optimal"}, |
| 38 | {ID: "adapter_%s_health_state_degraded", Name: "degraded"}, |
| 39 | {ID: "adapter_%s_health_state_partially_degraded", Name: "partially_degraded"}, |
| 40 | {ID: "adapter_%s_health_state_failed", Name: "failed"}, |
| 41 | }, |
| 42 | } |
| 43 | ) |
| 44 | |
| 45 | var physDriveChartsTmpl = collectorapi.Charts{ |
| 46 | physDriveMediaErrorsRateChartTmpl.Copy(), |
| 47 | physDrivePredictiveFailuresRateChartTmpl.Copy(), |
| 48 | } |
| 49 | |
| 50 | var ( |
| 51 | physDriveMediaErrorsRateChartTmpl = collectorapi.Chart{ |
| 52 | ID: "phys_drive_%s_media_errors_rate", |
| 53 | Title: "Physical Drive media errors rate", |
| 54 | Units: "errors/s", |
| 55 | Fam: "phys drive errors", |
| 56 | Ctx: "megacli.phys_drive_media_errors", |
| 57 | Type: collectorapi.Line, |
| 58 | Priority: prioPhysDriveMediaErrorsRate, |
| 59 | Dims: collectorapi.Dims{ |
| 60 | {ID: "phys_drive_%s_media_error_count", Name: "media_errors"}, |
| 61 | }, |
| 62 | } |
| 63 | physDrivePredictiveFailuresRateChartTmpl = collectorapi.Chart{ |
| 64 | ID: "phys_drive_%s_predictive_failures_rate", |
| 65 | Title: "Physical Drive predictive failures rate", |
| 66 | Units: "failures/s", |
| 67 | Fam: "phys drive errors", |
| 68 | Ctx: "megacli.phys_drive_predictive_failures", |
| 69 | Type: collectorapi.Line, |
| 70 | Priority: prioPhysDrivePredictiveFailuresRate, |
| 71 | Dims: collectorapi.Dims{ |
| 72 | {ID: "phys_drive_%s_predictive_failure_count", Name: "predictive_failures"}, |
| 73 | }, |
| 74 | } |
| 75 | ) |
| 76 | |
| 77 | var bbuChartsTmpl = collectorapi.Charts{ |
| 78 | bbuRelativeChargeChartsTmpl.Copy(), |
| 79 | bbuRechargeCyclesChartsTmpl.Copy(), |
| 80 | bbuCapacityDegradationChartsTmpl.Copy(), |
| 81 | bbuTemperatureChartsTmpl.Copy(), |
| 82 | } |
| 83 | |
| 84 | var ( |
| 85 | bbuRelativeChargeChartsTmpl = collectorapi.Chart{ |
| 86 | ID: "bbu_adapter_%s_relative_charge", |
| 87 | Title: "BBU relative charge", |
| 88 | Units: "percentage", |
| 89 | Fam: "bbu charge", |
| 90 | Ctx: "megacli.bbu_charge", |
| 91 | Type: collectorapi.Area, |
| 92 | Priority: prioBBURelativeCharge, |
| 93 | Dims: collectorapi.Dims{ |
| 94 | {ID: "bbu_adapter_%s_relative_state_of_charge", Name: "charge"}, |
| 95 | }, |
| 96 | } |
| 97 | bbuRechargeCyclesChartsTmpl = collectorapi.Chart{ |
| 98 | ID: "bbu_adapter_%s_recharge_cycles", |
| 99 | Title: "BBU recharge cycles", |
| 100 | Units: "cycles", |
| 101 | Fam: "bbu charge", |
| 102 | Ctx: "megacli.bbu_recharge_cycles", |
| 103 | Type: collectorapi.Line, |
| 104 | Priority: prioBBURechargeCycles, |
| 105 | Dims: collectorapi.Dims{ |
| 106 | {ID: "bbu_adapter_%s_cycle_count", Name: "recharge"}, |
| 107 | }, |
| 108 | } |
| 109 | bbuCapacityDegradationChartsTmpl = collectorapi.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: collectorapi.Line, |
| 116 | Priority: prioBBUCapDegradationPerc, |
| 117 | Dims: collectorapi.Dims{ |
| 118 | {ID: "bbu_adapter_%s_capacity_degradation_perc", Name: "cap_degradation"}, |
| 119 | }, |
| 120 | } |
| 121 | bbuTemperatureChartsTmpl = collectorapi.Chart{ |
| 122 | ID: "bbu_adapter_%s_temperature", |
| 123 | Title: "BBU temperature", |
| 124 | Units: "Celsius", |
| 125 | Fam: "bbu temperature", |
| 126 | Ctx: "megacli.bbu_temperature", |
| 127 | Type: collectorapi.Line, |
| 128 | Priority: prioBBUTemperature, |
| 129 | Dims: collectorapi.Dims{ |
| 130 | {ID: "bbu_adapter_%s_temperature", Name: "temperature"}, |
| 131 | }, |
| 132 | } |
| 133 | ) |
| 134 | |
| 135 | func (c *Collector) addAdapterCharts(ad *megaAdapter) { |
| 136 | charts := adapterChartsTmpl.Copy() |
| 137 | |
| 138 | for _, chart := range *charts { |
| 139 | chart.ID = fmt.Sprintf(chart.ID, ad.number) |
| 140 | chart.Labels = []collectorapi.Label{ |
| 141 | {Key: "adapter_number", Value: ad.number}, |
| 142 | } |
| 143 | for _, dim := range chart.Dims { |
| 144 | dim.ID = fmt.Sprintf(dim.ID, ad.number) |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | if err := c.Charts().Add(*charts...); err != nil { |
| 149 | c.Warning(err) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | func (c *Collector) addPhysDriveCharts(pd *megaPhysDrive) { |
| 154 | charts := physDriveChartsTmpl.Copy() |
| 155 | |
| 156 | for _, chart := range *charts { |
| 157 | chart.ID = fmt.Sprintf(chart.ID, pd.wwn) |
| 158 | chart.Labels = []collectorapi.Label{ |
| 159 | {Key: "adapter_number", Value: pd.adapterNumber}, |
| 160 | {Key: "wwn", Value: pd.wwn}, |
| 161 | {Key: "slot_number", Value: pd.slotNumber}, |
| 162 | {Key: "drive_position", Value: pd.drivePosition}, |
| 163 | {Key: "drive_type", Value: pd.pdType}, |
| 164 | } |
| 165 | for _, dim := range chart.Dims { |
| 166 | dim.ID = fmt.Sprintf(dim.ID, pd.wwn) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | if err := c.Charts().Add(*charts...); err != nil { |
| 171 | c.Warning(err) |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | func (c *Collector) 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 = []collectorapi.Label{ |
| 185 | {Key: "adapter_number", Value: bbu.adapterNumber}, |
| 186 | {Key: "battery_type", Value: bbu.batteryType}, |
| 187 | } |
| 188 | for _, dim := range chart.Dims { |
| 189 | dim.ID = fmt.Sprintf(dim.ID, bbu.adapterNumber) |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | if err := c.Charts().Add(*charts...); err != nil { |
| 194 | c.Warning(err) |
| 195 | } |
| 196 | } |