2017-09-17 01:26:19 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/database"
|
|
|
|
"github.com/FreifunkBremen/yanic/database/all"
|
|
|
|
"github.com/FreifunkBremen/yanic/rrd"
|
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
// importCmd represents the import command
|
|
|
|
var importCmd = &cobra.Command{
|
2017-11-21 14:12:06 +00:00
|
|
|
Use: "import <file.rrd> <site>",
|
2017-09-17 01:26:19 +00:00
|
|
|
Short: "Imports global statistics from the given RRD files, requires InfluxDB",
|
2017-11-21 14:12:06 +00:00
|
|
|
Example: "yanic import --config /etc/yanic.toml olddata.rrd global",
|
|
|
|
Args: cobra.ExactArgs(2),
|
2017-09-17 01:26:19 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
path := args[0]
|
2017-11-21 14:12:06 +00:00
|
|
|
site := args[1]
|
2017-09-17 01:26:19 +00:00
|
|
|
config := loadConfig()
|
|
|
|
|
|
|
|
connections, err := all.Connect(config.Database.Connection)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
database.Start(connections, config)
|
|
|
|
defer database.Close(connections)
|
|
|
|
|
|
|
|
log.Println("importing RRD from", path)
|
|
|
|
|
|
|
|
for ds := range rrd.Read(path) {
|
|
|
|
connections.InsertGlobals(
|
|
|
|
&runtime.GlobalStats{
|
|
|
|
Nodes: uint32(ds.Nodes),
|
|
|
|
Clients: uint32(ds.Clients),
|
|
|
|
},
|
|
|
|
ds.Time,
|
2017-11-21 14:12:06 +00:00
|
|
|
site,
|
2017-09-17 01:26:19 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(importCmd)
|
|
|
|
importCmd.Flags().StringVarP(&configPath, "config", "c", "config.toml", "Path to configuration file")
|
|
|
|
}
|