diff --git a/interfacediagnostics/interface_diagnostics.go b/interfacediagnostics/interface_diagnostics.go index dd3e192e..9ea377a2 100644 --- a/interfacediagnostics/interface_diagnostics.go +++ b/interfacediagnostics/interface_diagnostics.go @@ -1,6 +1,7 @@ package interfacediagnostics type InterfaceDiagnostics struct { + Index string Name string LaserBiasCurrent float64 LaserOutputPower float64 @@ -13,4 +14,6 @@ type InterfaceDiagnostics struct { ModuleVoltage float64 RxSignalAvgOpticalPower float64 RxSignalAvgOpticalPowerDbm float64 + + Lanes []*InterfaceDiagnostics } diff --git a/interfacediagnostics/interface_diagnostics_collector.go b/interfacediagnostics/interface_diagnostics_collector.go index 5cc072bd..90162420 100644 --- a/interfacediagnostics/interface_diagnostics_collector.go +++ b/interfacediagnostics/interface_diagnostics_collector.go @@ -27,17 +27,17 @@ var ( func init() { l := []string{"target", "name"} + moduleVoltageDesc = prometheus.NewDesc(prefix+"module_voltage", "Module voltage", l, nil) + moduleTemperatureDesc = prometheus.NewDesc(prefix+"temp", "Module temperature in degrees Celsius", l, nil) + rxSignalAvgOpticalPowerDesc = prometheus.NewDesc(prefix+"rx_signal_avg", "Receiver signal average optical power in mW", l, nil) + rxSignalAvgOpticalPowerDbmDesc = prometheus.NewDesc(prefix+"rx_signal_avg_dbm", "Receiver signal average optical power in mW", l, nil) + + l = append(l, "lane") laserBiasCurrentDesc = prometheus.NewDesc(prefix+"laser_bias", "Laser bias current in mA", l, nil) laserOutputPowerDesc = prometheus.NewDesc(prefix+"laser_output", "Laser output power in mW", l, nil) laserOutputPowerDbmDesc = prometheus.NewDesc(prefix+"laser_output_dbm", "Laser output power in dBm", l, nil) - moduleTemperatureDesc = prometheus.NewDesc(prefix+"temp", "Module temperature in degrees Celsius", l, nil) - laserRxOpticalPowerDesc = prometheus.NewDesc(prefix+"laser_rx", "Laser rx power in mW", l, nil) laserRxOpticalPowerDbmDesc = prometheus.NewDesc(prefix+"laser_rx_dbm", "Laser rx power in dBm", l, nil) - - moduleVoltageDesc = prometheus.NewDesc(prefix+"module_voltage", "Module voltage", l, nil) - rxSignalAvgOpticalPowerDesc = prometheus.NewDesc(prefix+"rx_signal_avg", "Receiver signal average optical power in mW", l, nil) - rxSignalAvgOpticalPowerDbmDesc = prometheus.NewDesc(prefix+"rx_signal_avg_dbm", "Receiver signal average optical power in mW", l, nil) } type interfaceDiagnosticsCollector struct { @@ -72,18 +72,29 @@ func (c *interfaceDiagnosticsCollector) Collect(client *rpc.Client, ch chan<- pr for _, d := range diagnostics { l := append(labelValues, d.Name) - ch <- prometheus.MustNewConstMetric(laserBiasCurrentDesc, prometheus.GaugeValue, d.LaserBiasCurrent, l...) - ch <- prometheus.MustNewConstMetric(laserOutputPowerDesc, prometheus.GaugeValue, d.LaserOutputPower, l...) - ch <- prometheus.MustNewConstMetric(laserOutputPowerDbmDesc, prometheus.GaugeValue, d.LaserOutputPowerDbm, l...) ch <- prometheus.MustNewConstMetric(moduleTemperatureDesc, prometheus.GaugeValue, d.ModuleTemperature, l...) - if d.ModuleVoltage > 0 { ch <- prometheus.MustNewConstMetric(moduleVoltageDesc, prometheus.GaugeValue, d.ModuleVoltage, l...) + } + if d.RxSignalAvgOpticalPower > 0 { ch <- prometheus.MustNewConstMetric(rxSignalAvgOpticalPowerDesc, prometheus.GaugeValue, d.RxSignalAvgOpticalPower, l...) ch <- prometheus.MustNewConstMetric(rxSignalAvgOpticalPowerDbmDesc, prometheus.GaugeValue, d.RxSignalAvgOpticalPowerDbm, l...) + } + + var data []*InterfaceDiagnostics + if len(d.Lanes) > 0 { + data = d.Lanes } else { - ch <- prometheus.MustNewConstMetric(laserRxOpticalPowerDesc, prometheus.GaugeValue, d.LaserRxOpticalPower, l...) - ch <- prometheus.MustNewConstMetric(laserRxOpticalPowerDbmDesc, prometheus.GaugeValue, d.LaserRxOpticalPowerDbm, l...) + data = []*InterfaceDiagnostics{d} + } + + for _, e := range data { + l2 := append(l, e.Index) + ch <- prometheus.MustNewConstMetric(laserBiasCurrentDesc, prometheus.GaugeValue, e.LaserBiasCurrent, l2...) + ch <- prometheus.MustNewConstMetric(laserOutputPowerDesc, prometheus.GaugeValue, e.LaserOutputPower, l2...) + ch <- prometheus.MustNewConstMetric(laserOutputPowerDbmDesc, prometheus.GaugeValue, e.LaserOutputPowerDbm, l2...) + ch <- prometheus.MustNewConstMetric(laserRxOpticalPowerDesc, prometheus.GaugeValue, e.LaserRxOpticalPower, l2...) + ch <- prometheus.MustNewConstMetric(laserRxOpticalPowerDbmDesc, prometheus.GaugeValue, e.LaserRxOpticalPowerDbm, l2...) } } @@ -103,6 +114,7 @@ func (c *interfaceDiagnosticsCollector) interfaceDiagnostics(client *rpc.Client) continue } d := &InterfaceDiagnostics{ + Index: "", Name: diag.Name, LaserBiasCurrent: float64(diag.Diagnostics.LaserBiasCurrent), LaserOutputPower: float64(diag.Diagnostics.LaserOutputPower), @@ -113,18 +125,36 @@ func (c *interfaceDiagnosticsCollector) interfaceDiagnostics(client *rpc.Client) d.LaserOutputPowerDbm = f } - if diag.Diagnostics.ModuleVoltage > 0 { - d.ModuleVoltage = float64(diag.Diagnostics.ModuleVoltage) - d.RxSignalAvgOpticalPower = float64(diag.Diagnostics.RxSignalAvgOpticalPower) - f, err = strconv.ParseFloat(diag.Diagnostics.RxSignalAvgOpticalPowerDbm, 64) - if err == nil { - d.RxSignalAvgOpticalPowerDbm = f - } - } else { - d.LaserRxOpticalPower = float64(diag.Diagnostics.LaserRxOpticalPower) - f, err = strconv.ParseFloat(diag.Diagnostics.LaserRxOpticalPowerDbm, 64) - if err == nil { - d.LaserRxOpticalPowerDbm = f + d.ModuleVoltage = float64(diag.Diagnostics.ModuleVoltage) + d.RxSignalAvgOpticalPower = float64(diag.Diagnostics.RxSignalAvgOpticalPower) + f, err = strconv.ParseFloat(diag.Diagnostics.RxSignalAvgOpticalPowerDbm, 64) + if err == nil { + d.RxSignalAvgOpticalPowerDbm = f + } + d.LaserRxOpticalPower = float64(diag.Diagnostics.LaserRxOpticalPower) + f, err = strconv.ParseFloat(diag.Diagnostics.LaserRxOpticalPowerDbm, 64) + if err == nil { + d.LaserRxOpticalPowerDbm = f + } + + if len(diag.Diagnostics.OpticsDiagnosticsLaneValues) > 0 { + for _, lane := range diag.Diagnostics.OpticsDiagnosticsLaneValues { + l := &InterfaceDiagnostics{ + Index: lane.LaneIndex, + Name: diag.Name, + LaserBiasCurrent: float64(lane.LaserBiasCurrent), + LaserOutputPower: float64(lane.LaserOutputPower), + } + f, err := strconv.ParseFloat(lane.LaserOutputPowerDbm, 64) + if err == nil { + l.LaserOutputPowerDbm = f + } + l.LaserRxOpticalPower = float64(lane.LaserRxOpticalPower) + f, err = strconv.ParseFloat(lane.LaserRxOpticalPowerDbm, 64) + if err == nil { + l.LaserRxOpticalPowerDbm = f + } + d.Lanes = append(d.Lanes, l) } } diff --git a/interfacediagnostics/rpc.go b/interfacediagnostics/rpc.go index 9a7440a9..fb12e689 100644 --- a/interfacediagnostics/rpc.go +++ b/interfacediagnostics/rpc.go @@ -9,9 +9,9 @@ type InterfaceDiagnosticsRpc struct { type PhyDiagInterface struct { Name string `xml:"name"` Diagnostics struct { - LaserBiasCurrent float64 `xml:"laser-bias-current"` - LaserOutputPower float64 `xml:"laser-output-power"` - LaserOutputPowerDbm string `xml:"laser-output-power-dbm"` + LaserBiasCurrent float64 `xml:"laser-bias-current,omitempty"` + LaserOutputPower float64 `xml:"laser-output-power,omitempty"` + LaserOutputPowerDbm string `xml:"laser-output-power-dbm,omitempty"` ModuleTemperature struct { Value float64 `xml:"celsius,attr"` } `xml:"module-temperature"` @@ -24,5 +24,16 @@ type PhyDiagInterface struct { LaserRxOpticalPowerDbm string `xml:"laser-rx-optical-power-dbm,omitempty"` NA string `xml:"optic-diagnostics-not-available"` + + OpticsDiagnosticsLaneValues []LaneValue `xml:"optics-diagnostics-lane-values,omitempty"` } `xml:"optics-diagnostics,omitempty"` } + +type LaneValue struct { + LaneIndex string `xml:"lane-index"` + LaserBiasCurrent float64 `xml:"laser-bias-current,omitempty"` + LaserOutputPower float64 `xml:"laser-output-power,omitempty"` + LaserOutputPowerDbm string `xml:"laser-output-power-dbm,omitempty"` + LaserRxOpticalPower float64 `xml:"laser-rx-optical-power,omitempty"` + LaserRxOpticalPowerDbm string `xml:"laser-rx-optical-power-dbm,omitempty"` +}