Move printing db.blocks to main.go

This commit is contained in:
Bas Harenslak 2017-10-02 22:48:47 +02:00
parent 9945a67bff
commit a41dad30fb
2 changed files with 19 additions and 22 deletions

View File

@ -60,7 +60,7 @@ func main() {
if err != nil {
exitWithError(err)
}
db.PrintBlocks()
printBlocks(db.Blocks())
}
flag.CommandLine.Set("log.level", "debug")
}
@ -331,3 +331,21 @@ func exitWithError(err error) {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
func printBlocks(blocks []tsdb.DiskBlock) {
tw := tsdb.GetNewTabWriter(os.Stdout)
defer tw.Flush()
fmt.Fprintln(tw, "BLOCK ULID\tMIN TIME\tMAX TIME\tNUM SAMPLES\tNUM CHUNKS\tNUM SERIES")
for _, b := range blocks {
fmt.Fprintf(tw,
"%v\t%v\t%v\t%v\t%v\t%v\n",
b.Meta().ULID,
b.Meta().MinTime,
b.Meta().MaxTime,
b.Meta().Stats.NumSamples,
b.Meta().Stats.NumChunks,
b.Meta().Stats.NumSeries,
)
}
}

21
db.go
View File

@ -228,27 +228,6 @@ func (db *DB) Dir() string {
return db.dir
}
func (db *DB) PrintBlocks() {
db.mtx.RLock()
defer db.mtx.RUnlock()
tw := GetNewTabWriter(os.Stdout)
defer tw.Flush()
fmt.Fprintln(tw, "BLOCK ULID\tMIN TIME\tMAX TIME\tNUM SAMPLES\tNUM CHUNKS\tNUM SERIES")
for _, b := range db.blocks {
fmt.Fprintf(tw,
"%v\t%v\t%v\t%v\t%v\t%v\n",
b.Meta().ULID,
b.Meta().MinTime,
b.Meta().MaxTime,
b.Meta().Stats.NumSamples,
b.Meta().Stats.NumChunks,
b.Meta().Stats.NumSeries,
)
}
}
func (db *DB) run() {
defer close(db.donec)