The server uses the stats service specified in the config

This commit is contained in:
Michael Baird 2017-04-19 17:22:00 -05:00
parent fea18bc14b
commit c4334b1ac6

View file

@ -17,6 +17,7 @@ import (
"time"
"github.com/pilosa/pilosa"
"github.com/pilosa/pilosa/datadog"
"github.com/pilosa/pilosa/gossip"
"github.com/pilosa/pilosa/httpbroadcast"
)
@ -90,6 +91,7 @@ func (m *Command) Run(args ...string) (err error) {
}
func (m *Command) SetupServer() error {
var err error
cluster := pilosa.NewCluster()
cluster.ReplicaN = m.Config.Cluster.ReplicaN
@ -118,9 +120,12 @@ func (m *Command) SetupServer() error {
// Configure index.
fmt.Fprintf(m.Stderr, "Using data from: %s\n", m.Config.DataDir)
m.Server.Index.Path = m.Config.DataDir
m.Server.Index.Stats = pilosa.NewExpvarStatsClient()
m.Server.MetricInterval = time.Duration(m.Config.Metric.PollingInterval)
m.Server.Index.Stats, err = NewStatsClient(m.Config.Metric.Service, m.Config.Metric.Host)
if err != nil {
return err
}
var err error
m.Server.Host, err = normalizeHost(m.Config.Host)
if err != nil {
return err
@ -201,3 +206,15 @@ func (m *Command) Close() error {
}
return serveErr
}
// NewStatsClient creates a stats client from the config
func NewStatsClient(name string, host string) (pilosa.StatsClient, error) {
switch name {
case "expvar":
return pilosa.NewExpvarStatsClient(), nil
case "statsd":
return datadog.NewStatsClient(host)
default:
return pilosa.NopStatsClient, nil
}
}