Skip to content

Commit

Permalink
Merge pull request #156 from kakkotetsu/ethernet-switching
Browse files Browse the repository at this point in the history
add metrics for MAC address table
  • Loading branch information
czerwonk authored Oct 19, 2021
2 parents ed4a82c + ac70ccb commit 7bfdf4e
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
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

0 comments on commit 7bfdf4e

Please sign in to comment.