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

Commit 19b9383

Browse files
committed
support controlling archive to read from
1 parent 7c15bea commit 19b9383

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

cmd/mt-store-cat/main.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var (
3737
printTs = flag.Bool("print-ts", false, "print time stamps instead of formatted dates. only for points and point-summary format")
3838
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")
3939
timeZoneStr = flag.String("time-zone", "local", "time-zone to use for interpreting from/to when needed. (check your config)")
40+
archiveStr = flag.String("archive", "", "archive to fetch for given metric. e.g. 'sum_1800'")
4041
verbose bool
4142

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

200+
var archive schema.Archive
201+
if *archiveStr != "" {
202+
archive, err = schema.ArchiveFromString(*archiveStr)
203+
if err != nil {
204+
log.Fatalf("could not parse archive %q: %s", err)
205+
}
206+
}
207+
199208
// set up is done, now actually execute the business logic
200209

201210
// handle "tables"
@@ -243,7 +252,7 @@ func main() {
243252
// chunk-summary doesn't need an explicit listing. it knows if metrics is empty, to query all
244253
// but the other two do need an explicit listing.
245254
if format == "points" || format == "point-summary" {
246-
metrics, err = getMetrics(store, "", "", "")
255+
metrics, err = getMetrics(store, "", "", "", archive)
247256
if err != nil {
248257
log.Errorf("cassandra query error. %s", err.Error())
249258
return
@@ -263,7 +272,7 @@ func main() {
263272
if verbose {
264273
fmt.Println("# Looking for these metrics:")
265274
}
266-
metrics, err = getMetrics(store, prefix, substr, glob)
275+
metrics, err = getMetrics(store, prefix, substr, glob, archive)
267276
if err != nil {
268277
log.Errorf("cassandra query error. %s", err.Error())
269278
return

cmd/mt-store-cat/metrics.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func match(prefix, substr, glob string, metric Metric) bool {
5050
}
5151

5252
// getMetrics lists all metrics from the store matching the given condition.
53-
func getMetrics(store *cassandra.CassandraStore, prefix, substr, glob string) ([]Metric, error) {
53+
func getMetrics(store *cassandra.CassandraStore, prefix, substr, glob string, archive schema.Archive) ([]Metric, error) {
5454
var metrics []Metric
5555
iter := store.Session.Query("select id, name from metric_idx").Iter()
5656
var m Metric
@@ -62,7 +62,8 @@ func getMetrics(store *cassandra.CassandraStore, prefix, substr, glob string) ([
6262
panic(err)
6363
}
6464
m.AMKey = schema.AMKey{
65-
MKey: mkey,
65+
MKey: mkey,
66+
Archive: archive,
6667
}
6768
metrics = append(metrics, m)
6869
}

docs/tools.md

+2
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ mt-store-cat -cassandra-keyspace metrictank -from='-1month' '*' 'prefix:fake' po
347347
mt-store-cat -cassandra-keyspace metrictank '*' 'prefix:fake' chunk-summary
348348
mt-store-cat -groupTTL h -cassandra-keyspace metrictank 'metric_512' '1.37cf8e3731ee4c79063c1d55280d1bbe' chunk-summary
349349
Flags:
350+
-archive string
351+
archive to fetch for given metric. e.g. 'sum_1800'
350352
-cassandra-addrs string
351353
cassandra host (may be given multiple times as comma-separated list) (default "localhost")
352354
-cassandra-auth

0 commit comments

Comments
 (0)