| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package ethtool |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | |
| 8 | "github.com/netdata/netdata/go/plugins/plugin/framework/collectorapi" |
| 9 | ) |
| 10 | |
| 11 | const ( |
| 12 | prioModuleReceiverPowerDbm = collectorapi.Priority + iota |
| 13 | prioModuleLaserOutputPowerDbm |
| 14 | prioModuleLaserBiasCurrent |
| 15 | prioModuleTemperatureC |
| 16 | prioModuleVoltage |
| 17 | ) |
| 18 | |
| 19 | var ifaceModuleEepromCharts = collectorapi.Charts{ |
| 20 | ifaceModuleReceiverPowerDbmChartTmpl.Copy(), |
| 21 | ifaceModuleLaserPowerDbmChartTmpl.Copy(), |
| 22 | ifaceModuleLaserBiasCurrentChartTmpl.Copy(), |
| 23 | ifaceModuleTempCelsiusChartTmpl.Copy(), |
| 24 | ifaceModuleVoltageChartTmpl.Copy(), |
| 25 | } |
| 26 | |
| 27 | var ( |
| 28 | ifaceModuleReceiverPowerDbmChartTmpl = collectorapi.Chart{ |
| 29 | ID: "iface_%s_module_receiver_power_dbm", |
| 30 | Title: "CollectorV1 Receiver Signal Average Optical Power", |
| 31 | Units: "dBm", |
| 32 | Fam: "optical module", |
| 33 | Ctx: "ethtool.optical_module_receiver_signal_power", |
| 34 | Priority: prioModuleReceiverPowerDbm, |
| 35 | Dims: collectorapi.Dims{ |
| 36 | {ID: "iface_%s_receiver_signal_average_optical_power_dbm", Name: "rx_power", Div: precision}, |
| 37 | }, |
| 38 | } |
| 39 | ifaceModuleLaserPowerDbmChartTmpl = collectorapi.Chart{ |
| 40 | ID: "iface_%s_module_laser_output_power_dbm", |
| 41 | Title: "CollectorV1 Laser Output Power", |
| 42 | Units: "dBm", |
| 43 | Fam: "optical module", |
| 44 | Ctx: "ethtool.optical_module_laser_output_power", |
| 45 | Priority: prioModuleLaserOutputPowerDbm, |
| 46 | Dims: collectorapi.Dims{ |
| 47 | {ID: "iface_%s_laser_output_power_dbm", Name: "tx_power", Div: precision}, |
| 48 | }, |
| 49 | } |
| 50 | ifaceModuleLaserBiasCurrentChartTmpl = collectorapi.Chart{ |
| 51 | ID: "iface_%s_module_laser_bias_current", |
| 52 | Title: "CollectorV1 Laser Bias Current", |
| 53 | Units: "mA", |
| 54 | Fam: "optical module", |
| 55 | Ctx: "ethtool.optical_module_laser_bias_current", |
| 56 | Priority: prioModuleLaserBiasCurrent, |
| 57 | Dims: collectorapi.Dims{ |
| 58 | {ID: "iface_%s_laser_bias_current_ma", Name: "bias_current", Div: precision}, |
| 59 | }, |
| 60 | } |
| 61 | ifaceModuleTempCelsiusChartTmpl = collectorapi.Chart{ |
| 62 | ID: "iface_%s_module_temperature_c", |
| 63 | Title: "CollectorV1 Temperature", |
| 64 | Units: "Celsius", |
| 65 | Fam: "optical module", |
| 66 | Ctx: "ethtool.optical_module_temperature", |
| 67 | Priority: prioModuleTemperatureC, |
| 68 | Dims: collectorapi.Dims{ |
| 69 | {ID: "iface_%s_module_temperature_c", Name: "temperature", Div: precision}, |
| 70 | }, |
| 71 | } |
| 72 | ifaceModuleVoltageChartTmpl = collectorapi.Chart{ |
| 73 | ID: "iface_%s_module_voltage", |
| 74 | Title: "CollectorV1 Voltage", |
| 75 | Units: "Volts", |
| 76 | Fam: "optical module", |
| 77 | Ctx: "ethtool.optical_module_voltage", |
| 78 | Priority: prioModuleVoltage, |
| 79 | Dims: collectorapi.Dims{ |
| 80 | {ID: "iface_%s_module_voltage_v", Name: "voltage", Div: precision}, |
| 81 | }, |
| 82 | } |
| 83 | ) |
| 84 | |
| 85 | func (c *Collector) addModuleEepromCharts(iface string, eeprom *moduleEeprom) { |
| 86 | if eeprom == nil || eeprom.ddm == nil { |
| 87 | return |
| 88 | } |
| 89 | |
| 90 | charts := ifaceModuleEepromCharts.Copy() |
| 91 | |
| 92 | if eeprom.ddm.laserBiasMA == nil { |
| 93 | _ = charts.Remove(ifaceModuleLaserBiasCurrentChartTmpl.ID) |
| 94 | } |
| 95 | if eeprom.ddm.laserPowerDBM == nil { |
| 96 | _ = charts.Remove(ifaceModuleLaserPowerDbmChartTmpl.ID) |
| 97 | } |
| 98 | if eeprom.ddm.rxSignalPowerDBM == nil { |
| 99 | _ = charts.Remove(ifaceModuleLaserPowerDbmChartTmpl.ID) |
| 100 | } |
| 101 | if eeprom.ddm.tempC == nil { |
| 102 | _ = charts.Remove(ifaceModuleTempCelsiusChartTmpl.ID) |
| 103 | } |
| 104 | if eeprom.ddm.voltageV == nil { |
| 105 | _ = charts.Remove(ifaceModuleVoltageChartTmpl.ID) |
| 106 | } |
| 107 | |
| 108 | for _, chart := range *charts { |
| 109 | chart.ID = fmt.Sprintf(chart.ID, iface) |
| 110 | chart.Labels = []collectorapi.Label{ |
| 111 | {Key: "iface", Value: iface}, |
| 112 | } |
| 113 | for _, dim := range chart.Dims { |
| 114 | dim.ID = fmt.Sprintf(dim.ID, iface) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | if err := c.Charts().Add(*charts...); err != nil { |
| 119 | c.Warningf("failed to add chart for interfce '%s': %v", iface, err) |
| 120 | } |
| 121 | } |