Skip to content

Commit

Permalink
Merge pull request #7 from 4xoc/exclude-admin-down
Browse files Browse the repository at this point in the history
add flag to disable reporting on admin down interfaces
  • Loading branch information
johannwagner committed Jul 10, 2023
2 parents 48abcd0 + e4e2848 commit 91bca34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
)

Expand Down Expand Up @@ -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,
}
Expand Down
7 changes: 6 additions & 1 deletion transceiver-collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ var laserLabels = []string{"interface", "laser_index"}
type TransceiverCollector struct {
excludeInterfaces []string
includeInterfaces []string
excludeInterfacesDown bool
collectInterfaceFeatures bool
powerUnitdBm bool
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -205,6 +206,7 @@ func NewCollector(excludeInterfaces []string, includeInterfaces []string, collec
return &TransceiverCollector{
excludeInterfaces: excludeInterfaces,
includeInterfaces: includeInterfaces,
excludeInterfacesDown: excludeInterfacesDown,
collectInterfaceFeatures: collectInterfaceFeatures,
powerUnitdBm: powerUnitdBm,
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 91bca34

Please sign in to comment.