// NewListener creates a new listener for carbon datapoints func NewListener(ctx context.Context, sink dpsink.Sink, conf listenerConfig, listenAddr string, metricDeconstructor string, metricDeconstructorOptions string) (*Listener, error) { psocket, err := net.Listen("tcp", listenAddr) if err != nil { return nil, err } deconstructor, err := metricdeconstructor.Load(metricDeconstructor, metricDeconstructorOptions) if err != nil { return nil, err } counter := &dpsink.Counter{} finalSink := dpsink.FromChain(sink, dpsink.NextWrap(counter)) receiver := Listener{ sink: finalSink, psocket: psocket, conf: conf, metricDeconstructor: deconstructor, ctx: ctx, st: stats.ToKeeperMany(protocol.ListenerDims(conf.name, "carbon"), counter), } receiver.wg.Add(1) go receiver.startListening() return &receiver, nil }
// SetupHandler is shared between signalfx and here to setup listening for collectd connections. // Will do shared basic setup like configuring request counters func SetupHandler(ctx context.Context, name string, sink dpsink.Sink) (*web.Handler, stats.Keeper) { metricTracking := web.RequestCounter{} counter := &dpsink.Counter{} collectdDecoder := JSONDecoder{ SendTo: dpsink.FromChain(sink, dpsink.NextWrap(counter)), } h := web.NewHandler(ctx, &collectdDecoder).Add(web.NextHTTP(metricTracking.ServeHTTP)) st := stats.ToKeeperMany(protocol.ListenerDims(name, "collectd"), &metricTracking, counter, &collectdDecoder) return h, st }
func setupChain(ctx context.Context, sink dpsink.Sink, name string, chainType string, getReader func(dpsink.Sink) ErrorReader) (*web.Handler, stats.Keeper) { counter := &dpsink.Counter{} finalSink := dpsink.FromChain(sink, dpsink.NextWrap(counter)) errReader := getReader(finalSink) errorTracker := ErrorTrackerHandler{ reader: errReader, } metricTracking := web.RequestCounter{} handler := web.NewHandler(ctx, &errorTracker).Add(web.NextHTTP(metricTracking.ServeHTTP)) st := stats.ToKeeperMany(protocol.ListenerDims(name, "sfx_"+chainType), &metricTracking, &errorTracker, counter) return handler, st }