From 127c61a55fc29c2eacfa401fec00350702cc59db Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Tue, 22 Jan 2013 19:32:56 +0100 Subject: [PATCH] Add command-line arguments for config file and storage path. --- main.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index dc7e178df..94f3c0cd6 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ package main import ( "code.google.com/p/gorest" - "fmt" + "flag" "github.com/matttproud/golang_instrumentation" "github.com/matttproud/prometheus/api" "github.com/matttproud/prometheus/config" @@ -29,15 +29,20 @@ import ( "os/signal" ) +// Commandline flags. +var ( + configFile = flag.String("configFile", "prometheus.conf", "Prometheus configuration file name.") + metricsStoragePath = flag.String("metricsStoragePath", "/tmp/metrics", "Base path for metrics storage.") +) + func main() { - configFile := "prometheus.conf" - conf, err := config.LoadFromFile(configFile) + flag.Parse() + conf, err := config.LoadFromFile(*configFile) if err != nil { - log.Fatal(fmt.Sprintf("Error loading configuration from %s: %v", - configFile, err)) + log.Fatalf("Error loading configuration from %s: %v", configFile, err) } - persistence, err := leveldb.NewLevelDBMetricPersistence("/tmp/metrics") + persistence, err := leveldb.NewLevelDBMetricPersistence(*metricsStoragePath) if err != nil { log.Print(err) os.Exit(1) @@ -64,7 +69,7 @@ func main() { ruleManager := rules.NewRuleManager(ruleResults, conf.Global.EvaluationInterval) err = ruleManager.AddRulesFromConfig(conf) if err != nil { - log.Fatal(fmt.Sprintf("Error loading rule files: %v", err)) + log.Fatalf("Error loading rule files: %v", err) } go func() {