Skip to content

Commit

Permalink
refactor: change the way upstreams presented
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrizhu committed Jul 22, 2024
1 parent d9bbdaa commit 628d33c
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions lg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"io/ioutil"
"net/http"
"strconv"
"strings"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -15,10 +14,10 @@ import (

var (
asPathGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "as_path",
Help: "AS PATH",
Name: "upstreams",
Help: "upstreams",
},
[]string{"prefix", "city", "mux"},
[]string{"prefix", "city", "mux", "upstreams"},
)
//bgpCommunitiesGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
// Name: "bgp_communities",
Expand Down Expand Up @@ -55,14 +54,13 @@ func (p *PrefixState) checkLGState() {
defer p.Mu.Unlock()

for _, rrc := range ripeStatLookingGlassResp.Data.Rrcs {
upstreams := []int{}
upstreams := []string{}
//communities := []string{}
for _, peer := range rrc.Peers {
asPathSplit := strings.Split(peer.AsPath, " ")
upstream := 0
upstream := ""
if len(asPathSplit) >= 2 {
upstreamStr := asPathSplit[len(asPathSplit)-2]
upstream, err = strconv.Atoi(upstreamStr)
upstream = asPathSplit[len(asPathSplit)-2]
if err != nil {
log.Err(err).Msg("atoi fail")
}
Expand All @@ -71,13 +69,12 @@ func (p *PrefixState) checkLGState() {
//communities = append(communities, peer.Community)
}
upstreams = slices.Compact(upstreams)
for _, upstream := range upstreams {
asPathGauge.WithLabelValues(
p.Prefix,
rrc.Location,
prefixes[p.Prefix],
).Set(float64(upstream))
}
asPathGauge.WithLabelValues(
p.Prefix,
rrc.Location,
prefixes[p.Prefix],
strings.Join(upstreams, " "),
).Set(float64(len(upstreams)))
//communities = slices.Compact(communities)
//for _, e := range communities {
// bgpCommunitiesGauge.WithLabelValues(
Expand Down

0 comments on commit 628d33c

Please sign in to comment.