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

add metrics for MAC address table #156

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions collectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/czerwonk/junos_exporter/isis"
"github.com/czerwonk/junos_exporter/l2circuit"
"github.com/czerwonk/junos_exporter/ldp"
"github.com/czerwonk/junos_exporter/mac"
"github.com/czerwonk/junos_exporter/nat"
"github.com/czerwonk/junos_exporter/ospf"
"github.com/czerwonk/junos_exporter/power"
Expand Down Expand Up @@ -93,6 +94,7 @@ func (c *collectors) initCollectorsForDevices(device *connector.Device) {
c.addCollectorIfEnabledForDevice(device, "storage", f.Storage, storage.NewCollector)
c.addCollectorIfEnabledForDevice(device, "system", f.System, system.NewCollector)
c.addCollectorIfEnabledForDevice(device, "power", f.Power, power.NewCollector)
c.addCollectorIfEnabledForDevice(device, "mac", f.MAC, mac.NewCollector)
c.addCollectorIfEnabledForDevice(device, "vrrp", f.VRRP, vrrp.NewCollector)
}

Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type FeatureConfig struct {
Satellite bool `yaml:"satellite,omitempty"`
System bool `yaml:"system,omitempty"`
Power bool `yaml:"power,omitempty"`
MAC bool `yaml:"mac,omitempty"`
VRRP bool `yaml:"vrrp,omitempty"`
}

Expand Down Expand Up @@ -107,6 +108,7 @@ func setDefaultValues(c *Config) {
f.RPM = false
f.Satellite = false
f.Power = false
f.MAC = false
f.VRRP = false
}

Expand Down
62 changes: 62 additions & 0 deletions mac/collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package mac

import (
"github.com/czerwonk/junos_exporter/collector"
"github.com/czerwonk/junos_exporter/rpc"
"github.com/prometheus/client_golang/prometheus"
)

const prefix string = "junos_mac_table_"

var (
totalCount *prometheus.Desc
recieveCount *prometheus.Desc
dynamicCount *prometheus.Desc
floodCount *prometheus.Desc
)

func init() {
l := []string{"target"}
totalCount = prometheus.NewDesc(prefix+"total_count", "Number of entries in table", l, nil)
recieveCount = prometheus.NewDesc(prefix+"recieve_count", "Number of L3 recieve route entries in table", l, nil)
dynamicCount = prometheus.NewDesc(prefix+"dynamic_count", "Number of dynamic entries in table", l, nil)
floodCount = prometheus.NewDesc(prefix+"flood_count", "Number of flood entries in table", l, nil)
}

type macCollector struct {
}

// Name returns the name of the collector
func (*macCollector) Name() string {
return "Mac"
}

// NewCollector creates a new collector
func NewCollector() collector.RPCCollector {
return &macCollector{}
}

// Describe describes the metrics
func (*macCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- totalCount
ch <- recieveCount
ch <- dynamicCount
ch <- floodCount
}

// Collect collects metrics from JunOS
func (c *macCollector) Collect(client *rpc.Client, ch chan<- prometheus.Metric, labelValues []string) error {
var x = MacRpc{}
err := client.RunCommandAndParse("show ethernet-switching table summary", &x)
if err != nil {
return err
}

entry := x.Information.Table.Entry
ch <- prometheus.MustNewConstMetric(totalCount, prometheus.GaugeValue, float64(entry.TotalCount), labelValues...)
ch <- prometheus.MustNewConstMetric(recieveCount, prometheus.GaugeValue, float64(entry.ReceiveCount), labelValues...)
ch <- prometheus.MustNewConstMetric(dynamicCount, prometheus.GaugeValue, float64(entry.DynamicCount), labelValues...)
ch <- prometheus.MustNewConstMetric(floodCount, prometheus.GaugeValue, float64(entry.FloodCount), labelValues...)

return nil
}
21 changes: 21 additions & 0 deletions mac/rpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mac

type MacRpc struct {
Information EthernetSwitchingTableInformation `xml:"ethernet-switching-table-information"`
}

type EthernetSwitchingTableInformation struct {
Table EthernetSwitchingTable `xml:"ethernet-switching-table"`
}

type EthernetSwitchingTable struct {
Entry MacTableEntry `xml:"mac-table-entry"`
}

type MacTableEntry struct {
TotalCount int64 `xml:"mac-table-total-count"`
ReceiveCount int64 `xml:"mac-table-recieve-count"`
DynamicCount int64 `xml:"mac-table-dynamic-count"`
FloodCount int64 `xml:"mac-table-flood-count"`
}

2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var (
rpkiEnabled = flag.Bool("rpki.enabled", false, "Scrape rpki metrics")
satelliteEnabled = flag.Bool("satellite.enabled", false, "Scrape metrics from satellite devices")
systemEnabled = flag.Bool("system.enabled", false, "Scrape system metrics")
macEnabled = flag.Bool("mac.enabled", false, "Scrape MAC address table metrics")
alarmFilter = flag.String("alarms.filter", "", "Regex to filter for alerts to ignore")
configFile = flag.String("config.file", "", "Path to config file")
dynamicIfaceLabels = flag.Bool("dynamic-interface-labels", true, "Parse interface descriptions to get labels dynamicly")
Expand Down Expand Up @@ -208,6 +209,7 @@ func loadConfigFromFlags() *config.Config {
f.Satellite = *satelliteEnabled
f.System = *systemEnabled
f.Power = *powerEnabled
f.MAC = *macEnabled

return c
}
Expand Down