Skip to content

Commit

Permalink
combine router_monitor_arp_devices and router_monitor_hostnames metric
Browse files Browse the repository at this point in the history
  • Loading branch information
blesswinsamuel committed Aug 9, 2024
1 parent 8d72b9e commit 380e9e1
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions internal/routermonitor/arp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ type arpCollector struct {
hostCache map[string]hostCacheValue
hostCacheMutex sync.Mutex

arpDevices *prometheus.Desc
firewallHostnames *prometheus.Desc
arpDevices *prometheus.Desc
}

func NewArpCollector(filename string, stripDomainSuffix string) *arpCollector {
Expand All @@ -34,17 +33,13 @@ func NewArpCollector(filename string, stripDomainSuffix string) *arpCollector {
stripDomainSuffix: stripDomainSuffix,
hostCache: make(map[string]hostCacheValue),
arpDevices: prometheus.NewDesc("router_monitor_arp_devices", "",
[]string{"ip_addr", "hw_addr", "device"}, nil,
),
firewallHostnames: prometheus.NewDesc("router_monitor_hostnames", "",
[]string{"ip_addr", "hostname", "device"}, nil,
[]string{"ip_addr", "hw_addr", "hostname", "device"}, nil,
),
}
}

func (collector *arpCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- collector.arpDevices
ch <- collector.firewallHostnames
}

// Collect implements required collect function for all promehteus collectors
Expand Down Expand Up @@ -94,8 +89,7 @@ func (collector *arpCollector) Collect(ch chan<- prometheus.Metric) {
log.Printf("Error parsing flag: %v", err)
}
device := fields[5]
ch <- prometheus.MustNewConstMetric(collector.arpDevices, prometheus.GaugeValue, float64(flag), ipAddr, hwAddr, device)
ch <- prometheus.MustNewConstMetric(collector.firewallHostnames, prometheus.GaugeValue, 1, ipAddr, hostname, device)
ch <- prometheus.MustNewConstMetric(collector.arpDevices, prometheus.GaugeValue, float64(flag), ipAddr, hwAddr, hostname, device)
}

if err := scanner.Err(); err != nil {
Expand Down

0 comments on commit 380e9e1

Please sign in to comment.