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

Commit f5a7e43

Browse files
authored
Merge pull request #325 from FUSAKLA/fus-cmd-human-readable-timestamps
feat cmd/tsdb: added human readable print for timestamps on block list
2 parents d298c5a + 30ca799 commit f5a7e43

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

cmd/tsdb/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"runtime"
2525
"runtime/pprof"
2626
"sort"
27+
"strconv"
2728
"strings"
2829
"sync"
2930
"text/tabwriter"
@@ -45,6 +46,7 @@ func main() {
4546
benchWriteNumMetrics = benchWriteCmd.Flag("metrics", "number of metrics to read").Default("10000").Int()
4647
benchSamplesFile = benchWriteCmd.Arg("file", "input file with samples data, default is (../../testdata/20k.series)").Default("../../testdata/20k.series").String()
4748
listCmd = cli.Command("ls", "list db blocks")
49+
listCmdHumanReadable = listCmd.Flag("human-readable", "print human readable values").Short('h').Bool()
4850
listPath = listCmd.Arg("db path", "database path (default is benchout/storage)").Default("benchout/storage").String()
4951
)
5052

@@ -61,7 +63,7 @@ func main() {
6163
if err != nil {
6264
exitWithError(err)
6365
}
64-
printBlocks(db.Blocks())
66+
printBlocks(db.Blocks(), listCmdHumanReadable)
6567
}
6668
flag.CommandLine.Set("log.level", "debug")
6769
}
@@ -344,7 +346,7 @@ func exitWithError(err error) {
344346
os.Exit(1)
345347
}
346348

347-
func printBlocks(blocks []*tsdb.Block) {
349+
func printBlocks(blocks []*tsdb.Block, humanReadable *bool) {
348350
tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
349351
defer tw.Flush()
350352

@@ -355,11 +357,18 @@ func printBlocks(blocks []*tsdb.Block) {
355357
fmt.Fprintf(tw,
356358
"%v\t%v\t%v\t%v\t%v\t%v\n",
357359
meta.ULID,
358-
meta.MinTime,
359-
meta.MaxTime,
360+
getFormatedTime(meta.MinTime, humanReadable),
361+
getFormatedTime(meta.MaxTime, humanReadable),
360362
meta.Stats.NumSamples,
361363
meta.Stats.NumChunks,
362364
meta.Stats.NumSeries,
363365
)
364366
}
365367
}
368+
369+
func getFormatedTime(timestamp int64, humanReadable *bool) string {
370+
if *humanReadable {
371+
return time.Unix(timestamp/1000, 0).String()
372+
}
373+
return strconv.FormatInt(timestamp, 10)
374+
}

0 commit comments

Comments
 (0)