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

Commit

Permalink
support metric matching + add new mt-aggs-explain tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed Apr 7, 2017
1 parent bdd6549 commit 1f7160b
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
82 changes: 82 additions & 0 deletions cmd/mt-aggs-explain/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package main

import (
"flag"
"fmt"
"os"
"runtime"

log "github.com/Sirupsen/logrus"
"github.com/raintank/metrictank/conf"
"github.com/raintank/metrictank/consolidation"
)

var (
GitHash = "(none)"
showVersion = flag.Bool("version", false, "print version string")
metric = flag.String("metric", "", "specify a metric name to see which aggregation rule it matches")
)

func main() {
flag.Usage = func() {
fmt.Println("mt-aggs-explain")
fmt.Println()
fmt.Println("Usage:")
fmt.Println()
fmt.Printf(" mt-aggs-explain [flags] [config-file]\n")
fmt.Println(" (config file defaults to /etc/metrictank/storage-aggregations.conf)")
fmt.Println()
fmt.Println("Flags:")
flag.PrintDefaults()
}
flag.Parse()

if *showVersion {
fmt.Printf("mt-aggs-explain (built with %s, git hash %s)\n", runtime.Version(), GitHash)
return
}
if flag.NArg() > 1 {
flag.Usage()
os.Exit(-1)
}
aggsFile := "/etc/metrictank/storage-aggregations.conf"
if flag.NArg() == 1 {
aggsFile = flag.Arg(0)
}
aggs, err := conf.ReadAggregations(aggsFile)
if err != nil {
log.Fatalf("can't read aggregations file %q: %s", aggsFile, err.Error())
}

if *metric != "" {
aggI, agg := aggs.Match(*metric)
fmt.Printf("metric %q gets aggI %d\n", *metric, aggI)
show(agg)
fmt.Println()
fmt.Println()
}

fmt.Println("### all definitions ###")

for _, agg := range aggs.Data {
show(agg)
fmt.Println()
}
fmt.Println("default:")
fmt.Println(aggs.DefaultAggregation)
}

func show(agg conf.Aggregation) {
fmt.Println("#", agg.Name)
fmt.Printf("pattern: %10s\n", agg.Pattern)
fmt.Printf("priority: %10f\n", agg.XFilesFactor)
fmt.Printf("methods:\n")
for i, method := range agg.AggregationMethod {
consolidator := consolidation.Consolidator(method)
if i == 0 {
fmt.Println(" ", consolidator.String(), "<-- used for rollup reads and normalization (not: runtime consolidation)")
} else {
fmt.Println(" ", consolidator.String())
}
}
}
9 changes: 9 additions & 0 deletions cmd/mt-schemas-explain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var (
GitHash = "(none)"
showVersion = flag.Bool("version", false, "print version string")
windowFactor = flag.Int("window-factor", 20, "size of compaction window relative to TTL")
metric = flag.String("metric", "", "specify a metric name to see which schema it matches")
interval = flag.Int("int", 0, "specify an interval to apply interval-based matching in addition to metric matching (e.g. to simulate kafka-mdm input)")
)

func main() {
Expand Down Expand Up @@ -49,6 +51,13 @@ func main() {
log.Fatalf("can't read schemas file %q: %s", schemasFile, err.Error())
}

if *metric != "" {
schemaI, s := schemas.Match(*metric, *interval)
fmt.Printf("metric %q with interval %d gets schemaI %d\n", *metric, *interval, schemaI)
fmt.Printf("## [%q] pattern=%q prio=%d retentions=%v\n", s.Name, s.Pattern, s.Priority, s.Retentions)
fmt.Println()
}

for _, schema := range schemas.List() {
fmt.Println("#", schema.Name)
fmt.Printf("pattern: %10s\n", schema.Pattern)
Expand Down
22 changes: 22 additions & 0 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ This file is generated by [tools-to-doc](https://github.com/raintank/metrictank/
---


## mt-aggs-explain

```
mt-aggs-explain
Usage:
mt-aggs-explain [flags] [config-file]
(config file defaults to /etc/metrictank/storage-aggregations.conf)
Flags:
-metric string
specify a metric name to see which aggregation rule it matches
-version
print version string
```


## mt-index-cat

```
Expand Down Expand Up @@ -243,6 +261,10 @@ Usage:
(config file defaults to /etc/metrictank/storage-schemas.conf)
Flags:
-int int
specify an interval to apply interval-based matching in addition to metric matching (e.g. to simulate kafka-mdm input)
-metric string
specify a metric name to see which schema it matches
-version
print version string
-window-factor int
Expand Down

0 comments on commit 1f7160b

Please sign in to comment.