Skip to content

Commit

Permalink
refactor for prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrizhu committed Jun 30, 2024
1 parent 80a2908 commit 0a12735
Showing 1 changed file with 68 additions and 16 deletions.
84 changes: 68 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,60 @@ const (
port = ":2112"
)

var prefixes = []string{
// PEERING v6
"2804:269c:fe41::/48",
"2804:269c:fe42::/48",
"2804:269c:fe44::/48",
"2804:269c:fe45::/48",
"2804:269c:fe47::/48",
"2804:269c:fe50::/48",
"2804:269c:fe51::/48",
"2804:269c:fe53::/48",
"2804:269c:fe56::/48",
"2804:269c:fe57::/48",
"2804:269c:fe58::/48",
"2804:269c:fe59::/48",
"2804:269c:fe5a::/48",
"2804:269c:fe5b::/48",
"2804:269c:fe5c::/48",
"2804:269c:fe5d::/48",
"2804:269c:fe5e::/48",
"2804:269c:fe5f::/48",
"2804:269c:fe60::/48",
"2804:269c:fe61::/48",
"2804:269c:fe62::/48",
"2804:269c:fe63::/48",
"2804:269c:fe64::/48",
"2804:269c:fe65::/48",
"2804:269c:fe66::/48",
"2804:269c:fe67::/48",
"2804:269c:fe68::/48",
"2804:269c:fe69::/48",
"2804:269c:fe6a::/48",
"2804:269c:fe6b::/48",
"2804:269c:fe6c::/48",
"2804:269c:fe6d::/48",
"2804:269c:fe6e::/48",
"2804:269c:fe6f::/48",
"2804:269c:fe70::/48",
"2804:269c:fe71::/48",
"2804:269c:fe72::/48",
"2804:269c:fe73::/48",
"2804:269c:fe74::/48",
"2804:269c:fe76::/48",

// isbgpsafeyet.com valid
"104.17.224.0/20",
"2606:4700::/44",

// isbgpsafeyet.com invalid
"103.21.244.0/24",
"2606:4700:7000::/48",
}

var prefixStates = []*PrefixState{}

var (
prefixStateGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "prefix_visibility",
Expand Down Expand Up @@ -72,36 +126,34 @@ func (p *PrefixState) checkState() {
}
}

func updateStates() {
log.Debug().Msg("Updating Prefixes")
for _, ps := range prefixStates {
ps.checkState()
}
}

func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})
zerolog.SetGlobalLevel(zerolog.DebugLevel)
log.Info().Msg("Starting PEERINGMON Exporter")

prefixes := []string{
"2804:269c:fe53::/48",
"2804:269c:fe56::/48",
"2606:4700:7000::/48",
"198.8.58.0/24",
}

prefixStates := make([]*PrefixState, len(prefixes))
for i, prefix := range prefixes {
prefixStates[i] = &PrefixState{Prefix: prefix, State: make(map[string]float32)}
for _, prefix := range prefixes {
prefixStates = append(prefixStates, &PrefixState{
Prefix: prefix,
State: make(map[string]float32),
})
}

for _, ps := range prefixStates {
ps.checkState()
}
updateStates()

go func() {
ticker := time.NewTicker(1 * time.Minute)
defer ticker.Stop()

for range ticker.C {
for _, ps := range prefixStates {
ps.checkState()
}
updateStates()
}
}()

Expand Down

0 comments on commit 0a12735

Please sign in to comment.