diff --git a/cmd/mt-index-cat/main.go b/cmd/mt-index-cat/main.go index e85ee8e5c5..edb05f91d3 100644 --- a/cmd/mt-index-cat/main.go +++ b/cmd/mt-index-cat/main.go @@ -39,6 +39,7 @@ func main() { var prefix string var substr string var suffix string + var orgFilter int var regexStr string var regex *regexp.Regexp var tags string @@ -55,6 +56,7 @@ func main() { globalFlags.StringVar(&prefix, "prefix", "", "only show metrics that have this prefix") globalFlags.StringVar(&substr, "substr", "", "only show metrics that have this substring") globalFlags.StringVar(&suffix, "suffix", "", "only show metrics that have this suffix") + globalFlags.IntVar(&orgFilter, "org", -1, "show only metrics with this OrgID (-1 to disable)") globalFlags.StringVar(&partitionStr, "partitions", "*", "only show metrics from the comma separated list of partitions or * for all") globalFlags.IntVar(&btTotalPartitions, "bt-total-partitions", -1, "total number of partitions (when using bigtable and partitions='*')") globalFlags.StringVar(®exStr, "regex", "", "only show metrics that match this regex") @@ -318,6 +320,11 @@ func main() { if !strings.Contains(d.Name, substr) { continue } + + if orgFilter != -1 && d.OrgId != uint32(orgFilter) { + continue + } + if tags == "none" && len(d.Tags) != 0 { continue } @@ -364,7 +371,7 @@ func main() { } else { now := time.Now() for _, p := range partitions { - defs = btIdx.LoadPartition(p, nil, now) + defs = btIdx.LoadPartition(p, nil, now, orgFilter) // set this after doing the query, to assure age can't possibly be negative unless if clocks are misconfigured. out.QueryTime = time.Now().Unix() processDefs(defs) diff --git a/docs/tools.md b/docs/tools.md index 86d331725a..3ab5652179 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -201,6 +201,8 @@ global config flags: exclude series that have not been seen for this much time (compared against LastUpdate). use 0 to disable (default "6h30min") -min-stale string exclude series that have been seen in this much time (compared against LastUpdate). use 0 to disable (default "0") + -org int + show only metrics with this OrgID (-1 to disable) (default -1) -partitions string only show metrics from the comma separated list of partitions or * for all (default "*") -prefix string diff --git a/idx/bigtable/bigtable.go b/idx/bigtable/bigtable.go index fda62eed48..a9730f0058 100644 --- a/idx/bigtable/bigtable.go +++ b/idx/bigtable/bigtable.go @@ -278,14 +278,14 @@ func (b *BigtableIdx) rebuildIndex() { num := 0 var defs []schema.MetricDefinition for _, partition := range cluster.Manager.GetPartitions() { - defs = b.LoadPartition(partition, defs[:0], pre) + defs = b.LoadPartition(partition, defs[:0], pre, -1) num += b.MemoryIndex.LoadPartition(partition, defs) } log.Infof("bigtable-idx: Rebuilding Memory Index Complete. Imported %d. Took %s", num, time.Since(pre)) } -func (b *BigtableIdx) LoadPartition(partition int32, defs []schema.MetricDefinition, now time.Time) []schema.MetricDefinition { +func (b *BigtableIdx) LoadPartition(partition int32, defs []schema.MetricDefinition, now time.Time, orgFilter int) []schema.MetricDefinition { ctx := context.Background() rr := bigtable.PrefixRange(fmt.Sprintf("%d_", partition)) defsByNames := make(map[string][]schema.MetricDefinition) @@ -296,6 +296,9 @@ func (b *BigtableIdx) LoadPartition(partition int32, defs []schema.MetricDefinit if marshalErr != nil { return false } + if orgFilter != -1 && def.OrgId != uint32(orgFilter) { + return true + } log.Debugf("bigtable-idx: found def %+v", def) nameWithTags := def.NameWithTags() defsByNames[nameWithTags] = append(defsByNames[nameWithTags], def)