コード例 #1
0
ファイル: main.go プロジェクト: pkdevbox/loggregator
func main() {
	// Metron is intended to be light-weight so we occupy only one core
	runtime.GOMAXPROCS(1)

	flag.Parse()
	config, err := config.ParseConfig(*configFilePath)
	if err != nil {
		panic(err)
	}

	log := logger.NewLogger(*debug, *logFilePath, "metron", config.Syslog)
	log.Info("Startup: Setting up the Metron agent")

	dopplerClientPool, err := initializeClientPool(config, log)
	if err != nil {
		log.Errorf("Error while initializing client pool: %s", err.Error())
		os.Exit(-1)
	}

	dopplerForwarder := dopplerforwarder.New(dopplerClientPool, log)
	byteSigner := signer.New(config.SharedSecret, dopplerForwarder)
	marshaller := eventmarshaller.New(byteSigner, log)
	messageTagger := tagger.New(config.Deployment, config.Job, config.Index, marshaller)
	aggregator := messageaggregator.New(messageTagger, log)

	initializeMetrics(byteSigner, config, log)

	dropsondeUnmarshaller := eventunmarshaller.New(aggregator, log)
	dropsondeReader := networkreader.New(fmt.Sprintf("localhost:%d", config.DropsondeIncomingMessagesPort), "dropsondeAgentListener", dropsondeUnmarshaller, log)

	log.Info("metron started")

	dropsondeReader.Start()
}
コード例 #2
0
ファイル: main.go プロジェクト: jvshahid/loggregator
func main() {
	// Metron is intended to be light-weight so we occupy only one core
	runtime.GOMAXPROCS(1)

	flag.Parse()
	config, logger := parseConfig(*debug, *configFilePath, *logFilePath)

	dopplerClientPool := initializeClientPool(config, logger)

	dopplerForwarder := dopplerforwarder.New(dopplerClientPool, logger)
	byteSigner := signer.New(config.SharedSecret, dopplerForwarder)
	marshaller := eventmarshaller.New(byteSigner, logger)
	messageTagger := tagger.New(config.Deployment, config.Job, config.Index, marshaller)
	aggregator := messageaggregator.New(messageTagger, logger)

	initializeMetrics(byteSigner, config, logger)

	dropsondeUnmarshaller := eventunmarshaller.New(aggregator, logger)
	dropsondeReader := networkreader.New(fmt.Sprintf("localhost:%d", config.DropsondeIncomingMessagesPort), "dropsondeAgentListener", dropsondeUnmarshaller, logger)

	// TODO: remove next four lines when legacy support is removed (or extracted to injector)
	legacyMarshaller := eventmarshaller.New(byteSigner, logger)
	legacyMessageTagger := tagger.New(config.Deployment, config.Job, config.Index, legacyMarshaller)
	legacyUnmarshaller := legacyunmarshaller.New(legacyMessageTagger, logger)
	legacyReader := networkreader.New(fmt.Sprintf("localhost:%d", config.LegacyIncomingMessagesPort), "legacyAgentListener", legacyUnmarshaller, logger)

	go legacyReader.Start()
	dropsondeReader.Start()
}
コード例 #3
0
ファイル: main.go プロジェクト: khj0651/loggregator
func main() {
	flag.Parse()
	config, logger := parseConfig(*debug, *configFilePath, *logFilePath)

	dopplerClientPool := initializeClientPool(config, logger)

	dopplerForwarder := dopplerforwarder.New(dopplerClientPool, logger)
	byteSigner := signer.New(config.SharedSecret, dopplerForwarder)
	marshaller := eventmarshaller.New(byteSigner, logger)
	varzShim := varzforwarder.New(config.Job, metricTTL, marshaller, logger)
	messageTagger := tagger.New(config.Deployment, config.Job, config.Index, varzShim)
	aggregator := messageaggregator.New(messageTagger, logger)

	dropsondeUnmarshaller := eventunmarshaller.New(aggregator, logger)
	dropsondeReader := networkreader.New(fmt.Sprintf("localhost:%d", config.DropsondeIncomingMessagesPort), "dropsondeAgentListener", dropsondeUnmarshaller, logger)

	// TODO: remove next two lines when legacy support is removed (or extracted to injector)
	legacyUnmarshaller := legacyunmarshaller.New(aggregator, logger)
	legacyReader := networkreader.New(fmt.Sprintf("localhost:%d", config.LegacyIncomingMessagesPort), "legacyAgentListener", legacyUnmarshaller, logger)

	instrumentables := []instrumentation.Instrumentable{
		legacyReader,
		dropsondeReader,
		legacyUnmarshaller,
		dropsondeUnmarshaller,
		aggregator,
		varzShim,
		marshaller,
	}

	go startMonitoringEndpoints(config, instrumentables, logger)

	go legacyReader.Start()
	dropsondeReader.Start()
}
コード例 #4
0
func NewMessageWriter(host string, port int, sharedSecret string, sentCounter *metricsreporter.Counter) *messageWriter {
	output, err := net.Dial("udp4", fmt.Sprintf("%s:%d", host, port))
	if err != nil {
		fmt.Printf("DIAL Error: %s\n", err.Error())
	}

	var writer writers.ByteArrayWriter
	writer = networkWriter{
		sentCounter: sentCounter,
		conn:        output,
	}

	if len(sharedSecret) > 0 {
		writer = signer.New(sharedSecret, writer)
	}

	return &messageWriter{
		writer: writer,
	}
}
コード例 #5
0
ファイル: message_writer.go プロジェクト: khj0651/loggregator
func NewMessageWriter(port int, sharedSecret string, reporter sentMessagesReporter) *messageWriter {
	ip, err := localip.LocalIP()
	if err != nil {
		panic(err)
	}
	output, err := net.Dial("udp", fmt.Sprintf("%s:%d", ip, port))
	if err != nil {
		fmt.Printf("DIAL Error: %s\n", err.Error())
	}

	var writer writers.ByteArrayWriter
	writer = networkWriter{
		reporter: reporter,
		conn:     output,
	}

	if len(sharedSecret) > 0 {
		writer = signer.New(sharedSecret, writer)
	}

	return &messageWriter{
		writer: writer,
	}
}
コード例 #6
0
ファイル: signer_test.go プロジェクト: khj0651/loggregator
package signer_test

import (
	"metron/writers/signer"

	"github.com/cloudfoundry/dropsonde/signature"

	"metron/writers/mocks"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Signer", func() {
	It("sends signed messages to output writer", func() {
		writer := &mocks.MockByteArrayWriter{}
		s := signer.New("shared-secret", writer)

		message := []byte("Some message")
		s.Write(message)

		Expect(writer.Data()).To(HaveLen(1))

		signedMessage := signature.SignMessage(message, []byte("shared-secret"))
		Expect(writer.Data()[0]).To(Equal(signedMessage))
	})
})