mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 07:34:04 -08:00
Merge pull request #142 from krasi-georgiev/107-swap-cobra-with-kingpin
replaced cobra with kingpin for the tsdb cli tool
This commit is contained in:
commit
e45bb1d328
3
cmd/tsdb/README.md
Normal file
3
cmd/tsdb/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
TODO:
|
||||
- [ ] add tabular output
|
||||
- [ ] break commands in separate files
|
|
@ -18,8 +18,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -33,39 +31,34 @@ import (
|
|||
"github.com/prometheus/prometheus/pkg/textparse"
|
||||
"github.com/prometheus/tsdb"
|
||||
"github.com/prometheus/tsdb/labels"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Start HTTP server for pprof endpoint.
|
||||
go http.ListenAndServe(":9999", nil)
|
||||
|
||||
root := &cobra.Command{
|
||||
Use: "tsdb",
|
||||
Short: "CLI tool for tsdb",
|
||||
}
|
||||
|
||||
root.AddCommand(
|
||||
NewBenchCommand(),
|
||||
var (
|
||||
cli = kingpin.New(filepath.Base(os.Args[0]), "CLI tool for tsdb")
|
||||
benchCmd = cli.Command("bench", "run benchmarks")
|
||||
benchWriteCmd = benchCmd.Command("write", "run a write performance benchmark")
|
||||
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()
|
||||
)
|
||||
|
||||
flag.CommandLine.Set("log.level", "debug")
|
||||
|
||||
root.Execute()
|
||||
}
|
||||
|
||||
func NewBenchCommand() *cobra.Command {
|
||||
c := &cobra.Command{
|
||||
Use: "bench",
|
||||
Short: "run benchmarks",
|
||||
switch kingpin.MustParse(cli.Parse(os.Args[1:])) {
|
||||
case benchWriteCmd.FullCommand():
|
||||
wb := &writeBenchmark{
|
||||
outPath: *benchWriteOutPath,
|
||||
numMetrics: *benchWriteNumMetrics,
|
||||
samplesFile: *benchSamplesFile,
|
||||
}
|
||||
c.AddCommand(NewBenchWriteCommand())
|
||||
|
||||
return c
|
||||
wb.run()
|
||||
}
|
||||
flag.CommandLine.Set("log.level", "debug")
|
||||
}
|
||||
|
||||
type writeBenchmark struct {
|
||||
outPath string
|
||||
samplesFile string
|
||||
cleanup bool
|
||||
numMetrics int
|
||||
|
||||
|
@ -77,22 +70,7 @@ type writeBenchmark struct {
|
|||
mtxprof *os.File
|
||||
}
|
||||
|
||||
func NewBenchWriteCommand() *cobra.Command {
|
||||
var wb writeBenchmark
|
||||
c := &cobra.Command{
|
||||
Use: "write <file>",
|
||||
Short: "run a write performance benchmark",
|
||||
Run: wb.run,
|
||||
}
|
||||
c.PersistentFlags().StringVar(&wb.outPath, "out", "benchout/", "set the output path")
|
||||
c.PersistentFlags().IntVar(&wb.numMetrics, "metrics", 10000, "number of metrics to read")
|
||||
return c
|
||||
}
|
||||
|
||||
func (b *writeBenchmark) run(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
exitWithError(fmt.Errorf("missing file argument"))
|
||||
}
|
||||
func (b *writeBenchmark) run() {
|
||||
if b.outPath == "" {
|
||||
dir, err := ioutil.TempDir("", "tsdb_bench")
|
||||
if err != nil {
|
||||
|
@ -123,7 +101,7 @@ func (b *writeBenchmark) run(cmd *cobra.Command, args []string) {
|
|||
var metrics []labels.Labels
|
||||
|
||||
measureTime("readData", func() {
|
||||
f, err := os.Open(args[0])
|
||||
f, err := os.Open(b.samplesFile)
|
||||
if err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue