Skip to content

Commit

Permalink
Add metric for number of VRPs in grace period
Browse files Browse the repository at this point in the history
  • Loading branch information
ties committed Jul 11, 2022
1 parent baf52f2 commit 5b022de
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/rtrmon/rtrmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ var (
},
[]string{"lhs_url", "rhs_url", "visibility_seconds"},
)
VRPInGracePeriod = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "rpki_grace_period_vrps",
Help: "Number of unique VRPS in grace period by url.",
},
[]string{"url"},
)
RTRState = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "rtr_state",
Expand Down Expand Up @@ -148,6 +155,7 @@ var (
func init() {
prometheus.MustRegister(VRPCount)
prometheus.MustRegister(VRPDifferenceForDuration)
prometheus.MustRegister(VRPInGracePeriod)
prometheus.MustRegister(RTRState)
prometheus.MustRegister(RTRSerial)
prometheus.MustRegister(RTRSession)
Expand Down Expand Up @@ -336,7 +344,7 @@ func (c *Client) Start(id int, ch chan int) {
}

tCurrentUpdate := time.Now().UTC()
updatedVrpMap := buildNewVrpMap(c.id, c.vrps, decoded.Data, tCurrentUpdate)
updatedVrpMap := c.buildNewVrpMap(decoded.Data, tCurrentUpdate)

c.compLock.Lock()
c.vrps = updatedVrpMap
Expand All @@ -356,27 +364,27 @@ func (c *Client) Start(id int, ch chan int) {
// * contains all the VRPs in newVRPs
// * keeps the firstSeen value for VRPs already in the old map
// * keeps elements around for GracePeriod after they are not in the input.
func buildNewVrpMap(id int, currentVrpMap vrpMap, newVrps []prefixfile.VRPJson, now time.Time) vrpMap {
func (c *Client) buildNewVrpMap(newVrps []prefixfile.VRPJson, now time.Time) vrpMap {
tCurrentUpdate := now.Unix()
res := make(vrpMap)

for _, vrp := range newVrps {
asn, err := vrp.GetASN2()
if err != nil {
log.Errorf("%d: exploration error for %v asn: %v", id, vrp, err)
log.Errorf("%d: exploration error for %v asn: %v", c.id, vrp, err)
continue
}
prefix, err := vrp.GetPrefix2()
if err != nil {
log.Errorf("%d: exploration error for %v prefix: %v", id, vrp, err)
log.Errorf("%d: exploration error for %v prefix: %v", c.id, vrp, err)
continue
}

maxlen := vrp.GetMaxLen()
key := fmt.Sprintf("%s-%d-%d", prefix.String(), maxlen, asn)

firstSeen := tCurrentUpdate
currentEntry, ok := currentVrpMap[key]
currentEntry, ok := c.vrps[key]
if ok {
firstSeen = currentEntry.FirstSeen
}
Expand All @@ -402,6 +410,8 @@ func buildNewVrpMap(id int, currentVrpMap vrpMap, newVrps []prefixfile.VRPJson,
}
}

VRPInGracePeriod.With(prometheus.Labels{"url": c.Path}).Set(float64(inGracePeriod))

return res
}

Expand Down

0 comments on commit 5b022de

Please sign in to comment.