Commit 33570415 authored by Kamil Kisiel's avatar Kamil Kisiel

Moved stub server function to gostatsd.go main

parent f744f49f
......@@ -29,8 +29,26 @@ func init() {
func main() {
flag.Parse()
err := statsd.ListenAndServe(metricsAddr, consoleAddr, graphiteAddr, flushInterval)
// Start the metric aggregator
graphite, err := statsd.NewGraphiteClient(graphiteAddr)
if err != nil {
log.Fatal(err)
}
aggregator := statsd.NewMetricAggregator(&graphite, flushInterval)
go aggregator.Aggregate()
// Start the metric receiver
f := func(metric statsd.Metric) {
aggregator.MetricChan <- metric
}
receiver := statsd.MetricReceiver{metricsAddr, statsd.HandlerFunc(f)}
go receiver.ListenAndReceive()
// Start the console
console := statsd.ConsoleServer{consoleAddr, &aggregator}
go console.ListenAndServe()
// Listen forever
select {}
}
package statsd
import (
"time"
)
func ListenAndServe(metricAddr string, consoleAddr string, graphiteAddr string, flushInterval time.Duration) error {
graphite, err := NewGraphiteClient(graphiteAddr)
if err != nil {
return err
}
aggregator := NewMetricAggregator(&graphite, flushInterval)
f := func(metric Metric) {
aggregator.MetricChan <- metric
}
receiver := MetricReceiver{metricAddr, HandlerFunc(f)}
console := ConsoleServer{consoleAddr, &aggregator}
go aggregator.Aggregate()
go receiver.ListenAndReceive()
go console.ListenAndServe()
select {}
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment