Ejemplo n.º 1
0
func initialize() {
	emitter := AutowiredEmitter()
	sender := metric_sender.NewMetricSender(emitter)
	batcher := metricbatcher.New(sender, defaultBatchInterval)
	metrics.Initialize(sender, batcher)
	logs.Initialize(log_sender.NewLogSender(AutowiredEmitter(), gosteno.NewLogger("dropsonde/logs")))
	envelopes.Initialize(envelope_sender.NewEnvelopeSender(emitter))
	go runtime_stats.NewRuntimeStats(DefaultEmitter, statsInterval).Run(nil)
	http.DefaultTransport = InstrumentedRoundTripper(http.DefaultTransport)
}
Ejemplo n.º 2
0
func initializeMetrics(origin, destination string) (*metricbatcher.MetricBatcher, error) {
	err := setupDefaultEmitter(origin, destination)
	if err != nil {
		// Legacy holdover.  We would prefer to panic, rather than just throwing our metrics
		// away and pretending we're running fine, but for now, we just don't want to break
		// anything.
		dropsonde.DefaultEmitter = &dropsonde.NullEventEmitter{}
	}

	// Copied from dropsonde.initialize(), since we stopped using dropsonde.Initialize
	// but needed it to continue operating the same.
	sender := metric_sender.NewMetricSender(dropsonde.DefaultEmitter)
	batcher := metricbatcher.New(sender, defaultBatchInterval)
	metrics.Initialize(sender, batcher)
	logs.Initialize(log_sender.NewLogSender(dropsonde.DefaultEmitter, gosteno.NewLogger("dropsonde/logs")))
	envelopes.Initialize(envelope_sender.NewEnvelopeSender(dropsonde.DefaultEmitter))
	go runtime_stats.NewRuntimeStats(dropsonde.DefaultEmitter, statsInterval).Run(nil)
	http.DefaultTransport = dropsonde.InstrumentedRoundTripper(http.DefaultTransport)
	return batcher, err
}
	"github.com/cloudfoundry/dropsonde/emitter/fake"
	"github.com/cloudfoundry/dropsonde/envelope_sender"
	"github.com/cloudfoundry/dropsonde/envelopes"
	"github.com/gogo/protobuf/proto"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("ValueMetricSender", func() {
	var (
		fakeEventEmitter *fake.FakeEventEmitter
	)
	BeforeEach(func() {
		fakeEventEmitter = fake.NewFakeEventEmitter("MonitorTest")
		envelopes.Initialize(envelope_sender.NewEnvelopeSender(fakeEventEmitter))
	})

	AfterEach(func() {
		fakeEventEmitter.Close()
	})

	It("emits bosh metrics", func() {
		valueMetricSender := valuemetricsender.NewValueMetricSender()
		timeInSeconds := time.Now().Unix()
		valueMetricSender.SendValueMetric("some-deployment", "some-job", "some-index", "some-event-name", timeInSeconds, 1.23, "some-unit")

		Eventually(fakeEventEmitter.GetEnvelopes()).Should(HaveLen(1))
		Expect(fakeEventEmitter.GetEnvelopes()[0].Origin).Should(Equal(proto.String(valuemetricsender.ForwarderOrigin)))
		Expect(fakeEventEmitter.GetEnvelopes()[0].ValueMetric).ShouldNot(BeNil())
		Expect(fakeEventEmitter.GetEnvelopes()[0].Timestamp).ShouldNot(Equal(timeInSeconds * int64(time.Second)))
Ejemplo n.º 4
0
	"github.com/gogo/protobuf/proto"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("EnvelopeSender", func() {
	var (
		emitter   *fake.FakeEventEmitter
		sender    envelope_sender.EnvelopeSender
		envOrigin string
	)

	BeforeEach(func() {
		envOrigin = "original-origin"
		emitter = fake.NewFakeEventEmitter("origin")
		sender = envelope_sender.NewEnvelopeSender(emitter)
	})

	It("sends an Envelope to its emitter", func() {
		err := sender.SendEnvelope(createTestEnvelope(envOrigin))
		Expect(err).NotTo(HaveOccurred())

		Expect(emitter.GetEnvelopes()).To(HaveLen(1))
		envelope := emitter.GetEnvelopes()[0]
		metric := envelope.ValueMetric
		Expect(metric.GetName()).To(Equal("metric-name"))
		Expect(metric.GetValue()).To(BeNumerically("==", 42))
		Expect(metric.GetUnit()).To(Equal("answers"))
		Expect(envelope.Origin).To(Equal(proto.String(envOrigin)))
	})