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

Added FEC mode to FEC feature #263

Merged
merged 12 commits into from
Nov 12, 2024
29 changes: 23 additions & 6 deletions pkg/features/interfaces/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type description struct {
receiveCodeViolationsDesc *prometheus.Desc
receiveTotalErrorsDesc *prometheus.Desc
transmitTotalErrorsDesc *prometheus.Desc
mtu *prometheus.Desc
mtuDesc *prometheus.Desc
fecModeDesc *prometheus.Desc
}

func newDescriptions(dynLabels dynamiclabels.Labels) *description {
Expand Down Expand Up @@ -97,8 +98,8 @@ func newDescriptions(dynLabels dynamiclabels.Labels) *description {
d.receiveCodeViolationsDesc = prometheus.NewDesc(prefix+"receive_code_violations", "Number of received Code Violations", l, nil)
d.receiveTotalErrorsDesc = prometheus.NewDesc(prefix+"receive_total_errors", "Number of received Total Errors", l, nil)
d.transmitTotalErrorsDesc = prometheus.NewDesc(prefix+"transmit_total_errors", "Number of transmitted Total Errors", l, nil)
d.mtu = prometheus.NewDesc(prefix+"mtu", "configured MTU", l, nil)

d.mtuDesc = prometheus.NewDesc(prefix+"mtu", "configured MTU", l, nil)
d.fecModeDesc = prometheus.NewDesc(prefix+"fec_mode", "Mode of FEC. 0 for none, 1 for default, 2 for fec74, 3 for fec91, 4 for fec108", l, nil)
return d
}

Expand Down Expand Up @@ -161,7 +162,8 @@ func (*interfaceCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- d.receiveCodeViolationsDesc
ch <- d.receiveTotalErrorsDesc
ch <- d.transmitTotalErrorsDesc
ch <- d.mtu
ch <- d.mtuDesc
ch <- d.fecModeDesc
}

// Collect collects metrics from JunOS
Expand Down Expand Up @@ -230,6 +232,7 @@ func (c *interfaceCollector) interfaceStats(client collector.Client) ([]*interfa
ReceiveTotalErrors: float64(phy.MACStatistics.InputTotalErrors),
TransmitTotalErrors: float64(phy.MACStatistics.OutputTotalErrors),
MTU: phy.MTU,
FECMode: convertFECModeToFloat64(strings.ToLower(phy.EthernetFecMode.EnabledFecMode)),
}

if phy.InterfaceFlapped.Value != "Never" {
Expand Down Expand Up @@ -332,7 +335,6 @@ func (c *interfaceCollector) collectForInterface(s *interfaceStats, ch chan<- pr
mtu = "65535"
}
mtu64, _ := strconv.ParseFloat(mtu, 64)

ch <- prometheus.MustNewConstMetric(d.adminStatusDesc, prometheus.GaugeValue, float64(adminUp), lv...)
ch <- prometheus.MustNewConstMetric(d.operStatusDesc, prometheus.GaugeValue, float64(operUp), lv...)
ch <- prometheus.MustNewConstMetric(d.errorStatusDesc, prometheus.GaugeValue, float64(err), lv...)
Expand All @@ -341,7 +343,7 @@ func (c *interfaceCollector) collectForInterface(s *interfaceStats, ch chan<- pr
ch <- prometheus.MustNewConstMetric(d.receiveErrorsDesc, prometheus.CounterValue, s.ReceiveErrors, lv...)
ch <- prometheus.MustNewConstMetric(d.receiveDropsDesc, prometheus.CounterValue, s.ReceiveDrops, lv...)
ch <- prometheus.MustNewConstMetric(d.interfaceSpeedDesc, prometheus.GaugeValue, float64(sp64), lv...)
ch <- prometheus.MustNewConstMetric(d.mtu, prometheus.GaugeValue, float64(mtu64), lv...)
ch <- prometheus.MustNewConstMetric(d.mtuDesc, prometheus.GaugeValue, float64(mtu64), lv...)

if s.LastFlapped != 0 {
ch <- prometheus.MustNewConstMetric(d.lastFlappedDesc, prometheus.GaugeValue, s.LastFlapped, lv...)
Expand All @@ -366,6 +368,21 @@ func (c *interfaceCollector) collectForInterface(s *interfaceStats, ch chan<- pr
ch <- prometheus.MustNewConstMetric(d.receiveCodeViolationsDesc, prometheus.CounterValue, s.ReceiveCodeViolations, lv...)
ch <- prometheus.MustNewConstMetric(d.receiveTotalErrorsDesc, prometheus.CounterValue, s.ReceiveTotalErrors, lv...)
ch <- prometheus.MustNewConstMetric(d.transmitTotalErrorsDesc, prometheus.CounterValue, s.TransmitTotalErrors, lv...)
ch <- prometheus.MustNewConstMetric(d.fecModeDesc, prometheus.CounterValue, s.FECMode, lv...)
}
}

func convertFECModeToFloat64(s string) float64 {
switch s {
case "none":
return 0
case "fec74":
return 2
case "fec91":
return 3
case "fec108":
return 4
default:
return 1
}
}
1 change: 1 addition & 0 deletions pkg/features/interfaces/interface_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ type interfaceStats struct {
ReceiveTotalErrors float64
TransmitTotalErrors float64
MTU string
FECMode float64
}
13 changes: 10 additions & 3 deletions pkg/features/interfaces/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ type phyInterface struct {
Seconds uint64 `xml:"seconds,attr"`
Value string `xml:",chardata"`
} `xml:"interface-flapped"`
MACStatistics ethernetMACStat `xml:"ethernet-mac-statistics"`
FECStatistics ethernetFECStat `xml:"ethernet-fec-statistics"`
MTU string `xml:"mtu"`
MACStatistics ethernetMACStat `xml:"ethernet-mac-statistics"`
EthernetFecMode ethernetFECMode `xml:"ethernet-fec-mode"`
FECStatistics ethernetFECStat `xml:"ethernet-fec-statistics"`
MTU string `xml:"mtu"`
}

type logInterface struct {
Expand Down Expand Up @@ -88,3 +89,9 @@ type ethernetFECStat struct {
NumberfecCcwErrorRate uint64 `xml:"fec_ccw_error_rate"`
NumberfecNccwErrorRate uint64 `xml:"fec_nccw_error_rate"`
}

type ethernetFECMode struct {
Text string `xml:",chardata"`
Style string `xml:"style,attr"`
EnabledFecMode string `xml:"enabled_fec_mode"`
}
Loading