remove bgp states introduced in by #46 since the information can now be extracted by using the up metric with better performance

This commit is contained in:
Daniel Czerwonk 2022-01-14 11:33:50 +01:00
parent cde3432490
commit c99e498508
6 changed files with 2 additions and 105 deletions

View File

@ -51,16 +51,6 @@ func (c *BirdClient) GetOSPFAreas(protocol *protocol.Protocol) ([]*protocol.Ospf
return parser.ParseOspf(b), nil
}
// GetBGPStates retrieves BGP state information from bird
func (c *BirdClient) GetBGPStates(protocol *protocol.Protocol) (*protocol.BgpState, error) {
sock := c.socketFor(protocol.IPVersion)
b, err := birdsocket.Query(sock, fmt.Sprintf("show protocols all %s", protocol.Name))
if err != nil {
return nil, err
}
return parser.ParseBgpState(b), nil
}
func (c *BirdClient) protocolsFromBird(ipVersions []string) ([]*protocol.Protocol, error) {
protocols := make([]*protocol.Protocol, 0)

View File

@ -10,7 +10,4 @@ type Client interface {
// GetOSPFAreas retrieves OSPF specific information from bird
GetOSPFAreas(protocol *protocol.Protocol) ([]*protocol.OspfArea, error)
// GetBGPStates retrieves BGP state information from bird
GetBGPStates(protocol *protocol.Protocol) (*protocol.BgpState, error)
}

View File

@ -49,7 +49,7 @@ func exportersForLegacy(c *client.BirdClient) map[protocol.Proto][]metrics.Metri
l := metrics.NewLegacyLabelStrategy()
return map[protocol.Proto][]metrics.MetricExporter{
protocol.BGP: {metrics.NewLegacyMetricExporter("bgp4_session", "bgp6_session", l), metrics.NewBGPStateExporter("", c)},
protocol.BGP: {metrics.NewLegacyMetricExporter("bgp4_session", "bgp6_session", l)},
protocol.Direct: {metrics.NewLegacyMetricExporter("direct4", "direct6", l)},
protocol.Kernel: {metrics.NewLegacyMetricExporter("kernel4", "kernel6", l)},
protocol.OSPF: {metrics.NewLegacyMetricExporter("ospf", "ospfv3", l), metrics.NewOSPFExporter("", c)},
@ -64,7 +64,7 @@ func exportersForDefault(c *client.BirdClient, descriptionLabels bool) map[proto
e := metrics.NewGenericProtocolMetricExporter("bird_protocol", true, l)
return map[protocol.Proto][]metrics.MetricExporter{
protocol.BGP: {e, metrics.NewBGPStateExporter("bird_", c)},
protocol.BGP: {e},
protocol.Direct: {e},
protocol.Kernel: {e},
protocol.OSPF: {e, metrics.NewOSPFExporter("bird_", c)},

View File

@ -1,36 +0,0 @@
package metrics
import (
"github.com/czerwonk/bird_exporter/client"
"github.com/czerwonk/bird_exporter/protocol"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
type bgpStateMetricExporter struct {
prefix string
client client.Client
}
// NewBGPStateExporter creates a new MetricExporter for BGP metrics
func NewBGPStateExporter(prefix string, client client.Client) MetricExporter {
return &bgpStateMetricExporter{prefix: prefix, client: client}
}
func (m *bgpStateMetricExporter) Describe(ch chan<- *prometheus.Desc) {
}
func (m *bgpStateMetricExporter) Export(p *protocol.Protocol, ch chan<- prometheus.Metric, newFormat bool) {
labels := []string{"name", "proto", "state"}
bgpstateDesc := prometheus.NewDesc(m.prefix+"bgp_state_count", "Number of BGP connections at each state", labels, nil)
state, err := m.client.GetBGPStates(p)
if err != nil {
log.Errorln(err)
return
}
if state != nil {
l := []string{state.Name, "BGP", state.State}
ch <- prometheus.MustNewConstMetric(bgpstateDesc, prometheus.GaugeValue, float64(1), l...)
}
}

View File

@ -1,48 +0,0 @@
package parser
import (
"bufio"
"bytes"
"regexp"
"strings"
"github.com/czerwonk/bird_exporter/protocol"
)
var (
bgpStateRegex *regexp.Regexp
)
type bgpStateContext struct {
line string
current *protocol.BgpState
}
func init() {
bgpStateRegex = regexp.MustCompile(`^(?:1002\-)?([^\s]+)\s+(MRT|BGP|BFD|OSPF|RPKI|RIP|RAdv|Pipe|Perf|Direct|Babel|Device|Kernel|Static)\s+([^\s]+)\s+([^\s]+)\s+(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}|[^\s]+)\s+(Idle|Connect|Active|OpenSent|OpenConfirm|Established|Close)(?:\s+(.*?))?$`)
}
func ParseBgpState(data []byte) *protocol.BgpState {
reader := bytes.NewReader(data)
scanner := bufio.NewScanner(reader)
c := &bgpStateContext{
current: nil,
}
for scanner.Scan() {
c.line = strings.TrimRight(scanner.Text(), " ")
if c.line == "" {
c.current = nil
}
m := bgpStateRegex.FindStringSubmatch(c.line)
if m != nil {
s := &protocol.BgpState{Name: m[1]}
c.current = s
c.current.State = m[6]
break
}
}
return c.current
}

View File

@ -1,6 +0,0 @@
package protocol
type BgpState struct {
Name string
State string
}