Example #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)
}
Example #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)))
Example #4
0
	"github.com/cloudfoundry/dropsonde/envelopes"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/gogo/protobuf/proto"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry/dropsonde/envelope_sender/fake"
)

var _ = Describe("Metrics", func() {
	var fakeEnvelopeSender *fake.FakeEnvelopeSender

	BeforeEach(func() {
		fakeEnvelopeSender = fake.NewFakeEnvelopeSender()
		envelopes.Initialize(fakeEnvelopeSender)
	})

	It("delegates SendEnvelope", func() {
		testEnvelope := createTestEnvelope()

		envelopes.SendEnvelope(testEnvelope)

		Expect(fakeEnvelopeSender.GetEnvelopes()).To(HaveLen(1))
		Expect(fakeEnvelopeSender.GetEnvelopes()[0]).To(BeEquivalentTo(testEnvelope))
	})

	Context("when Envelope Sender is not initialized", func() {

		BeforeEach(func() {
			envelopes.Initialize(nil)