Example #1
0
func main() {
	flag.Parse()

	level, err := gosteno.GetLogLevel(*logLevel)
	if err != nil {
		level = gosteno.LOG_INFO
	}
	loggingConfig := &gosteno.Config{
		Sinks: []gosteno.Sink{
			gosteno.NewIOSink(os.Stdout),
		},
		Level:     level,
		Codec:     gosteno.NewJsonCodec(),
		EnableLOC: true,
	}

	gosteno.Init(loggingConfig)
	logger := gosteno.NewLogger("statsdinjector")

	statsdMessageListener := statsdlistener.New(*statsdPort, logger)
	statsdEmitter := statsdemitter.New(*metronPort, logger)

	inputChan := make(chan *events.Envelope)

	go statsdMessageListener.Run(inputChan)
	statsdEmitter.Run(inputChan)
}
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
	"github.com/cloudfoundry/sonde-go/events"
)

var _ = Describe("StatsdListener", func() {
	Describe("Run", func() {

		BeforeEach(func() {
			loggertesthelper.TestLoggerSink.Clear()
		})

		It("reads multiple gauges (on different lines) in the same packet", func(done Done) {
			listener := statsdlistener.New(51162, loggertesthelper.Logger())

			envelopeChan := make(chan *events.Envelope)

			wg := stopMeLater(func() { listener.Run(envelopeChan) })

			defer func() {
				stopAndWait(func() { listener.Stop() }, wg)
				close(done)
			}()

			Eventually(loggertesthelper.TestLoggerSink.LogContents).Should(ContainSubstring("Listening for statsd on host"))

			connection, err := net.Dial("udp", ":51162")
			Expect(err).ToNot(HaveOccurred())
			defer connection.Close()