Merge pull request #325 from FUSAKLA/fus-cmd-human-readable-timestamps

feat cmd/tsdb: added human readable print for timestamps on block list
This commit is contained in:
Goutham Veeramachaneni 2018-05-10 10:40:14 +02:00 committed by GitHub
commit f5a7e43384
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,6 +24,7 @@ import (
"runtime" "runtime"
"runtime/pprof" "runtime/pprof"
"sort" "sort"
"strconv"
"strings" "strings"
"sync" "sync"
"text/tabwriter" "text/tabwriter"
@ -45,6 +46,7 @@ func main() {
benchWriteNumMetrics = benchWriteCmd.Flag("metrics", "number of metrics to read").Default("10000").Int() benchWriteNumMetrics = benchWriteCmd.Flag("metrics", "number of metrics to read").Default("10000").Int()
benchSamplesFile = benchWriteCmd.Arg("file", "input file with samples data, default is (../../testdata/20k.series)").Default("../../testdata/20k.series").String() benchSamplesFile = benchWriteCmd.Arg("file", "input file with samples data, default is (../../testdata/20k.series)").Default("../../testdata/20k.series").String()
listCmd = cli.Command("ls", "list db blocks") listCmd = cli.Command("ls", "list db blocks")
listCmdHumanReadable = listCmd.Flag("human-readable", "print human readable values").Short('h').Bool()
listPath = listCmd.Arg("db path", "database path (default is benchout/storage)").Default("benchout/storage").String() listPath = listCmd.Arg("db path", "database path (default is benchout/storage)").Default("benchout/storage").String()
) )
@ -61,7 +63,7 @@ func main() {
if err != nil { if err != nil {
exitWithError(err) exitWithError(err)
} }
printBlocks(db.Blocks()) printBlocks(db.Blocks(), listCmdHumanReadable)
} }
flag.CommandLine.Set("log.level", "debug") flag.CommandLine.Set("log.level", "debug")
} }
@ -344,7 +346,7 @@ func exitWithError(err error) {
os.Exit(1) os.Exit(1)
} }
func printBlocks(blocks []*tsdb.Block) { func printBlocks(blocks []*tsdb.Block, humanReadable *bool) {
tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
defer tw.Flush() defer tw.Flush()
@ -355,11 +357,18 @@ func printBlocks(blocks []*tsdb.Block) {
fmt.Fprintf(tw, fmt.Fprintf(tw,
"%v\t%v\t%v\t%v\t%v\t%v\n", "%v\t%v\t%v\t%v\t%v\t%v\n",
meta.ULID, meta.ULID,
meta.MinTime, getFormatedTime(meta.MinTime, humanReadable),
meta.MaxTime, getFormatedTime(meta.MaxTime, humanReadable),
meta.Stats.NumSamples, meta.Stats.NumSamples,
meta.Stats.NumChunks, meta.Stats.NumChunks,
meta.Stats.NumSeries, meta.Stats.NumSeries,
) )
} }
} }
func getFormatedTime(timestamp int64, humanReadable *bool) string {
if *humanReadable {
return time.Unix(timestamp/1000, 0).String()
}
return strconv.FormatInt(timestamp, 10)
}