示例#1
0
func NewFakeApp(appID string, logRate int) *FakeApp {

	generator := messagegenerator.NewLogMessageGenerator(appID)
	counter := metricsreporter.NewCounter("sentLogs")
	// 49625 is the DropsondeIncomingMessagesPort for the metron that will be spun up.
	writer := messagewriter.NewMessageWriter("localhost", 49625, "", counter)

	writeStrategy := writestrategies.NewConstantWriteStrategy(generator, writer, logRate)

	return &FakeApp{
		appID:         appID,
		logRate:       logRate,
		writeStrategy: writeStrategy,
		logCounter:    counter,
	}
}
示例#2
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()
}
	. "integration_tests/doppler/helpers"
	"io"
	"net"
	"time"
	"tools/benchmark/metricsreporter"
)

var _ = Describe("MessageLossBenchmark", func() {
	Measure("number of messages through a syslog drain per second", func(b Benchmarker) {
		localIP, err := localip.LocalIP()
		Expect(err).NotTo(HaveOccurred())
		syslogDrainAddress := net.JoinHostPort(localIP, "6547")
		listener, err := net.Listen("tcp", syslogDrainAddress)
		Expect(err).NotTo(HaveOccurred())

		counter := metricsreporter.NewCounter("messages")
		go func() {
			conn, err := listener.Accept()
			Expect(err).NotTo(HaveOccurred())

			defer conn.Close()
			buffer := make([]byte, 1024)
			for {
				conn.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
				_, err := conn.Read(buffer)
				if err == io.EOF {
					return
				} else if err != nil {
					continue
				}
	"net/http/httptest"
	"time"
	"tools/benchmark/metricsreporter"

	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
	"github.com/cloudfoundry/loggregatorlib/server/handlers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Websocketmessagereader", func() {

	It("connects to a websocket endpoint", func() {
		sentMessage := "a message"

		messages := make(chan []byte, 1)
		wsh := handlers.NewWebsocketHandler(messages, time.Second, loggertesthelper.Logger())
		server := httptest.NewServer(wsh)
		defer server.Close()

		messages <- []byte(sentMessage)

		receivedCounter := metricsreporter.NewCounter("counter")
		reader := websocketmessagereader.New(server.Listener.Addr().String(), receivedCounter)
		reader.Read()

		Eventually(receivedCounter.GetValue).Should(BeEquivalentTo(1))
	})
})
示例#5
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"tools/benchmark/metricsreporter"
)

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")
示例#6
0
package messagewriter_test

import (
	"tools/benchmark/messagewriter"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"tools/benchmark/metricsreporter"
)

var _ = Describe("MessageWriter", func() {
	var (
		sentCounter *metricsreporter.Counter
	)
	BeforeEach(func() {
		sentCounter = metricsreporter.NewCounter("sent")
	})

	It("should keep track of the total sent messages", func() {
		msgWriter := messagewriter.NewMessageWriter("localhost", 51161, "", sentCounter)
		message := []byte{}
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)
		msgWriter.Write(message)

		Expect(sentCounter.GetValue()).To(BeEquivalentTo(8))
				reporter.Stop()

				Expect(reporter.NumTicks()).To(BeEquivalentTo(1), "The reporter is writing too quickly")

				Eventually(buffer).Should(gbytes.Say(fmt.Sprintf("%s, 1, 1, %.2f/s, 0.00%%", duration, rate)))
			})
		})

		Context("with additional counters", func() {
			var (
				counter1 *metricsreporter.Counter
				counter2 *metricsreporter.Counter
			)

			BeforeEach(func() {
				counter1 = metricsreporter.NewCounter("counter1")
				counter2 = metricsreporter.NewCounter("counter2")
				counters = []*metricsreporter.Counter{counter1, counter2}
			})

			It("reports the column names", func() {
				Eventually(buffer).Should(gbytes.Say("Runtime, Sent, Received, Rate, PercentLoss, counter1, counter2"))
			})

			It("reports additional counter values", func() {
				reporter.ReceivedCounter().IncrementValue()
				reporter.SentCounter().IncrementValue()

				counter1.IncrementValue()
				counter2.IncrementValue()
				counter2.IncrementValue()
示例#8
0
package metricsreporter_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"tools/benchmark/metricsreporter"
)

var _ = Describe("Counter", func() {
	var counter *metricsreporter.Counter

	BeforeEach(func() {
		counter = metricsreporter.NewCounter("counter")
	})

	Context("GetName", func() {
		It("returns its name", func() {
			Expect(counter.GetName()).To(Equal("counter"))
		})
	})

	Context("GetValue", func() {
		It("returns its current value", func() {
			Expect(counter.GetValue()).To(BeEquivalentTo(0))
		})
	})

	Context("GetTotal", func() {
		It("returns its current total", func() {
			Expect(counter.GetTotal()).To(BeEquivalentTo(0))
		})