This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
main.go
94 lines (85 loc) · 2.98 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"flag"
"fmt"
"os"
"runtime"
"time"
"github.com/grafana/metrictank/conf"
"github.com/grafana/metrictank/logger"
"github.com/grafana/metrictank/store/cassandra"
log "github.com/sirupsen/logrus"
)
var (
version = "(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 init() {
formatter := &logger.TextFormatter{}
formatter.TimestampFormat = "2006-01-02 15:04:05.000"
log.SetFormatter(formatter)
log.SetLevel(log.InfoLevel)
}
func main() {
flag.Usage = func() {
fmt.Println("mt-schemas-explain")
fmt.Println()
fmt.Println("Usage:")
fmt.Println()
fmt.Printf(" mt-schemas-explain [flags] [config-file]\n")
fmt.Println(" (config file defaults to /etc/metrictank/storage-schemas.conf)")
fmt.Println()
fmt.Println("Flags:")
flag.PrintDefaults()
}
flag.Parse()
if *showVersion {
fmt.Printf("mt-schemas-explain (version: %s - runtime: %s)\n", version, runtime.Version())
return
}
if flag.NArg() > 1 {
flag.Usage()
os.Exit(-1)
}
schemasFile := "/etc/metrictank/storage-schemas.conf"
if flag.NArg() == 1 {
schemasFile = flag.Arg(0)
}
schemas, err := conf.ReadSchemas(schemasFile)
if err != nil {
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()
}
s, def := schemas.ListRaw()
for _, schema := range s {
display(schema)
}
fmt.Println("built-in default:")
display(def)
}
func display(schema conf.Schema) {
fmt.Println("#", schema.Name)
fmt.Printf("pattern: %10s\n", schema.Pattern)
fmt.Printf("priority: %10d\n", schema.Priority)
fmt.Printf("retentions:%10s %10s %10s %10s %10s %15s %10s\n", "interval", "retention", "chunkspan", "numchunks", "ready", "tablename", "windowsize")
for _, ret := range schema.Retentions.Rets {
retention := ret.MaxRetention()
table := cassandra.GetTable(uint32(retention), *windowFactor, cassandra.Table_name_format)
retStr := time.Duration(time.Duration(retention) * time.Second).String()
if retention%(3600*24) == 0 {
retStr = fmt.Sprintf("%dd", retention/3600/24)
}
chunkSpanStr := time.Duration(time.Duration(ret.ChunkSpan) * time.Second).String()
windowSizeStr := time.Duration(time.Duration(table.WindowSize) * time.Hour).String()
fmt.Printf(" %10d %10s %10s %10d %12d %15s %10s\n", ret.SecondsPerPoint, retStr, chunkSpanStr, ret.NumChunks, ret.Ready, table.Name, windowSizeStr)
}
fmt.Println()
}