From 1f23b5456e8d3cfd9c663e62407129a31bc7f293 Mon Sep 17 00:00:00 2001 From: Ezri Zhu Date: Thu, 25 Jul 2024 15:47:36 -0400 Subject: [PATCH] export avail status and origin as --- lg.go | 35 +++++++---- main.go | 22 +------ prefixes.go | 176 +++++++++++++++++++++++++++++++++++----------------- vis.go | 25 +++++--- 4 files changed, 159 insertions(+), 99 deletions(-) diff --git a/lg.go b/lg.go index bce54d5..cc5e884 100644 --- a/lg.go +++ b/lg.go @@ -4,6 +4,7 @@ import ( "encoding/json" "io/ioutil" "net/http" + "strconv" "strings" "github.com/prometheus/client_golang/prometheus" @@ -17,13 +18,13 @@ var ( Name: "direct_upstreams", Help: "upstreams", }, - []string{"prefix", "city", "mux", "upstreams"}, + []string{"prefix", "city", "mux", "upstreams", "available", "origin"}, ) upstreams2Gauge = promauto.NewGaugeVec(prometheus.GaugeOpts{ Name: "indirect_upstreams", Help: "upstreams", }, - []string{"prefix", "city", "mux", "upstreams"}, + []string{"prefix", "city", "mux", "upstreams", "available", "origin"}, ) //bgpCommunitiesGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{ // Name: "bgp_communities", @@ -33,9 +34,9 @@ var ( //) ) -func (p *PrefixState) checkLGState() { - log.Trace().Str("Prefix", p.Prefix).Msg("checking prefix state") - url := ripestatBase + "/data/looking-glass/data.json?resource=" + p.Prefix + "&sourceapp=" + appId +func (p *Prefix) checkLGState() { + log.Trace().Str("Prefix", p.prefix).Msg("checking prefix state") + url := ripestatBase + "/data/looking-glass/data.json?resource=" + p.prefix + "&sourceapp=" + appId resp, err := http.Get(url) if err != nil { log.Error().Err(err).Msg("Fetching ripestat") @@ -56,8 +57,12 @@ func (p *PrefixState) checkLGState() { Msg("ripestat(lg) resp status code != 200") } - p.Mu.Lock() - defer p.Mu.Unlock() + availableStr := "y" + if !p.available { + availableStr = "n" + } + + origin := strconv.Itoa(p.origin) for _, rrc := range ripeStatLookingGlassResp.Data.Rrcs { upstreams := []string{} @@ -90,25 +95,29 @@ func (p *PrefixState) checkLGState() { } upstreamsGauge.WithLabelValues( - p.Prefix, + p.prefix, rrc.Location, - prefixes[p.Prefix], + p.pop, strings.Join(upstreams, " "), + availableStr, + origin, ).Set(float64(len(upstreams))) upstreams2Gauge.WithLabelValues( - p.Prefix, + p.prefix, rrc.Location, - prefixes[p.Prefix], + p.pop, strings.Join(upstreams2, " "), + availableStr, + origin, ).Set(float64(len(upstreams2))) //communities = slices.Compact(communities) //for _, e := range communities { // bgpCommunitiesGauge.WithLabelValues( - // p.Prefix, + // p.prefix, // rrc.Location, - // prefixes[p.Prefix], + // prefixes[p.prefix], // e, // ).Set(1) //} diff --git a/main.go b/main.go index fb6b428..11280d2 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,6 @@ import ( "os" "os/signal" "strconv" - "sync" "syscall" "time" @@ -18,25 +17,17 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) -var prefixStates = []*PrefixState{} - var port int var appId string var debug bool const ripestatBase = "https://stat.ripe.net" -type PrefixState struct { - Prefix string - State map[string]float32 - Mu sync.Mutex -} - func updateStates() { log.Debug().Msg("Updating Prefixes") - for _, ps := range prefixStates { - go ps.checkVisState() - go ps.checkLGState() + for _, prefix := range monitorState { + go prefix.checkVisState() + go prefix.checkLGState() } } @@ -64,13 +55,6 @@ func main() { Str("Data Source", "RIPE RIS via RIPEstat API"). Msg("Starting PEERINGMON Exporter") - for prefix, _ := range prefixes { - prefixStates = append(prefixStates, &PrefixState{ - Prefix: prefix, - State: make(map[string]float32), - }) - } - updateStates() go func() { diff --git a/prefixes.go b/prefixes.go index b3d47cc..d5bd996 100644 --- a/prefixes.go +++ b/prefixes.go @@ -1,62 +1,124 @@ package main -var prefixes = map[string]string{ - "2804:269c:fe41::/48": "seattle01", - "2804:269c:fe42::/48": "isi01", - "2804:269c:fe43::/48": "cornell01", - "2804:269c:fe44::/48": "phoenix01", - "2804:269c:fe45::/48": "amsterdam01", - "2804:269c:fe46::/48": "gatech01", - "2804:269c:fe47::/48": "ufmg01", - "2804:269c:fe49::/48": "grnet01", - "2804:269c:fe4a::/48": "uw01", - "2804:269c:fe4b::/48": "wisc01", - "2804:269c:fe4c::/48": "usc01", - "2804:269c:fe4d::/48": "dallas01", - "2804:269c:fe4e::/48": "neu01", - "2804:269c:fe4f::/48": "sbu01", - "2804:269c:fe50::/48": "clemson01", - "2804:269c:fe51::/48": "utah01", - "2804:269c:fe53::/48": "saopaulo01", - "2804:269c:fe54::/48": "fabwash", - "2804:269c:fe56::/48": "fabstar", - "2804:269c:fe57::/48": "vtrmiami", - "2804:269c:fe58::/48": "vtratlanta", - "2804:269c:fe59::/48": "vtramsterdam", - "2804:269c:fe5a::/48": "vtrtokyo", - "2804:269c:fe5b::/48": "vtrsydney", - "2804:269c:fe5c::/48": "vtrfrankfurt", - "2804:269c:fe5d::/48": "vtrseattle", - "2804:269c:fe5e::/48": "vtrchicago", - "2804:269c:fe5f::/48": "vtrparis", - "2804:269c:fe60::/48": "vtrsingapore", - "2804:269c:fe61::/48": "vtrwarsaw", - "2804:269c:fe62::/48": "vtrnewyork", - "2804:269c:fe63::/48": "vtrdallas", - "2804:269c:fe64::/48": "vtrmexico", - "2804:269c:fe65::/48": "vtrtoronto", - "2804:269c:fe66::/48": "vtrmadrid", - "2804:269c:fe67::/48": "vtrstockholm", - "2804:269c:fe68::/48": "vtrbangalore", - "2804:269c:fe69::/48": "vtrdelhi", - "2804:269c:fe6a::/48": "vtrlosangelas", - "2804:269c:fe6b::/48": "vtrsilicon", - "2804:269c:fe6c::/48": "vtrlondon", - "2804:269c:fe6d::/48": "vtrmumbai", - "2804:269c:fe6e::/48": "vtrseoul", - "2804:269c:fe6f::/48": "vtrmelbourne", - "2804:269c:fe70::/48": "vtrsaopaulo", - "2804:269c:fe71::/48": "vtrjohannesburg", - "2804:269c:fe72::/48": "vtrosaka", - "2804:269c:fe73::/48": "vtrsantiago", - "2804:269c:fe74::/48": "vtrmanchester", - "2804:269c:fe75::/48": "vtrtelaviv", - "2804:269c:fe76::/48": "vtrhonolulu", - "2804:269c:fe77::/48": "cfuseast1", +type Prefix struct { + prefix string + pop string + available bool + origin int +} + +var monitorState = []Prefix{ + Prefix{prefix: "2804:269c:fe01::/48", pop: "seattle01", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe02::/48", pop: "isi01", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe03::/48", pop: "cornell01", available: false, origin: 47065}, + Prefix{prefix: "2804:269c:fe04::/48", pop: "phoenix01", available: false, origin: 47065}, + Prefix{prefix: "2804:269c:fe05::/48", pop: "amsterdam01", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe06::/48", pop: "gatech01", available: false, origin: 47065}, + Prefix{prefix: "2804:269c:fe07::/48", pop: "ufmg01", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe09::/48", pop: "grnet01", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe0a::/48", pop: "uw01", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe0b::/48", pop: "wisc01", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe0c::/48", pop: "usc01", available: false, origin: 47065}, + Prefix{prefix: "2804:269c:fe0d::/48", pop: "dallas01", available: false, origin: 47065}, + Prefix{prefix: "2804:269c:fe0e::/48", pop: "neu01", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe0f::/48", pop: "sbu01", available: false, origin: 47065}, + Prefix{prefix: "2804:269c:fe10::/48", pop: "clemson01", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe11::/48", pop: "utah01", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe13::/48", pop: "saopaulo01", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe14::/48", pop: "fabwash", available: false, origin: 47065}, + Prefix{prefix: "2804:269c:fe16::/48", pop: "fabstar", available: false, origin: 47065}, + Prefix{prefix: "2804:269c:fe17::/48", pop: "vtrmiami", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe18::/48", pop: "vtratlanta", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe19::/48", pop: "vtramsterdam", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe1a::/48", pop: "vtrtokyo", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe1b::/48", pop: "vtrsydney", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe1c::/48", pop: "vtrfrankfurt", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe1d::/48", pop: "vtrseattle", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe1e::/48", pop: "vtrchicago", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe1f::/48", pop: "vtrparis", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe20::/48", pop: "vtrsingapore", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe21::/48", pop: "vtrwarsaw", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe22::/48", pop: "vtrnewyork", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe23::/48", pop: "vtrdallas", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe24::/48", pop: "vtrmexico", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe25::/48", pop: "vtrtoronto", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe26::/48", pop: "vtrmadrid", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe27::/48", pop: "vtrstockholm", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe28::/48", pop: "vtrbangalore", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe29::/48", pop: "vtrdelhi", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe2a::/48", pop: "vtrlosangelas", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe2b::/48", pop: "vtrsilicon", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe2c::/48", pop: "vtrlondon", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe2d::/48", pop: "vtrmumbai", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe2e::/48", pop: "vtrseoul", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe2f::/48", pop: "vtrmelbourne", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe30::/48", pop: "vtrsaopaulo", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe31::/48", pop: "vtrjohannesburg", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe32::/48", pop: "vtrosaka", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe33::/48", pop: "vtrsantiago", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe34::/48", pop: "vtrmanchester", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe35::/48", pop: "vtrtelaviv", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe36::/48", pop: "vtrhonolulu", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe37::/48", pop: "cfuseast1", available: true, origin: 47065}, + Prefix{prefix: "2804:269c:fe38::/48", pop: "vtrezri1", available: true, origin: 47065}, + + Prefix{prefix: "2804:269c:fe41::/48", pop: "seattle01", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe42::/48", pop: "isi01", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe43::/48", pop: "cornell01", available: false, origin: 61574}, + Prefix{prefix: "2804:269c:fe44::/48", pop: "phoenix01", available: false, origin: 61574}, + Prefix{prefix: "2804:269c:fe45::/48", pop: "amsterdam01", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe46::/48", pop: "gatech01", available: false, origin: 61574}, + Prefix{prefix: "2804:269c:fe47::/48", pop: "ufmg01", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe49::/48", pop: "grnet01", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe4a::/48", pop: "uw01", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe4b::/48", pop: "wisc01", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe4c::/48", pop: "usc01", available: false, origin: 61574}, + Prefix{prefix: "2804:269c:fe4d::/48", pop: "dallas01", available: false, origin: 61574}, + Prefix{prefix: "2804:269c:fe4e::/48", pop: "neu01", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe4f::/48", pop: "sbu01", available: false, origin: 61574}, + Prefix{prefix: "2804:269c:fe50::/48", pop: "clemson01", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe51::/48", pop: "utah01", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe53::/48", pop: "saopaulo01", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe54::/48", pop: "fabwash", available: false, origin: 61574}, + Prefix{prefix: "2804:269c:fe56::/48", pop: "fabstar", available: false, origin: 61574}, + Prefix{prefix: "2804:269c:fe57::/48", pop: "vtrmiami", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe58::/48", pop: "vtratlanta", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe59::/48", pop: "vtramsterdam", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe5a::/48", pop: "vtrtokyo", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe5b::/48", pop: "vtrsydney", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe5c::/48", pop: "vtrfrankfurt", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe5d::/48", pop: "vtrseattle", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe5e::/48", pop: "vtrchicago", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe5f::/48", pop: "vtrparis", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe60::/48", pop: "vtrsingapore", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe61::/48", pop: "vtrwarsaw", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe62::/48", pop: "vtrnewyork", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe63::/48", pop: "vtrdallas", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe64::/48", pop: "vtrmexico", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe65::/48", pop: "vtrtoronto", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe66::/48", pop: "vtrmadrid", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe67::/48", pop: "vtrstockholm", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe68::/48", pop: "vtrbangalore", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe69::/48", pop: "vtrdelhi", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe6a::/48", pop: "vtrlosangelas", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe6b::/48", pop: "vtrsilicon", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe6c::/48", pop: "vtrlondon", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe6d::/48", pop: "vtrmumbai", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe6e::/48", pop: "vtrseoul", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe6f::/48", pop: "vtrmelbourne", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe70::/48", pop: "vtrsaopaulo", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe71::/48", pop: "vtrjohannesburg", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe72::/48", pop: "vtrosaka", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe73::/48", pop: "vtrsantiago", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe74::/48", pop: "vtrmanchester", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe75::/48", pop: "vtrtelaviv", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe76::/48", pop: "vtrhonolulu", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe77::/48", pop: "cfuseast1", available: true, origin: 61574}, + Prefix{prefix: "2804:269c:fe78::/48", pop: "vtrezri1", available: true, origin: 61574}, - //"104.17.224.0/20": "cf valid4", - //"2606:4700::/44": "cf valid6", + Prefix{prefix: "104.17.224.0/20", pop: "cf valid4", available: true, origin: 13335}, + Prefix{prefix: "2606:4700::/44", pop: "cf valid6", available: true, origin: 13335}, - //"103.21.244.0/24": "cf invalid4", - //"2606:4700:7000::/48": "cf invalid6", + Prefix{prefix: "103.21.244.0/24", pop: "cf invalid4", available: false, origin: 13335}, + Prefix{prefix: "2606:4700:7000::/48", pop: "cf invalid6", available: false, origin: 13335}, } diff --git a/vis.go b/vis.go index 8e5fd3c..0f6cd68 100644 --- a/vis.go +++ b/vis.go @@ -4,6 +4,7 @@ import ( "encoding/json" "io/ioutil" "net/http" + "strconv" "strings" "github.com/prometheus/client_golang/prometheus" @@ -15,12 +16,12 @@ var ( prefixStateGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{ Name: "prefix_visibility", Help: "Visibility of the prefix", - }, []string{"prefix", "city", "mux"}) + }, []string{"prefix", "city", "mux", "available", "origin"}) ) -func (p *PrefixState) checkVisState() { - log.Trace().Str("Prefix", p.Prefix).Msg("checking prefix state") - url := ripestatBase + "/data/visibility/data.json?data_overload_limit=ignore&include=peers_seeing&resource=" + p.Prefix + "&sourceapp=" + appId +func (p *Prefix) checkVisState() { + log.Trace().Str("Prefix", p.prefix).Msg("checking prefix state") + url := ripestatBase + "/data/visibility/data.json?data_overload_limit=ignore&include=peers_seeing&resource=" + p.prefix + "&sourceapp=" + appId resp, err := http.Get(url) if err != nil { log.Error().Err(err).Msg("Fetching ripestat") @@ -41,10 +42,13 @@ func (p *PrefixState) checkVisState() { Msg("ripestat(vis) resp status code != 200") } - ipv6 := strings.Contains(p.Prefix, ":") + ipv6 := strings.Contains(p.prefix, ":") - p.Mu.Lock() - defer p.Mu.Unlock() + availableStr := "y" + if !p.available { + availableStr = "n" + } + origin := strconv.Itoa(p.origin) for _, probe := range ripeStatVisibilityResp.Data.Visibilities { var vis float32 @@ -56,11 +60,12 @@ func (p *PrefixState) checkVisState() { float32(probe.Ipv4FullTablePeerCount) } - p.State[probe.Probe.City] = vis prefixStateGauge.WithLabelValues( - p.Prefix, + p.prefix, probe.Probe.City, - prefixes[p.Prefix], + p.pop, + availableStr, + origin, ).Set(float64(vis)) } }