Browse Source

Replace columnize by stdlib tabwriter

pull/5805/head
Bas Harenslak 7 years ago
parent
commit
9945a67bff
  1. 4
      cmd/tsdb/main.go
  2. 15
      db.go
  3. 18
      tabwriter.go

4
cmd/tsdb/main.go

@ -44,7 +44,7 @@ func main() {
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()
listCmd = cli.Command("ls", "list db blocks")
listPath = listCmd.Arg("db path", "database path").Default("benchout/storage").String()
listPath = listCmd.Arg("db path", "database path (default is benchout/storage)").Default("benchout/storage").String()
)
switch kingpin.MustParse(cli.Parse(os.Args[1:])) {
@ -60,7 +60,7 @@ func main() {
if err != nil {
exitWithError(err)
}
fmt.Println(db.PrintBlocks())
db.PrintBlocks()
}
flag.CommandLine.Set("log.level", "debug")
}

15
db.go

@ -38,7 +38,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/tsdb/chunks"
"github.com/prometheus/tsdb/labels"
"github.com/ryanuber/columnize"
)
// DefaultOptions used for the DB. They are sane for setups using
@ -229,23 +228,25 @@ func (db *DB) Dir() string {
return db.dir
}
func (db *DB) PrintBlocks() string {
func (db *DB) PrintBlocks() {
db.mtx.RLock()
defer db.mtx.RUnlock()
var output []string
output = append(output, "BLOCK ULID | MIN TIME | MAX TIME | NUM SAMPLES | NUM CHUNKS | NUM SERIES")
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 {
output = append(output, fmt.Sprintf("%v | %v | %v | %v | %v | %v",
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,
))
)
}
return columnize.SimpleFormat(output)
}
func (db *DB) run() {

18
tabwriter.go

@ -0,0 +1,18 @@
package tsdb
import (
"io"
"text/tabwriter"
)
const (
minwidth = 0
tabwidth = 0
padding = 2
padchar = ' '
flags = 0
)
func GetNewTabWriter(output io.Writer) *tabwriter.Writer {
return tabwriter.NewWriter(output, minwidth, tabwidth, padding, padchar, flags)
}
Loading…
Cancel
Save