Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
add min-age option to mt-index-cat
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed Sep 27, 2018
1 parent 31b2ffa commit c31344b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 17 additions & 5 deletions cmd/mt-index-cat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func main() {
var tags string
var from string
var maxAge string
var minAge string
var verbose bool
var limit int
var partitionStr string
Expand All @@ -42,7 +43,8 @@ func main() {
globalFlags.StringVar(&partitionStr, "partitions", "*", "only show metrics from the comma separated list of partitions or * for all")
globalFlags.StringVar(&tags, "tags", "", "tag filter. empty (default), 'some', 'none', 'valid', or 'invalid'")
globalFlags.StringVar(&from, "from", "30min", "for vegeta outputs, will generate requests for data starting from now minus... eg '30min', '5h', '14d', etc. or a unix timestamp")
globalFlags.StringVar(&maxAge, "max-age", "6h30min", "max age (last update diff with now) of metricdefs. use 0 to disable")
globalFlags.StringVar(&maxAge, "max-age", "6h30min", "max age (lastUpdate diff with now) of metricdefs. use 0 to disable")
globalFlags.StringVar(&minAge, "min-age", "0", "min age (lastUpdate diff with now) of metricdefs. use 0 to disable")
globalFlags.IntVar(&limit, "limit", 0, "only show this many metrics. use 0 to disable")
globalFlags.BoolVar(&verbose, "verbose", false, "print stats to stderr")

Expand Down Expand Up @@ -180,17 +182,24 @@ func main() {
perror(err)
}

var cutoff uint32
var cutoff, cutoffMin int64
now := time.Now().Unix()
if maxAge != "0" {
maxAgeInt, err := dur.ParseNDuration(maxAge)
perror(err)
cutoff = uint32(time.Now().Unix() - int64(maxAgeInt))
cutoff = now - int64(maxAgeInt)
}
if minAge != "0" {
minAgeInt, err := dur.ParseNDuration(minAge)
perror(err)
cutoffMin = now - int64(minAgeInt)
}

var defs []schema.MetricDefinition
if len(partitions) == 0 {
defs = idx.Load(nil, cutoff)
defs = idx.Load(nil, uint32(cutoff))
} else {
defs = idx.LoadPartitions(partitions, nil, cutoff)
defs = idx.LoadPartitions(partitions, nil, uint32(cutoff))
}
// set this after doing the query, to assure age can't possibly be negative
out.QueryTime = time.Now().Unix()
Expand Down Expand Up @@ -223,6 +232,9 @@ func main() {
continue
}
}
if cutoffMin != 0 && d.LastUpdate >= cutoffMin {
continue
}
show(d)
shown += 1
if shown == limit {
Expand Down
4 changes: 3 additions & 1 deletion docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ global config flags:
-limit int
only show this many metrics. use 0 to disable
-max-age string
max age (last update diff with now) of metricdefs. use 0 to disable (default "6h30min")
max age (lastUpdate diff with now) of metricdefs. use 0 to disable (default "6h30min")
-min-age string
min age (lastUpdate diff with now) of metricdefs. use 0 to disable (default "0")
-partitions string
only show metrics from the comma separated list of partitions or * for all (default "*")
-prefix string
Expand Down

0 comments on commit c31344b

Please sign in to comment.