diff --git a/main.go b/main.go index 369332d..37cd74a 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ var ( collectInterfaceFeatures = flag.Bool("collector.interface-features.enable", true, "Collect interface features") excludeInterfaces = flag.String("exclude.interfaces", "", "Comma seperated list of interfaces to exclude") includeInterfaces = flag.String("include.interfaces", "", "Comma seperated list of interfaces to include") + excludeInterfacesDown = flag.Bool("exclude.interfaces-down", false, "Don't report on interfaces being management DOWN") powerUnitdBm = flag.Bool("collector.optical-power-in-dbm", false, "Report optical powers in dBm instead of mW (default false -> mW)") ) @@ -98,7 +99,7 @@ func handleMetricsRequest(w http.ResponseWriter, request *http.Request) { includedIfaceNames[index] = strings.Trim(includedIfaceName, " ") } } - transceiverCollector := transceivercollector.NewCollector(excludedIfaceNames, includedIfaceNames, *collectInterfaceFeatures, *powerUnitdBm) + transceiverCollector := transceivercollector.NewCollector(excludedIfaceNames, includedIfaceNames, *excludeInterfacesDown, *collectInterfaceFeatures, *powerUnitdBm) wrapper := &transceiverCollectorWrapper{ collector: transceiverCollector, } diff --git a/transceiver-collector/collector.go b/transceiver-collector/collector.go index 040c1f5..88f4c0b 100644 --- a/transceiver-collector/collector.go +++ b/transceiver-collector/collector.go @@ -92,6 +92,7 @@ var laserLabels = []string{"interface", "laser_index"} type TransceiverCollector struct { excludeInterfaces []string includeInterfaces []string + excludeInterfacesDown bool collectInterfaceFeatures bool powerUnitdBm bool } @@ -173,7 +174,7 @@ func init() { } // NewCollector initializes a new TransceiverCollector -func NewCollector(excludeInterfaces []string, includeInterfaces []string, collectInterfaceFeatures bool, powerUnitdBm bool) *TransceiverCollector { +func NewCollector(excludeInterfaces []string, includeInterfaces []string, excludeInterfacesDown bool, collectInterfaceFeatures bool, powerUnitdBm bool) *TransceiverCollector { laserTxPowerThresholdsSupportedDesc = prometheus.NewDesc(prefix+"laser_tx_power_supports_thresholds_bool", "1 if thresholds for the laser tx power are supported", laserLabels, nil) laserRxPowerThresholdsSupportedDesc = prometheus.NewDesc(prefix+"laser_rx_power_supports_thresholds_bool", "1 if thresholds for the laser rx power are supported", laserLabels, nil) if powerUnitdBm { @@ -205,6 +206,7 @@ func NewCollector(excludeInterfaces []string, includeInterfaces []string, collec return &TransceiverCollector{ excludeInterfaces: excludeInterfaces, includeInterfaces: includeInterfaces, + excludeInterfacesDown: excludeInterfacesDown, collectInterfaceFeatures: collectInterfaceFeatures, powerUnitdBm: powerUnitdBm, } @@ -306,6 +308,9 @@ func (t *TransceiverCollector) getMonitoredInterfaces() ([]string, error) { if iface.Flags&net.FlagLoopback > 0 { continue } + if iface.Flags&net.FlagUp == 0 && t.excludeInterfacesDown { + continue + } if InterfacesExcluded && contains(t.excludeInterfaces, iface.Name) { continue }