diff --git a/.gitignore b/.gitignore index c38fa4e..5cfd391 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea *.iml +bird_exporter diff --git a/bgp/exporter.go b/bgp/exporter.go deleted file mode 100644 index d88a005..0000000 --- a/bgp/exporter.go +++ /dev/null @@ -1,26 +0,0 @@ -package bgp - -import ( - "github.com/czerwonk/bird_exporter/protocol" - "github.com/prometheus/client_golang/prometheus" -) - -var exporter map[int]*protocol.GenericProtocolMetricExporter - -type BgpMetricExporter struct { -} - -func init() { - exporter = make(map[int]*protocol.GenericProtocolMetricExporter) - exporter[4] = protocol.NewGenericProtocolMetricExporter("bgp4_session") - exporter[6] = protocol.NewGenericProtocolMetricExporter("bgp6_session") -} - -func (*BgpMetricExporter) Describe(ch chan<- *prometheus.Desc) { - exporter[4].Describe(ch) - exporter[6].Describe(ch) -} - -func (*BgpMetricExporter) Export(p *protocol.Protocol, ch chan<- prometheus.Metric) { - exporter[p.IpVersion].Export(p, ch) -} diff --git a/device/exporter.go b/device/exporter.go deleted file mode 100644 index 7306e74..0000000 --- a/device/exporter.go +++ /dev/null @@ -1,26 +0,0 @@ -package device - -import ( - "github.com/czerwonk/bird_exporter/protocol" - "github.com/prometheus/client_golang/prometheus" -) - -var exporter map[int]*protocol.GenericProtocolMetricExporter - -type DeviceMetricExporter struct { -} - -func init() { - exporter = make(map[int]*protocol.GenericProtocolMetricExporter) - exporter[4] = protocol.NewGenericProtocolMetricExporter("device4") - exporter[6] = protocol.NewGenericProtocolMetricExporter("device6") -} - -func (m *DeviceMetricExporter) Describe(ch chan<- *prometheus.Desc) { - exporter[4].Describe(ch) - exporter[6].Describe(ch) -} - -func (m *DeviceMetricExporter) Export(p *protocol.Protocol, ch chan<- prometheus.Metric) { - exporter[p.IpVersion].Export(p, ch) -} diff --git a/direct/exporter.go b/direct/exporter.go deleted file mode 100644 index d3051f0..0000000 --- a/direct/exporter.go +++ /dev/null @@ -1,26 +0,0 @@ -package direct - -import ( - "github.com/czerwonk/bird_exporter/protocol" - "github.com/prometheus/client_golang/prometheus" -) - -var exporter map[int]*protocol.GenericProtocolMetricExporter - -type DirectMetricExporter struct { -} - -func init() { - exporter = make(map[int]*protocol.GenericProtocolMetricExporter) - exporter[4] = protocol.NewGenericProtocolMetricExporter("direct4") - exporter[6] = protocol.NewGenericProtocolMetricExporter("direct6") -} - -func (*DirectMetricExporter) Describe(ch chan<- *prometheus.Desc) { - exporter[4].Describe(ch) - exporter[6].Describe(ch) -} - -func (*DirectMetricExporter) Export(p *protocol.Protocol, ch chan<- prometheus.Metric) { - exporter[p.IpVersion].Export(p, ch) -} diff --git a/kernel/exporter.go b/kernel/exporter.go deleted file mode 100644 index f2023d1..0000000 --- a/kernel/exporter.go +++ /dev/null @@ -1,26 +0,0 @@ -package kernel - -import ( - "github.com/czerwonk/bird_exporter/protocol" - "github.com/prometheus/client_golang/prometheus" -) - -var exporter map[int]*protocol.GenericProtocolMetricExporter - -type KernelMetricExporter struct { -} - -func init() { - exporter = make(map[int]*protocol.GenericProtocolMetricExporter) - exporter[4] = protocol.NewGenericProtocolMetricExporter("kernel4") - exporter[6] = protocol.NewGenericProtocolMetricExporter("kernel6") -} - -func (*KernelMetricExporter) Describe(ch chan<- *prometheus.Desc) { - exporter[4].Describe(ch) - exporter[6].Describe(ch) -} - -func (*KernelMetricExporter) Export(p *protocol.Protocol, ch chan<- prometheus.Metric) { - exporter[p.IpVersion].Export(p, ch) -} diff --git a/main.go b/main.go index 405188d..baf576e 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,7 @@ import ( "github.com/prometheus/common/log" ) -const version string = "0.9.0" +const version string = "1.0.0" var ( showVersion = flag.Bool("version", false, "Print version information.") diff --git a/metric_collector.go b/metric_collector.go index 2d7da8d..2ceab19 100644 --- a/metric_collector.go +++ b/metric_collector.go @@ -1,13 +1,8 @@ package main import ( - "github.com/czerwonk/bird_exporter/bgp" - "github.com/czerwonk/bird_exporter/device" - "github.com/czerwonk/bird_exporter/direct" - "github.com/czerwonk/bird_exporter/kernel" "github.com/czerwonk/bird_exporter/ospf" "github.com/czerwonk/bird_exporter/protocol" - "github.com/czerwonk/bird_exporter/static" "github.com/prometheus/client_golang/prometheus" ) @@ -23,12 +18,12 @@ type MetricCollector struct { func NewMetricCollectorForProtocols(protocols []*protocol.Protocol) *MetricCollector { e := map[int]MetricExporter{ - protocol.BGP: &bgp.BgpMetricExporter{}, - protocol.Device: &device.DeviceMetricExporter{}, - protocol.Direct: &direct.DirectMetricExporter{}, - protocol.Kernel: &kernel.KernelMetricExporter{}, + protocol.BGP: protocol.NewMetricExporter("bgp4_session", "bgp6_session"), + protocol.Device: protocol.NewMetricExporter("device4", "device6"), + protocol.Direct: protocol.NewMetricExporter("direct4", "direct6"), + protocol.Kernel: protocol.NewMetricExporter("kernel4", "kernel6"), protocol.OSPF: &ospf.OspfMetricExporter{}, - protocol.Static: &static.StaticMetricExporter{}, + protocol.Static: protocol.NewMetricExporter("static4", "static6"), } return &MetricCollector{protocols: protocols, exporters: e} diff --git a/protocol/exporter.go b/protocol/exporter.go new file mode 100644 index 0000000..213bb6d --- /dev/null +++ b/protocol/exporter.go @@ -0,0 +1,30 @@ +package protocol + +import ( + "github.com/prometheus/client_golang/prometheus" +) + +type ProtocolMetricExporter struct { + ipv4Exporter *GenericProtocolMetricExporter + ipv6Exporter *GenericProtocolMetricExporter +} + +func NewMetricExporter(prefixIpv4, prefixIpv6 string) *ProtocolMetricExporter { + return &ProtocolMetricExporter{ + ipv4Exporter: NewGenericProtocolMetricExporter(prefixIpv4), + ipv6Exporter: NewGenericProtocolMetricExporter(prefixIpv6), + } +} + +func (e *ProtocolMetricExporter) Describe(ch chan<- *prometheus.Desc) { + e.ipv4Exporter.Describe(ch) + e.ipv6Exporter.Describe(ch) +} + +func (e *ProtocolMetricExporter) Export(p *Protocol, ch chan<- prometheus.Metric) { + if p.IpVersion == 4 { + e.ipv4Exporter.Export(p, ch) + } else { + e.ipv6Exporter.Export(p, ch) + } +} diff --git a/static/exporter.go b/static/exporter.go deleted file mode 100644 index 952ff32..0000000 --- a/static/exporter.go +++ /dev/null @@ -1,26 +0,0 @@ -package static - -import ( - "github.com/czerwonk/bird_exporter/protocol" - "github.com/prometheus/client_golang/prometheus" -) - -var exporter map[int]*protocol.GenericProtocolMetricExporter - -type StaticMetricExporter struct { -} - -func init() { - exporter = make(map[int]*protocol.GenericProtocolMetricExporter) - exporter[4] = protocol.NewGenericProtocolMetricExporter("static4") - exporter[6] = protocol.NewGenericProtocolMetricExporter("static6") -} - -func (m *StaticMetricExporter) Describe(ch chan<- *prometheus.Desc) { - exporter[4].Describe(ch) - exporter[6].Describe(ch) -} - -func (m *StaticMetricExporter) Export(p *protocol.Protocol, ch chan<- prometheus.Metric) { - exporter[p.IpVersion].Export(p, ch) -}