From 37544aad4f6e95bc0eb62239c8d9e1b81fef8231 Mon Sep 17 00:00:00 2001 From: Baris Metin Date: Fri, 31 Jul 2015 01:57:37 -0700 Subject: [PATCH] cleanup --- fullerite.conf | 4 ++-- src/fullerite/collectors.go | 2 +- src/fullerite/handler/graphite.go | 8 ++++++-- src/fullerite/handler/handler.go | 8 ++------ src/fullerite/handler/signalfx.go | 9 +++++---- src/fullerite/handlers.go | 9 ++------- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/fullerite.conf b/fullerite.conf index 3f8a21fc..da53f9e7 100644 --- a/fullerite.conf +++ b/fullerite.conf @@ -9,12 +9,12 @@ "Diamond" ], "handlers": { + "Graphite": {}, "SignalFx": { "authToken": "token", "endpoint": "http://somethingsomething.com/blah", "interval": "10.0" - }, - "Graphite": {} + } }, "prefix": "test.", "interval": 10, diff --git a/src/fullerite/collectors.go b/src/fullerite/collectors.go index ed248918..62440f02 100644 --- a/src/fullerite/collectors.go +++ b/src/fullerite/collectors.go @@ -28,8 +28,8 @@ func readCollectorConfig(collector collector.Collector) { } func runCollector(collector collector.Collector) { + log.Info("Running ", collector) for { - log.Info("Collecting from ", collector) collector.Collect() time.Sleep(time.Duration(collector.Interval()) * time.Second) } diff --git a/src/fullerite/handler/graphite.go b/src/fullerite/handler/graphite.go index 103f7a6e..b4580790 100644 --- a/src/fullerite/handler/graphite.go +++ b/src/fullerite/handler/graphite.go @@ -13,13 +13,17 @@ type Graphite struct { // NewGraphite returns a new Graphite handler. func NewGraphite() *Graphite { g := new(Graphite) - g.name = "SignalFx" + g.name = "Graphite" g.maxBufferSize = DefaultBufferSize g.channel = make(chan metric.Metric) - return g } +// Configure accepts the different configuration options +func (g Graphite) Configure(conf *map[string]string) { + // TODO: implement +} + // Run sends metrics in the channel to the graphite server. func (g Graphite) Run() { // TODO: check interval and queue size and metrics. diff --git a/src/fullerite/handler/handler.go b/src/fullerite/handler/handler.go index 17142e9e..d4038048 100644 --- a/src/fullerite/handler/handler.go +++ b/src/fullerite/handler/handler.go @@ -35,6 +35,7 @@ type Handler interface { // taken care of by the base Name() string + String() string Channel() chan metric.Metric Interval() int @@ -115,12 +116,7 @@ func (handler *BaseHandler) SetInterval(val int) { handler.interval = val } -// Configure : this takes a dictionary of values with which the handler can configure itself -func (handler *BaseHandler) Configure(*map[string]string) { - // noop -} - // String returns the handler name in a printable format. func (handler *BaseHandler) String() string { - return handler.Name() + "Handler" + return handler.name + "Handler" } diff --git a/src/fullerite/handler/signalfx.go b/src/fullerite/handler/signalfx.go index 67e2c86a..6090daa6 100644 --- a/src/fullerite/handler/signalfx.go +++ b/src/fullerite/handler/signalfx.go @@ -1,12 +1,14 @@ package handler import ( - "bytes" "fullerite/metric" - "github.com/golang/protobuf/proto" + + "bytes" "io/ioutil" "net/http" "time" + + "github.com/golang/protobuf/proto" ) // SignalFx Handler @@ -25,7 +27,7 @@ func NewSignalFx() *SignalFx { return s } -// Configure : accepts the different configuration options for the signalfx handler +// Configure accepts the different configuration options for the signalfx handler func (s *SignalFx) Configure(config *map[string]string) { asmap := *config var exists bool @@ -41,7 +43,6 @@ func (s *SignalFx) Configure(config *map[string]string) { // Run send metrics in the channel to SignalFx. func (s *SignalFx) Run() { - log.Info("Starting signalfx handler...") datapoints := make([]*DataPoint, 0, s.maxBufferSize) lastEmission := time.Now() diff --git a/src/fullerite/handlers.go b/src/fullerite/handlers.go index 67b7443b..5fd701d8 100644 --- a/src/fullerite/handlers.go +++ b/src/fullerite/handlers.go @@ -7,9 +7,8 @@ import ( func startHandlers(c Config) (handlers []handler.Handler) { log.Info("Starting handlers...") - for name, config := range c.Handlers { - handler := buildHandler(name) + handler := handler.New(name) // apply any global configs handler.SetInterval(c.Interval) @@ -21,16 +20,12 @@ func startHandlers(c Config) (handlers []handler.Handler) { handlers = append(handlers, handler) + log.Info("Running ", handler) go handler.Run() } return handlers } -func buildHandler(name string) handler.Handler { - handler := handler.New(name) - return handler -} - func writeToHandlers(handlers []handler.Handler, metric metric.Metric) { for _, handler := range handlers { handler.Channel() <- metric