Skip to content

Commit

Permalink
Visibility thresholds can be overridden via args
Browse files Browse the repository at this point in the history
  * Visibility thresholds can be overridden via command line arguments.
  * Format the default thresholds in help output
  • Loading branch information
ties committed Jun 22, 2021
1 parent 79a006c commit 71a7648
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions cmd/rtrmon/rtrmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"runtime"
"strconv"
"strings"
"sync"
"time"

Expand All @@ -35,6 +36,8 @@ const (
METHOD_KEY
)

type thresholds []int64

var (
version = ""
buildinfos = ""
Expand Down Expand Up @@ -133,7 +136,7 @@ var (
2: "secondary",
}

VisibilityThresholds = []int64{0, 56, 256, 596, 851, 1024, 1706, 3411}
visibilityThresholds = thresholds{0, 56, 256, 596, 851, 1024, 1706, 3411}
)

func init() {
Expand All @@ -143,6 +146,39 @@ func init() {
prometheus.MustRegister(RTRSerial)
prometheus.MustRegister(RTRSession)
prometheus.MustRegister(LastUpdate)

flag.Var(&visibilityThresholds, "visibility.thresholds", "comma-separated list of visibility thresholds to override the default")
}

// String formats an array of thresholds as a comma separated string.
func (t *thresholds) String() string {
res := []byte("")
for idx, tr := range *t {
res = strconv.AppendInt(res, tr, 10)
if idx < len(*t)-1 {
res = append(res, ","...)
}
}
return string(res)
}

func (t *thresholds) Set(value string) error {
// Setting overrides current values
if len(*t) > 0 {
*t = thresholds{}
}

for _, tr := range strings.Split(value, ",") {
threshold, err := strconv.ParseInt(tr, 10, 32)

if err != nil {
return err
}

*t = append(*t, threshold)
}

return nil
}

func decodeJSON(data []byte) (*prefixfile.VRPList, error) {
Expand Down Expand Up @@ -631,7 +667,7 @@ func (c *Comparator) Compare() {
"type": "diff",
}).Set(float64(len(onlyIn2)))

for _, visibleFor := range VisibilityThresholds {
for _, visibleFor := range visibilityThresholds {
thresholdTimestamp := time.Now().Unix() - visibleFor
// Prevent differences with value 0 appearing if the process has not
// been running long enough for them to exist.
Expand Down

0 comments on commit 71a7648

Please sign in to comment.