diff --git a/pkg/features/interfaces/collector.go b/pkg/features/interfaces/collector.go index 31579a26..e22d259e 100644 --- a/pkg/features/interfaces/collector.go +++ b/pkg/features/interfaces/collector.go @@ -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 { @@ -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 } @@ -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 @@ -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" { @@ -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...) @@ -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...) @@ -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 } } diff --git a/pkg/features/interfaces/interface_stats.go b/pkg/features/interfaces/interface_stats.go index 69d4acfd..e4754a30 100644 --- a/pkg/features/interfaces/interface_stats.go +++ b/pkg/features/interfaces/interface_stats.go @@ -45,4 +45,5 @@ type interfaceStats struct { ReceiveTotalErrors float64 TransmitTotalErrors float64 MTU string + FECMode float64 } diff --git a/pkg/features/interfaces/rpc.go b/pkg/features/interfaces/rpc.go index 98693320..b2df197f 100644 --- a/pkg/features/interfaces/rpc.go +++ b/pkg/features/interfaces/rpc.go @@ -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 { @@ -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"` +}