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

Support for multi lane optics #43

Merged
merged 3 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions interfacediagnostics/interface_diagnostics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package interfacediagnostics

type InterfaceDiagnostics struct {
Index string
Name string
LaserBiasCurrent float64
LaserOutputPower float64
Expand All @@ -13,4 +14,6 @@ type InterfaceDiagnostics struct {
ModuleVoltage float64
RxSignalAvgOpticalPower float64
RxSignalAvgOpticalPowerDbm float64

Lanes []*InterfaceDiagnostics
}
78 changes: 54 additions & 24 deletions interfacediagnostics/interface_diagnostics_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
}
}

Expand All @@ -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),
Expand All @@ -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)
}
}

Expand Down
17 changes: 14 additions & 3 deletions interfacediagnostics/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
}