diff --git a/README.md b/README.md index 9eda82a..99e3d56 100644 --- a/README.md +++ b/README.md @@ -34,5 +34,5 @@ tsdb mock tsdb run [] Run the tsdb server. example: - timelite tsdb run --config-path="./storage/conf" --storage-path="./storage/tsdb" --host="0.0.0.0:9090" + timelite tsdb run --config-file="config.json" --storage-path="./storage/tsdb" --host="0.0.0.0:9090" ``` diff --git a/conf/config.go b/conf/config.go index ad1d60e..becb789 100644 --- a/conf/config.go +++ b/conf/config.go @@ -81,11 +81,11 @@ func GetPromConfig(host string) *config.Config { return promConf } -func InitConfig(configPath, storagePath, host string) error { - if configPath != "" { - if _, err := os.Stat(configPath); !os.IsNotExist(err) { +func InitConfig(configFile, storagePath, host string) error { + if configFile != "" { + if _, err := os.Stat(configFile); !os.IsNotExist(err) { // read config from file - err := GetConfig(configPath) + err := GetConfig(configFile) if err != nil { // if file not exist, create it return err @@ -93,7 +93,7 @@ func InitConfig(configPath, storagePath, host string) error { } } - dashboardPath := filepath.Join(filepath.Dir(configPath), "dashboards") + dashboardPath := filepath.Join(filepath.Dir(configFile), "dashboards") logPath := filepath.Join(storagePath, "log") promConf := GetPromConfig(host) @@ -105,13 +105,13 @@ func InitConfig(configPath, storagePath, host string) error { PromConfig: promConf, Host: host, } - return SaveConfig(configPath) + return SaveConfig(configFile) } -func SaveConfig(configPath string) error { - if _, err := os.Stat(filepath.Dir(configPath)); os.IsNotExist(err) { - err = os.MkdirAll(filepath.Dir(configPath), 0755) +func SaveConfig(configFile string) error { + if _, err := os.Stat(filepath.Dir(configFile)); os.IsNotExist(err) { + err = os.MkdirAll(filepath.Dir(configFile), 0755) if err != nil { return fmt.Errorf("failed to mkdir config dir: %v", err) } @@ -120,5 +120,5 @@ func SaveConfig(configPath string) error { if err != nil { return err } - return os.WriteFile(configPath, bytes, 0644) + return os.WriteFile(configFile, bytes, 0644) } diff --git a/main.go b/main.go index 8cea939..5abf603 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ func main() { storagePath := runTSDBCmd.Flag("storage-path", "The path to store the tsdb data.").Default("./storage/tsdb"). String() - configPath := runTSDBCmd.Flag("config-path", "The path to store the tsdb data.").Default("./storage/conf").String() + configFile := runTSDBCmd.Flag("config-file", "The config file path.").Default("./storage/conf").String() parseCmd := kingpin.MustParse(app.Parse(os.Args[1:])) @@ -50,9 +50,9 @@ func main() { case tsdbMockCmd.FullCommand(): util.PromTestServer() case runTSDBCmd.FullCommand(): - prepareTSDBEnv(*configPath, *storagePath, *host) + prepareTSDBEnv(*configFile, *storagePath, *host) // save config - conf.SaveConfig(filepath.Join(*configPath, "config.json")) + conf.SaveConfig(*configFile) engine, err := engine.NewEngine(conf.DefaultConfig.StoragePath, conf.DefaultConfig.LogPath) if err != nil { @@ -65,8 +65,8 @@ func main() { } } -func prepareTSDBEnv(configPath, storagePath, host string) { - err := conf.InitConfig(configPath, storagePath, host) +func prepareTSDBEnv(configFile, storagePath, host string) { + err := conf.InitConfig(configFile, storagePath, host) if err != nil { panic(err) }