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

Commit

Permalink
support controlling archive to read from
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed Nov 23, 2018
1 parent 7c15bea commit d174fbe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
13 changes: 11 additions & 2 deletions cmd/mt-store-cat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
printTs = flag.Bool("print-ts", false, "print time stamps instead of formatted dates. only for points and point-summary format")
groupTTL = flag.String("groupTTL", "d", "group chunks in TTL buckets: s (second. means unbucketed), m (minute), h (hour) or d (day). only for chunk-summary format")
timeZoneStr = flag.String("time-zone", "local", "time-zone to use for interpreting from/to when needed. (check your config)")
archiveStr = flag.String("archive", "", "archive to fetch for given metric. e.g. 'sum_1800'")
verbose bool

printTime func(ts uint32) string
Expand Down Expand Up @@ -196,6 +197,14 @@ func main() {
log.Fatalf("failed to read tables from cassandra. %s", err.Error())
}

var archive schema.Archive
if *archiveStr != "" {
archive, err = schema.ArchiveFromString(*archiveStr)
if err != nil {
log.Fatalf("could not parse archive %q: %s", *archiveStr, err)
}
}

// set up is done, now actually execute the business logic

// handle "tables"
Expand Down Expand Up @@ -243,7 +252,7 @@ func main() {
// chunk-summary doesn't need an explicit listing. it knows if metrics is empty, to query all
// but the other two do need an explicit listing.
if format == "points" || format == "point-summary" {
metrics, err = getMetrics(store, "", "", "")
metrics, err = getMetrics(store, "", "", "", archive)
if err != nil {
log.Errorf("cassandra query error. %s", err.Error())
return
Expand All @@ -263,7 +272,7 @@ func main() {
if verbose {
fmt.Println("# Looking for these metrics:")
}
metrics, err = getMetrics(store, prefix, substr, glob)
metrics, err = getMetrics(store, prefix, substr, glob, archive)
if err != nil {
log.Errorf("cassandra query error. %s", err.Error())
return
Expand Down
5 changes: 3 additions & 2 deletions cmd/mt-store-cat/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func match(prefix, substr, glob string, metric Metric) bool {
}

// getMetrics lists all metrics from the store matching the given condition.
func getMetrics(store *cassandra.CassandraStore, prefix, substr, glob string) ([]Metric, error) {
func getMetrics(store *cassandra.CassandraStore, prefix, substr, glob string, archive schema.Archive) ([]Metric, error) {
var metrics []Metric
iter := store.Session.Query("select id, name from metric_idx").Iter()
var m Metric
Expand All @@ -62,7 +62,8 @@ func getMetrics(store *cassandra.CassandraStore, prefix, substr, glob string) ([
panic(err)
}
m.AMKey = schema.AMKey{
MKey: mkey,
MKey: mkey,
Archive: archive,
}
metrics = append(metrics, m)
}
Expand Down
2 changes: 2 additions & 0 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ mt-store-cat -cassandra-keyspace metrictank -from='-1month' '*' 'prefix:fake' po
mt-store-cat -cassandra-keyspace metrictank '*' 'prefix:fake' chunk-summary
mt-store-cat -groupTTL h -cassandra-keyspace metrictank 'metric_512' '1.37cf8e3731ee4c79063c1d55280d1bbe' chunk-summary
Flags:
-archive string
archive to fetch for given metric. e.g. 'sum_1800'
-cassandra-addrs string
cassandra host (may be given multiple times as comma-separated list) (default "localhost")
-cassandra-auth
Expand Down

0 comments on commit d174fbe

Please sign in to comment.