2021-01-31 23:10:16 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"strings"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/influx"
|
2021-04-08 19:58:06 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/opentsdb"
|
2021-01-31 23:10:16 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/prometheus"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/vm"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
|
2021-01-31 23:31:25 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-01-31 23:10:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-01-03 19:12:01 +00:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
importer *vm.Importer
|
|
|
|
)
|
|
|
|
|
2021-01-31 23:10:16 +00:00
|
|
|
start := time.Now()
|
|
|
|
app := &cli.App{
|
|
|
|
Name: "vmctl",
|
2021-04-20 08:42:17 +00:00
|
|
|
Usage: "VictoriaMetrics command-line tool",
|
2021-01-31 23:10:16 +00:00
|
|
|
Version: buildinfo.Version,
|
|
|
|
Commands: []*cli.Command{
|
2021-04-08 19:58:06 +00:00
|
|
|
{
|
|
|
|
Name: "opentsdb",
|
|
|
|
Usage: "Migrate timeseries from OpenTSDB",
|
|
|
|
Flags: mergeFlags(globalFlags, otsdbFlags, vmFlags),
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
fmt.Println("OpenTSDB import mode")
|
|
|
|
|
|
|
|
oCfg := opentsdb.Config{
|
|
|
|
Addr: c.String(otsdbAddr),
|
|
|
|
Limit: c.Int(otsdbQueryLimit),
|
|
|
|
Offset: c.Int64(otsdbOffsetDays),
|
|
|
|
HardTS: c.Int64(otsdbHardTSStart),
|
|
|
|
Retentions: c.StringSlice(otsdbRetentions),
|
|
|
|
Filters: c.StringSlice(otsdbFilters),
|
|
|
|
Normalize: c.Bool(otsdbNormalize),
|
|
|
|
MsecsTime: c.Bool(otsdbMsecsTime),
|
|
|
|
}
|
|
|
|
otsdbClient, err := opentsdb.NewClient(oCfg)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create opentsdb client: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
vmCfg := initConfigVM(c)
|
|
|
|
importer, err := vm.NewImporter(vmCfg)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create VM importer: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
otsdbProcessor := newOtsdbProcessor(otsdbClient, importer, c.Int(otsdbConcurrency))
|
2022-01-03 19:12:01 +00:00
|
|
|
return otsdbProcessor.run(c.Bool(globalSilent), c.Bool(globalVerbose))
|
2021-04-08 19:58:06 +00:00
|
|
|
},
|
|
|
|
},
|
2021-01-31 23:10:16 +00:00
|
|
|
{
|
|
|
|
Name: "influx",
|
|
|
|
Usage: "Migrate timeseries from InfluxDB",
|
|
|
|
Flags: mergeFlags(globalFlags, influxFlags, vmFlags),
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
fmt.Println("InfluxDB import mode")
|
|
|
|
|
|
|
|
iCfg := influx.Config{
|
|
|
|
Addr: c.String(influxAddr),
|
|
|
|
Username: c.String(influxUser),
|
|
|
|
Password: c.String(influxPassword),
|
|
|
|
Database: c.String(influxDB),
|
|
|
|
Retention: c.String(influxRetention),
|
|
|
|
Filter: influx.Filter{
|
|
|
|
Series: c.String(influxFilterSeries),
|
|
|
|
TimeStart: c.String(influxFilterTimeStart),
|
|
|
|
TimeEnd: c.String(influxFilterTimeEnd),
|
|
|
|
},
|
|
|
|
ChunkSize: c.Int(influxChunkSize),
|
|
|
|
}
|
|
|
|
influxClient, err := influx.NewClient(iCfg)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create influx client: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
vmCfg := initConfigVM(c)
|
2022-01-03 19:12:01 +00:00
|
|
|
importer, err = vm.NewImporter(vmCfg)
|
2021-01-31 23:10:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create VM importer: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
processor := newInfluxProcessor(influxClient, importer,
|
|
|
|
c.Int(influxConcurrency), c.String(influxMeasurementFieldSeparator))
|
2022-01-03 19:12:01 +00:00
|
|
|
return processor.run(c.Bool(globalSilent), c.Bool(globalVerbose))
|
2021-01-31 23:10:16 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "prometheus",
|
|
|
|
Usage: "Migrate timeseries from Prometheus",
|
|
|
|
Flags: mergeFlags(globalFlags, promFlags, vmFlags),
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
fmt.Println("Prometheus import mode")
|
|
|
|
|
|
|
|
vmCfg := initConfigVM(c)
|
2022-01-03 19:12:01 +00:00
|
|
|
importer, err = vm.NewImporter(vmCfg)
|
2021-01-31 23:10:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create VM importer: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
promCfg := prometheus.Config{
|
|
|
|
Snapshot: c.String(promSnapshot),
|
|
|
|
Filter: prometheus.Filter{
|
|
|
|
TimeMin: c.String(promFilterTimeStart),
|
|
|
|
TimeMax: c.String(promFilterTimeEnd),
|
|
|
|
Label: c.String(promFilterLabel),
|
|
|
|
LabelValue: c.String(promFilterLabelValue),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
cl, err := prometheus.NewClient(promCfg)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create prometheus client: %s", err)
|
|
|
|
}
|
|
|
|
pp := prometheusProcessor{
|
|
|
|
cl: cl,
|
|
|
|
im: importer,
|
|
|
|
cc: c.Int(promConcurrency),
|
|
|
|
}
|
2022-01-03 19:12:01 +00:00
|
|
|
return pp.run(c.Bool(globalSilent), c.Bool(globalVerbose))
|
2021-01-31 23:10:16 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "vm-native",
|
|
|
|
Usage: "Migrate time series between VictoriaMetrics installations via native binary format",
|
|
|
|
Flags: vmNativeFlags,
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
fmt.Println("VictoriaMetrics Native import mode")
|
|
|
|
|
|
|
|
if c.String(vmNativeFilterMatch) == "" {
|
|
|
|
return fmt.Errorf("flag %q can't be empty", vmNativeFilterMatch)
|
|
|
|
}
|
|
|
|
|
|
|
|
p := vmNativeProcessor{
|
|
|
|
filter: filter{
|
|
|
|
match: c.String(vmNativeFilterMatch),
|
|
|
|
timeStart: c.String(vmNativeFilterTimeStart),
|
|
|
|
timeEnd: c.String(vmNativeFilterTimeEnd),
|
|
|
|
},
|
|
|
|
src: &vmNativeClient{
|
|
|
|
addr: strings.Trim(c.String(vmNativeSrcAddr), "/"),
|
|
|
|
user: c.String(vmNativeSrcUser),
|
|
|
|
password: c.String(vmNativeSrcPassword),
|
|
|
|
},
|
|
|
|
dst: &vmNativeClient{
|
|
|
|
addr: strings.Trim(c.String(vmNativeDstAddr), "/"),
|
|
|
|
user: c.String(vmNativeDstUser),
|
|
|
|
password: c.String(vmNativeDstPassword),
|
|
|
|
extraLabels: c.StringSlice(vmExtraLabel),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return p.run()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
go func() {
|
|
|
|
<-c
|
|
|
|
fmt.Println("\r- Execution cancelled")
|
2022-01-03 19:12:01 +00:00
|
|
|
if importer != nil {
|
|
|
|
importer.Close()
|
|
|
|
}
|
2021-01-31 23:10:16 +00:00
|
|
|
}()
|
|
|
|
|
2022-01-03 19:12:01 +00:00
|
|
|
err = app.Run(os.Args)
|
2021-01-31 23:10:16 +00:00
|
|
|
if err != nil {
|
2022-01-03 19:12:01 +00:00
|
|
|
log.Println(err)
|
2021-01-31 23:10:16 +00:00
|
|
|
}
|
|
|
|
log.Printf("Total time: %v", time.Since(start))
|
|
|
|
}
|
|
|
|
|
|
|
|
func initConfigVM(c *cli.Context) vm.Config {
|
|
|
|
return vm.Config{
|
|
|
|
Addr: c.String(vmAddr),
|
|
|
|
User: c.String(vmUser),
|
|
|
|
Password: c.String(vmPassword),
|
|
|
|
Concurrency: uint8(c.Int(vmConcurrency)),
|
|
|
|
Compress: c.Bool(vmCompress),
|
|
|
|
AccountID: c.String(vmAccountID),
|
|
|
|
BatchSize: c.Int(vmBatchSize),
|
|
|
|
SignificantFigures: c.Int(vmSignificantFigures),
|
2021-02-01 12:27:05 +00:00
|
|
|
RoundDigits: c.Int(vmRoundDigits),
|
2021-01-31 23:10:16 +00:00
|
|
|
ExtraLabels: c.StringSlice(vmExtraLabel),
|
|
|
|
}
|
|
|
|
}
|