mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44:05 -08:00
Add list blocks command to CLI
This commit is contained in:
parent
c521ac495f
commit
e190c7c78d
|
@ -43,6 +43,8 @@ func main() {
|
|||
benchWriteOutPath = benchWriteCmd.Flag("out", "set the output path").Default("benchout/").String()
|
||||
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()
|
||||
)
|
||||
|
||||
switch kingpin.MustParse(cli.Parse(os.Args[1:])) {
|
||||
|
@ -53,6 +55,12 @@ func main() {
|
|||
samplesFile: *benchSamplesFile,
|
||||
}
|
||||
wb.run()
|
||||
case listCmd.FullCommand():
|
||||
db, err := tsdb.Open(*listPath, nil, nil, nil)
|
||||
if err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
fmt.Println(db.PrintBlocks())
|
||||
}
|
||||
flag.CommandLine.Set("log.level", "debug")
|
||||
}
|
||||
|
|
20
db.go
20
db.go
|
@ -38,6 +38,7 @@ 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
|
||||
|
@ -228,6 +229,25 @@ func (db *DB) Dir() string {
|
|||
return db.dir
|
||||
}
|
||||
|
||||
func (db *DB) PrintBlocks() string {
|
||||
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")
|
||||
for _, b := range db.blocks {
|
||||
output = append(output, fmt.Sprintf("%v | %v | %v | %v | %v | %v",
|
||||
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() {
|
||||
defer close(db.donec)
|
||||
|
||||
|
|
Loading…
Reference in a new issue