mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Replace columnize by stdlib tabwriter
This commit is contained in:
parent
e190c7c78d
commit
9945a67bff
|
@ -44,7 +44,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")
|
||||||
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:])) {
|
switch kingpin.MustParse(cli.Parse(os.Args[1:])) {
|
||||||
|
@ -60,7 +60,7 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exitWithError(err)
|
exitWithError(err)
|
||||||
}
|
}
|
||||||
fmt.Println(db.PrintBlocks())
|
db.PrintBlocks()
|
||||||
}
|
}
|
||||||
flag.CommandLine.Set("log.level", "debug")
|
flag.CommandLine.Set("log.level", "debug")
|
||||||
}
|
}
|
||||||
|
|
15
db.go
15
db.go
|
@ -38,7 +38,6 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/tsdb/chunks"
|
"github.com/prometheus/tsdb/chunks"
|
||||||
"github.com/prometheus/tsdb/labels"
|
"github.com/prometheus/tsdb/labels"
|
||||||
"github.com/ryanuber/columnize"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultOptions used for the DB. They are sane for setups using
|
// DefaultOptions used for the DB. They are sane for setups using
|
||||||
|
@ -229,23 +228,25 @@ func (db *DB) Dir() string {
|
||||||
return db.dir
|
return db.dir
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) PrintBlocks() string {
|
func (db *DB) PrintBlocks() {
|
||||||
db.mtx.RLock()
|
db.mtx.RLock()
|
||||||
defer db.mtx.RUnlock()
|
defer db.mtx.RUnlock()
|
||||||
|
|
||||||
var output []string
|
tw := GetNewTabWriter(os.Stdout)
|
||||||
output = append(output, "BLOCK ULID | MIN TIME | MAX TIME | NUM SAMPLES | NUM CHUNKS | NUM SERIES")
|
defer tw.Flush()
|
||||||
|
|
||||||
|
fmt.Fprintln(tw, "BLOCK ULID\tMIN TIME\tMAX TIME\tNUM SAMPLES\tNUM CHUNKS\tNUM SERIES")
|
||||||
for _, b := range db.blocks {
|
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().ULID,
|
||||||
b.Meta().MinTime,
|
b.Meta().MinTime,
|
||||||
b.Meta().MaxTime,
|
b.Meta().MaxTime,
|
||||||
b.Meta().Stats.NumSamples,
|
b.Meta().Stats.NumSamples,
|
||||||
b.Meta().Stats.NumChunks,
|
b.Meta().Stats.NumChunks,
|
||||||
b.Meta().Stats.NumSeries,
|
b.Meta().Stats.NumSeries,
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
return columnize.SimpleFormat(output)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) run() {
|
func (db *DB) run() {
|
||||||
|
|
18
tabwriter.go
Normal file
18
tabwriter.go
Normal file
|
@ -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…
Reference in a new issue