예제 #1
0
파일: main.go 프로젝트: Jonty/loggregator
func main() {
	runtime.GOMAXPROCS(4)

	var interval = flag.String("interval", "1s", "Interval for reported results")
	var writeRate = flag.Int("writeRate", 15000, "Number of writes per second to send to metron")
	var stopAfter = flag.String("stopAfter", "5m", "How long to run the experiment for")
	flag.Parse()

	duration, err := time.ParseDuration(*interval)
	if err != nil {
		log.Fatalf("Invalid duration %s\n", *interval)
	}

	stopAfterDuration, err := time.ParseDuration(*stopAfter)
	if err != nil {
		log.Fatalf("Invalid duration %s\n", *stopAfter)
	}

	internalMetricsCounter := metricsreporter.NewCounter("internal metrics")
	reporter := metricsreporter.New(duration, os.Stdout, internalMetricsCounter)

	reader := messagereader.NewMessageReader(3457)
	legacyReader := legacyreader.NewLegacyReader(reporter.GetReceivedCounter(), internalMetricsCounter, reader)

	exp := experiment.NewExperiment(legacyReader)

	generator := messagegenerator.NewValueMetricGenerator()
	writer := messagewriter.NewMessageWriter("localhost", 51161, "", reporter.GetSentCounter())
	writeStrategy := writestrategies.NewConstantWriteStrategy(generator, writer, *writeRate)
	exp.AddWriteStrategy(writeStrategy)

	legacyGenerator := messagegenerator.NewLegacyLogGenerator()
	legacyWriter := messagewriter.NewMessageWriter("localhost", 51160, "", reporter.GetSentCounter())
	legacyWriteStrategy := writestrategies.NewConstantWriteStrategy(legacyGenerator, legacyWriter, *writeRate)
	exp.AddWriteStrategy(legacyWriteStrategy)

	announceToEtcd()

	go reporter.Start()
	go exp.Start()

	timer := time.NewTimer(stopAfterDuration)
	<-timer.C
	exp.Stop()
	reporter.Stop()
}
예제 #2
0
)

var _ = Describe("LegacyReader", func() {
	Context("Read", func() {
		var (
			receivedCounter        *metricsreporter.Counter
			internalMetricsCounter *metricsreporter.Counter
			reader                 fakeReader
			legacyReader           *legacyreader.LegacyReader
		)

		BeforeEach(func() {
			receivedCounter = metricsreporter.NewCounter("received")
			internalMetricsCounter = metricsreporter.NewCounter("internal metrics")
			reader = fakeReader{}
			legacyReader = legacyreader.NewLegacyReader(receivedCounter, internalMetricsCounter, &reader)
		})

		It("should report legacy log messages", func() {
			reader.event = messagegenerator.BasicLogMessageEnvelope("legacy", "appID")

			legacyReader.Read()

			Expect(receivedCounter.GetValue()).To(BeEquivalentTo(1))
		})

		It("should report value metrics", func() {
			reader.event = messagegenerator.BasicValueMetricEnvelope("test-origin")

			legacyReader.Read()