diff --git a/main.go b/main.go index 31c1309bf..34b65ebf9 100644 --- a/main.go +++ b/main.go @@ -15,12 +15,12 @@ package main import ( "flag" - "log" "os" "os/signal" "sync" "time" + "github.com/golang/glog" "github.com/prometheus/client_golang/extraction" "github.com/prometheus/prometheus/config" @@ -28,7 +28,6 @@ import ( "github.com/prometheus/prometheus/retrieval" "github.com/prometheus/prometheus/rules" "github.com/prometheus/prometheus/storage/metric" - "github.com/prometheus/prometheus/web" "github.com/prometheus/prometheus/web/api" ) @@ -91,7 +90,7 @@ func (p *prometheus) interruptHandler() { <-notifier - log.Println("Received SIGINT; Exiting Gracefully...") + glog.Warning("Received SIGINT; Exiting gracefully...") p.close() os.Exit(0) } @@ -169,15 +168,12 @@ func main() { conf, err := config.LoadFromFile(*configFile) if err != nil { - log.Fatalf("Error loading configuration from %s: %v", *configFile, err) + glog.Fatalf("Error loading configuration from %s: %v", *configFile, err) } ts, err := metric.NewTieredStorage(uint(*diskAppendQueueCapacity), 100, *arenaFlushInterval, *arenaTTL, *metricsStoragePath) if err != nil { - log.Fatalf("Error opening storage: %s", err) - } - if ts == nil { - log.Fatalln("Nil tiered storage.") + glog.Fatal("Error opening storage:", err) } unwrittenSamples := make(chan *extraction.Result, *samplesQueueCapacity) @@ -196,9 +192,8 @@ func main() { // Queue depth will need to be exposed ruleManager := rules.NewRuleManager(unwrittenSamples, notifications, conf.EvaluationInterval(), ts) - err = ruleManager.AddRulesFromConfig(conf) - if err != nil { - log.Fatalf("Error loading rule files: %v", err) + if err := ruleManager.AddRulesFromConfig(conf); err != nil { + glog.Fatal("Error loading rule files:", err) } go ruleManager.Run() @@ -273,56 +268,56 @@ func main() { go func() { for _ = range prometheus.headCompactionTimer.C { - log.Println("Starting head compaction...") + glog.Info("Starting head compaction...") err := prometheus.compact(*headAge, *headGroupSize) if err != nil { - log.Printf("could not compact due to %s", err) + glog.Error("could not compact:", err) } - log.Println("Done") + glog.Info("Done") } }() go func() { for _ = range prometheus.bodyCompactionTimer.C { - log.Println("Starting body compaction...") + glog.Info("Starting body compaction...") err := prometheus.compact(*bodyAge, *bodyGroupSize) if err != nil { - log.Printf("could not compact due to %s", err) + glog.Error("could not compact:", err) } - log.Println("Done") + glog.Info("Done") } }() go func() { for _ = range prometheus.tailCompactionTimer.C { - log.Println("Starting tail compaction...") + glog.Info("Starting tail compaction...") err := prometheus.compact(*tailAge, *tailGroupSize) if err != nil { - log.Printf("could not compact due to %s", err) + glog.Error("could not compact:", err) } - log.Println("Done") + glog.Info("Done") } }() go func() { for _ = range prometheus.deletionTimer.C { - log.Println("Starting deletion of stale values...") + glog.Info("Starting deletion of stale values...") err := prometheus.delete(*deleteAge, deletionBatchSize) if err != nil { - log.Printf("could not delete due to %s", err) + glog.Error("could not delete:", err) } - log.Println("Done") + glog.Info("Done") } }() go func() { err := webService.ServeForever() if err != nil { - log.Fatal(err) + glog.Fatal(err) } }() diff --git a/notification/notification.go b/notification/notification.go index 77c1cad90..1df4dd44c 100644 --- a/notification/notification.go +++ b/notification/notification.go @@ -19,11 +19,12 @@ import ( "flag" "io" "io/ioutil" - "log" "net/http" "text/template" "time" + "github.com/golang/glog" + clientmodel "github.com/prometheus/client_golang/model" "github.com/prometheus/prometheus/utility" @@ -95,7 +96,7 @@ func interpolateMessage(msg string, labels clientmodel.LabelSet, value clientmod "{{$value := .Value}}" if _, err := t.Parse(defs + msg); err != nil { - log.Println("Error parsing template:", err) + glog.Warning("Error parsing template:", err) return msg } @@ -114,7 +115,7 @@ func interpolateMessage(msg string, labels clientmodel.LabelSet, value clientmod var buf bytes.Buffer if err := t.Execute(&buf, &tmplData); err != nil { - log.Println("Error executing template:", err) + glog.Warning("Error executing template:", err) return msg } return buf.String() @@ -176,7 +177,7 @@ func (n *NotificationHandler) Run() { for reqs := range n.pendingNotifications { if n.alertmanagerUrl == "" { - log.Println("No alert manager configured, not dispatching notification") + glog.Warning("No alert manager configured, not dispatching notification") notificationsCount.Increment(map[string]string{result: dropped}) continue } @@ -186,7 +187,7 @@ func (n *NotificationHandler) Run() { recordOutcome(time.Since(begin), err) if err != nil { - log.Println("Error sending notification:", err) + glog.Error("Error sending notification:", err) } } } diff --git a/retrieval/target.go b/retrieval/target.go index d12b9bd97..c0156238a 100644 --- a/retrieval/target.go +++ b/retrieval/target.go @@ -16,12 +16,12 @@ package retrieval import ( "bytes" "fmt" - "log" "net/http" "os" "strings" "time" + "github.com/golang/glog" "github.com/prometheus/client_golang/extraction" clientmodel "github.com/prometheus/client_golang/model" @@ -303,7 +303,7 @@ func (t *target) GlobalAddress() string { address := t.address hostname, err := os.Hostname() if err != nil { - log.Printf("Couldn't get hostname: %s, returning target.Address()", err) + glog.Warning("Couldn't get hostname: %s, returning target.Address()", err) return address } for _, localhostRepresentation := range localhostRepresentations { diff --git a/retrieval/target_provider.go b/retrieval/target_provider.go index 8d5437839..9ef2ca8d3 100644 --- a/retrieval/target_provider.go +++ b/retrieval/target_provider.go @@ -15,13 +15,14 @@ package retrieval import ( "fmt" - "log" "net/url" "time" + "github.com/golang/glog" + "github.com/miekg/dns" + clientmodel "github.com/prometheus/client_golang/model" - "github.com/miekg/dns" "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/utility" ) @@ -77,7 +78,7 @@ func (p *sdTargetProvider) Targets() ([]Target, error) { for _, record := range response.Answer { addr, ok := record.(*dns.SRV) if !ok { - log.Printf("%s is not a valid SRV record", addr) + glog.Warning("%s is not a valid SRV record", addr) continue } // Remove the final dot from rooted DNS names to make them look more usual. diff --git a/retrieval/targetmanager.go b/retrieval/targetmanager.go index d59c082fa..eae4dc47b 100644 --- a/retrieval/targetmanager.go +++ b/retrieval/targetmanager.go @@ -14,10 +14,11 @@ package retrieval import ( - "log" "time" + "github.com/golang/glog" "github.com/prometheus/client_golang/extraction" + clientmodel "github.com/prometheus/client_golang/model" "github.com/prometheus/prometheus/config" @@ -65,7 +66,7 @@ func (m *targetManager) TargetPoolForJob(job config.JobConfig) *TargetPool { } targetPool = NewTargetPool(m, provider) - log.Printf("Pool for job %s does not exist; creating and starting...", job.GetName()) + glog.Infof("Pool for job %s does not exist; creating and starting...", job.GetName()) interval := job.ScrapeInterval() m.poolsByJob[job.GetName()] = targetPool diff --git a/retrieval/targetpool.go b/retrieval/targetpool.go index abe376a61..8d15c633a 100644 --- a/retrieval/targetpool.go +++ b/retrieval/targetpool.go @@ -14,11 +14,11 @@ package retrieval import ( - "log" "sort" "sync" "time" + "github.com/golang/glog" "github.com/prometheus/client_golang/extraction" ) @@ -63,7 +63,7 @@ func (p *TargetPool) Run(results chan<- *extraction.Result, interval time.Durati case newTargets := <-p.replaceTargetsQueue: p.replaceTargets(newTargets) case <-p.done: - log.Printf("TargetPool exiting...") + glog.Info("TargetPool exiting...") return } } @@ -127,7 +127,7 @@ func (p *TargetPool) runIteration(results chan<- *extraction.Result, interval ti if p.targetProvider != nil { targets, err := p.targetProvider.Targets() if err != nil { - log.Printf("Error looking up targets, keeping old list: %s", err) + glog.Warning("Error looking up targets, keeping old list: %s", err) } else { p.ReplaceTargets(targets) } diff --git a/rules/ast/ast.go b/rules/ast/ast.go index 1ca976010..be82ffc2e 100644 --- a/rules/ast/ast.go +++ b/rules/ast/ast.go @@ -17,11 +17,12 @@ import ( "errors" "fmt" "hash/fnv" - "log" "math" "sort" "time" + "github.com/golang/glog" + clientmodel "github.com/prometheus/client_golang/model" "github.com/prometheus/prometheus/stats" @@ -401,7 +402,7 @@ func (node *VectorAggregation) Eval(timestamp time.Time, view *viewAdapter) Vect func (node *VectorLiteral) Eval(timestamp time.Time, view *viewAdapter) Vector { values, err := view.GetValueAtTime(node.fingerprints, timestamp) if err != nil { - log.Println("Unable to get vector values:", err) + glog.Error("Unable to get vector values:", err) return Vector{} } return values @@ -589,7 +590,7 @@ func (node *MatrixLiteral) Eval(timestamp time.Time, view *viewAdapter) Matrix { } values, err := view.GetRangeValues(node.fingerprints, interval) if err != nil { - log.Println("Unable to get values for vector interval:", err) + glog.Error("Unable to get values for vector interval:", err) return Matrix{} } return values @@ -602,7 +603,7 @@ func (node *MatrixLiteral) EvalBoundaries(timestamp time.Time, view *viewAdapter } values, err := view.GetBoundaryValues(node.fingerprints, interval) if err != nil { - log.Printf("Unable to get boundary values for vector interval:", err) + glog.Error("Unable to get boundary values for vector interval:", err) return Matrix{} } return values diff --git a/rules/ast/query_analyzer.go b/rules/ast/query_analyzer.go index 977dac240..bdbed7710 100644 --- a/rules/ast/query_analyzer.go +++ b/rules/ast/query_analyzer.go @@ -14,9 +14,10 @@ package ast import ( - "log" "time" + "github.com/golang/glog" + clientmodel "github.com/prometheus/client_golang/model" "github.com/prometheus/prometheus/stats" @@ -56,7 +57,7 @@ func (analyzer *QueryAnalyzer) Visit(node Node) { case *VectorLiteral: fingerprints, err := analyzer.storage.GetFingerprintsForLabelSet(n.labels) if err != nil { - log.Printf("Error getting fingerprints for labelset %v: %v", n.labels, err) + glog.Errorf("Error getting fingerprints for labelset %v: %v", n.labels, err) return } n.fingerprints = fingerprints @@ -68,7 +69,7 @@ func (analyzer *QueryAnalyzer) Visit(node Node) { case *MatrixLiteral: fingerprints, err := analyzer.storage.GetFingerprintsForLabelSet(n.labels) if err != nil { - log.Printf("Error getting fingerprints for labelset %v: %v", n.labels, err) + glog.Errorf("Error getting fingerprints for labelset %v: %v", n.labels, err) return } n.fingerprints = fingerprints diff --git a/rules/load.go b/rules/load.go index 1c211db0c..001408570 100644 --- a/rules/load.go +++ b/rules/load.go @@ -18,10 +18,11 @@ import ( "errors" "fmt" "io" - "log" "os" "strings" + "github.com/golang/glog" + "github.com/prometheus/prometheus/rules/ast" ) @@ -69,7 +70,7 @@ func (lexer *RulesLexer) getChar() byte { } lexer.current = b } else if err != io.EOF { - log.Fatal(err) + glog.Fatal(err) } return lexer.current } diff --git a/rules/manager.go b/rules/manager.go index c11c658de..87312d829 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -14,11 +14,12 @@ package rules import ( - "log" "sync" "time" + "github.com/golang/glog" "github.com/prometheus/client_golang/extraction" + clientmodel "github.com/prometheus/client_golang/model" "github.com/prometheus/prometheus/config" @@ -74,7 +75,7 @@ func (m *ruleManager) Run() { m.runIteration(m.results) evalDurations.Add(map[string]string{intervalKey: m.interval.String()}, float64(time.Since(start)/time.Millisecond)) case <-m.done: - log.Printf("RuleManager exiting...") + glog.Info("RuleManager exiting...") break } } diff --git a/storage/metric/curator.go b/storage/metric/curator.go index bb00f2dd3..4e6f6f357 100644 --- a/storage/metric/curator.go +++ b/storage/metric/curator.go @@ -23,12 +23,12 @@ import ( clientmodel "github.com/prometheus/client_golang/model" - dto "github.com/prometheus/prometheus/model/generated" - "github.com/prometheus/prometheus/coding" "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage/raw" "github.com/prometheus/prometheus/storage/raw/leveldb" + + dto "github.com/prometheus/prometheus/model/generated" ) // CurationState contains high-level curation state information for the diff --git a/storage/metric/frontier.go b/storage/metric/frontier.go index c2194bbce..b61520ab2 100644 --- a/storage/metric/frontier.go +++ b/storage/metric/frontier.go @@ -19,11 +19,11 @@ import ( clientmodel "github.com/prometheus/client_golang/model" - dto "github.com/prometheus/prometheus/model/generated" - "github.com/prometheus/prometheus/coding" "github.com/prometheus/prometheus/coding/indexable" "github.com/prometheus/prometheus/storage/raw/leveldb" + + dto "github.com/prometheus/prometheus/model/generated" ) // diskFrontier describes an on-disk store of series to provide a diff --git a/storage/metric/index.go b/storage/metric/index.go index 18285f441..20eee58d8 100644 --- a/storage/metric/index.go +++ b/storage/metric/index.go @@ -20,12 +20,12 @@ import ( clientmodel "github.com/prometheus/client_golang/model" - dto "github.com/prometheus/prometheus/model/generated" - "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage/raw" "github.com/prometheus/prometheus/storage/raw/leveldb" "github.com/prometheus/prometheus/utility" + + dto "github.com/prometheus/prometheus/model/generated" ) type FingerprintMetricMapping map[clientmodel.Fingerprint]clientmodel.Metric diff --git a/storage/metric/leveldb.go b/storage/metric/leveldb.go index 7ce3d87a9..17133f65f 100644 --- a/storage/metric/leveldb.go +++ b/storage/metric/leveldb.go @@ -16,21 +16,21 @@ package metric import ( "flag" "fmt" - "log" "sort" "sync" "time" "code.google.com/p/goprotobuf/proto" + "github.com/golang/glog" clientmodel "github.com/prometheus/client_golang/model" - dto "github.com/prometheus/prometheus/model/generated" - "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage/raw" "github.com/prometheus/prometheus/storage/raw/leveldb" "github.com/prometheus/prometheus/utility" + + dto "github.com/prometheus/prometheus/model/generated" ) const sortConcurrency = 2 @@ -104,7 +104,7 @@ func (l *LevelDBMetricPersistence) Close() { closer.Close() case errorCloser: if err := closer.Close(); err != nil { - log.Println("anomaly closing:", err) + glog.Error("Error closing persistence:", err) } } } @@ -236,7 +236,7 @@ func NewLevelDBMetricPersistence(baseDirectory string) (*LevelDBMetricPersistenc if !workers.Wait() { for _, err := range workers.Errors() { - log.Printf("Could not open storage due to %s", err) + glog.Error("Could not open storage:", err) } return nil, fmt.Errorf("Unable to open metric persistence.") diff --git a/storage/metric/processor.go b/storage/metric/processor.go index d3a4e0f35..001086d9f 100644 --- a/storage/metric/processor.go +++ b/storage/metric/processor.go @@ -21,10 +21,10 @@ import ( clientmodel "github.com/prometheus/client_golang/model" - dto "github.com/prometheus/prometheus/model/generated" - "github.com/prometheus/prometheus/storage/raw" "github.com/prometheus/prometheus/storage/raw/leveldb" + + dto "github.com/prometheus/prometheus/model/generated" ) // processor models a post-processing agent that performs work given a sample diff --git a/storage/metric/processor_test.go b/storage/metric/processor_test.go index 775838261..2f9afb857 100644 --- a/storage/metric/processor_test.go +++ b/storage/metric/processor_test.go @@ -22,10 +22,10 @@ import ( clientmodel "github.com/prometheus/client_golang/model" + "github.com/prometheus/prometheus/storage/raw/leveldb" + dto "github.com/prometheus/prometheus/model/generated" fixture "github.com/prometheus/prometheus/storage/raw/leveldb/test" - - "github.com/prometheus/prometheus/storage/raw/leveldb" ) type curationState struct { diff --git a/storage/metric/samplekey.go b/storage/metric/samplekey.go index 9b35310c4..afcfad493 100644 --- a/storage/metric/samplekey.go +++ b/storage/metric/samplekey.go @@ -21,9 +21,9 @@ import ( clientmodel "github.com/prometheus/client_golang/model" - dto "github.com/prometheus/prometheus/model/generated" - "github.com/prometheus/prometheus/coding/indexable" + + dto "github.com/prometheus/prometheus/model/generated" ) // SampleKey models the business logic around the data-transfer object diff --git a/storage/metric/stochastic_test.go b/storage/metric/stochastic_test.go index fceb4bcc3..91a4d98fe 100644 --- a/storage/metric/stochastic_test.go +++ b/storage/metric/stochastic_test.go @@ -24,11 +24,11 @@ import ( clientmodel "github.com/prometheus/client_golang/model" - dto "github.com/prometheus/prometheus/model/generated" - "github.com/prometheus/prometheus/coding" "github.com/prometheus/prometheus/coding/indexable" "github.com/prometheus/prometheus/utility/test" + + dto "github.com/prometheus/prometheus/model/generated" ) const stochasticMaximumVariance = 8 diff --git a/storage/metric/tiered.go b/storage/metric/tiered.go index 34eded717..6608f58e2 100644 --- a/storage/metric/tiered.go +++ b/storage/metric/tiered.go @@ -15,12 +15,11 @@ package metric import ( "fmt" - "log" "sort" "sync" "time" - dto "github.com/prometheus/prometheus/model/generated" + "github.com/golang/glog" clientmodel "github.com/prometheus/client_golang/model" @@ -28,6 +27,8 @@ import ( "github.com/prometheus/prometheus/coding/indexable" "github.com/prometheus/prometheus/stats" "github.com/prometheus/prometheus/storage/raw/leveldb" + + dto "github.com/prometheus/prometheus/model/generated" ) type chunk Values @@ -175,7 +176,7 @@ func (t *TieredStorage) drain(drained chan<- bool) { t.state = tieredStorageDraining - log.Println("Triggering drain...") + glog.Info("Triggering drain...") t.draining <- (drained) } @@ -269,7 +270,7 @@ func (t *TieredStorage) Flush() { func (t *TieredStorage) flushMemory(ttl time.Duration) { flushOlderThan := time.Now().Add(-1 * ttl) - log.Println("Flushing...") + glog.Info("Flushing samples to disk...") t.memoryArena.Flush(flushOlderThan, t.appendToDiskQueue) queueLength := len(t.appendToDiskQueue) @@ -280,11 +281,11 @@ func (t *TieredStorage) flushMemory(ttl time.Duration) { samples = append(samples, chunk...) } - log.Printf("Writing %d samples...", len(samples)) + glog.Infof("Writing %d samples...", len(samples)) t.DiskStorage.AppendSamples(samples) } - log.Println("Done flushing.") + glog.Info("Done flushing.") } func (t *TieredStorage) Close() { @@ -373,7 +374,7 @@ func (t *TieredStorage) renderView(viewJob viewJob) { for _, scanJob := range scans { old, err := t.seriesTooOld(scanJob.fingerprint, *scanJob.operations[0].CurrentTime()) if err != nil { - log.Printf("Error getting watermark from cache for %s: %s", scanJob.fingerprint, err) + glog.Errorf("Error getting watermark from cache for %s: %s", scanJob.fingerprint, err) continue } if old { diff --git a/storage/metric/watermark.go b/storage/metric/watermark.go index b0a6fe1be..8023acff1 100644 --- a/storage/metric/watermark.go +++ b/storage/metric/watermark.go @@ -22,11 +22,11 @@ import ( clientmodel "github.com/prometheus/client_golang/model" - dto "github.com/prometheus/prometheus/model/generated" - "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage/raw" "github.com/prometheus/prometheus/storage/raw/leveldb" + + dto "github.com/prometheus/prometheus/model/generated" ) // unsafe.Sizeof(watermarks{}) diff --git a/storage/raw/index/leveldb/leveldb.go b/storage/raw/index/leveldb/leveldb.go index a498f8c14..0c443909a 100644 --- a/storage/raw/index/leveldb/leveldb.go +++ b/storage/raw/index/leveldb/leveldb.go @@ -16,10 +16,10 @@ package leveldb import ( "code.google.com/p/goprotobuf/proto" - dto "github.com/prometheus/prometheus/model/generated" - "github.com/prometheus/prometheus/storage/raw" "github.com/prometheus/prometheus/storage/raw/leveldb" + + dto "github.com/prometheus/prometheus/model/generated" ) var existenceValue = new(dto.MembershipIndexValue) diff --git a/tools/dumper/main.go b/tools/dumper/main.go index 97d0648e5..33182031b 100644 --- a/tools/dumper/main.go +++ b/tools/dumper/main.go @@ -22,16 +22,16 @@ import ( "encoding/csv" "flag" "fmt" - "log" "os" "strconv" "code.google.com/p/goprotobuf/proto" - - dto "github.com/prometheus/prometheus/model/generated" + "github.com/golang/glog" "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage/metric" + + dto "github.com/prometheus/prometheus/model/generated" ) var ( @@ -95,12 +95,12 @@ func main() { flag.Parse() if storageRoot == nil || *storageRoot == "" { - log.Fatal("Must provide a path...") + glog.Fatal("Must provide a path...") } persistence, err := metric.NewLevelDBMetricPersistence(*storageRoot) if err != nil { - log.Fatal(err) + glog.Fatal(err) } defer persistence.Close() @@ -110,13 +110,13 @@ func main() { entire, err := persistence.MetricSamples.ForEach(dumper, dumper, dumper) if err != nil { - log.Fatalf("Error dumping samples: %s", err) + glog.Fatal("Error dumping samples:", err) } if !entire { - log.Fatalf("Didn't scan entire corpus") + glog.Fatal("Didn't scan entire corpus") } dumper.Flush() if err = dumper.Error(); err != nil { - log.Fatalf("Error flushing CSV: %s", err) + glog.Fatal("Error flushing CSV:", err) } } diff --git a/tools/pruner/main.go b/tools/pruner/main.go index 684eec584..c71401ab3 100644 --- a/tools/pruner/main.go +++ b/tools/pruner/main.go @@ -19,8 +19,9 @@ package main import ( "flag" "github.com/prometheus/prometheus/storage/metric" - "log" "time" + + "github.com/golang/glog" ) var ( @@ -31,21 +32,21 @@ func main() { flag.Parse() if storageRoot == nil || *storageRoot == "" { - log.Fatal("Must provide a path...") + glog.Fatal("Must provide a path...") } persistences, err := metric.NewLevelDBMetricPersistence(*storageRoot) if err != nil { - log.Fatal(err) + glog.Fatal(err) } defer persistences.Close() start := time.Now() - log.Printf("Starting compaction...") + glog.Info("Starting compaction...") size, _ := persistences.Sizes() - log.Printf("Original Size: %d", size) + glog.Info("Original Size:", size) persistences.Prune() - log.Printf("Finished in %s", time.Since(start)) + glog.Info("Finished in", time.Since(start)) size, _ = persistences.Sizes() - log.Printf("New Size: %d", size) + glog.Info("New Size:", size) } diff --git a/tools/rule_checker/main.go b/tools/rule_checker/main.go index 2e9c3f2c9..35d25a227 100644 --- a/tools/rule_checker/main.go +++ b/tools/rule_checker/main.go @@ -19,7 +19,8 @@ package main import ( "flag" "fmt" - "log" + + "github.com/golang/glog" "github.com/prometheus/prometheus/rules" ) @@ -30,12 +31,12 @@ func main() { flag.Parse() if *ruleFile == "" { - log.Fatal("Must provide a rule file path") + glog.Fatal("Must provide a rule file path") } rules, err := rules.LoadRulesFromFile(*ruleFile) if err != nil { - log.Fatalf("Error loading rule file %s: %s", *ruleFile, err) + glog.Fatalf("Error loading rule file %s: %s", *ruleFile, err) } fmt.Printf("Successfully loaded %d rules:\n\n", len(rules)) diff --git a/web/api/query.go b/web/api/query.go index 43f16ec6e..75971428b 100644 --- a/web/api/query.go +++ b/web/api/query.go @@ -16,12 +16,12 @@ package api import ( "encoding/json" "errors" - "log" "net/http" "sort" "time" "code.google.com/p/gorest" + "github.com/golang/glog" clientmodel "github.com/prometheus/client_golang/model" @@ -59,7 +59,7 @@ func (serv MetricsService) Query(expr string, asText string) string { queryStats := stats.NewTimerGroup() result := ast.EvalToString(exprNode, timestamp, format, serv.Storage, queryStats) - log.Printf("Instant query: %s\nQuery stats:\n%s\n", expr, queryStats) + glog.Infof("Instant query: %s\nQuery stats:\n%s\n", expr, queryStats) return result } @@ -113,7 +113,7 @@ func (serv MetricsService) QueryRange(expr string, end int64, duration int64, st result := ast.TypedValueToJSON(matrix, "matrix") jsonTimer.Stop() - log.Printf("Range query: %s\nQuery stats:\n%s\n", expr, queryStats) + glog.Infof("Range query: %s\nQuery stats:\n%s\n", expr, queryStats) return result } @@ -123,14 +123,14 @@ func (serv MetricsService) Metrics() string { serv.setAccessControlHeaders(rb) rb.SetContentType(gorest.Application_Json) if err != nil { - log.Printf("Error loading metric names: %v", err) + glog.Error("Error loading metric names:", err) rb.SetResponseCode(http.StatusInternalServerError) return err.Error() } sort.Sort(metricNames) resultBytes, err := json.Marshal(metricNames) if err != nil { - log.Printf("Error marshalling metric names: %v", err) + glog.Error("Error marshalling metric names:", err) rb.SetResponseCode(http.StatusInternalServerError) return err.Error() } diff --git a/web/blob/blob.go b/web/blob/blob.go index 6a6981e92..47f1dd7ae 100644 --- a/web/blob/blob.go +++ b/web/blob/blob.go @@ -5,9 +5,10 @@ import ( "compress/gzip" "fmt" "io" - "log" "net/http" "strings" + + "github.com/golang/glog" ) const ( @@ -50,7 +51,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { file, err := GetFile(StaticFiles, name) if err != nil { if err != io.EOF { - log.Printf("Could not get file: %s", err) + glog.Warning("Could not get file:", err) } w.WriteHeader(http.StatusNotFound) return diff --git a/web/web.go b/web/web.go index cd8bd5abb..f3f7fbdf5 100644 --- a/web/web.go +++ b/web/web.go @@ -17,14 +17,13 @@ import ( "flag" "fmt" "html/template" - "log" "net" "net/http" "net/http/pprof" "os" "code.google.com/p/gorest" - + "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/exp" @@ -77,7 +76,7 @@ func (w WebService) ServeForever() error { exp.Handle("/user/", http.StripPrefix("/user/", http.FileServer(http.Dir(*userAssetsPath)))) } - log.Printf("listening on %s", *listenAddress) + glog.Info("listening on %s", *listenAddress) return http.ListenAndServe(*listenAddress, exp.DefaultCoarseMux) } @@ -94,14 +93,14 @@ func getEmbeddedTemplate(name string) (*template.Template, error) { file, err := blob.GetFile(blob.TemplateFiles, "_base.html") if err != nil { - log.Printf("Could not read base template: %s", err) + glog.Error("Could not read base template:", err) return nil, err } t.Parse(string(file)) file, err = blob.GetFile(blob.TemplateFiles, name+".html") if err != nil { - log.Printf("Could not read %s template: %s", name, err) + glog.Errorf("Could not read %s template: %s", name, err) return nil, err } t.Parse(string(file)) @@ -131,12 +130,12 @@ func getTemplate(name string) (t *template.Template, err error) { func executeTemplate(w http.ResponseWriter, name string, data interface{}) { tpl, err := getTemplate(name) if err != nil { - log.Printf("Error preparing layout template: %s", err) + glog.Error("Error preparing layout template:", err) return } err = tpl.Execute(w, data) if err != nil { - log.Printf("Error executing template: %s", err) + glog.Error("Error executing template:", err) } }