예제 #1
0
func CreateDefaultEmitter() (emitter.EventEmitter, string) {
	origin := os.Getenv("DROPSONDE_ORIGIN")
	if len(origin) == 0 {
		log.Println("Failed to auto-initialize dropsonde: DROPSONDE_ORIGIN environment variable not set")
		return nil, ""
	}

	destination := os.Getenv("DROPSONDE_DESTINATION")
	if len(destination) == 0 {
		log.Println("DROPSONDE_DESTINATION not set. Using " + DefaultDestination)
		destination = DefaultDestination
	}

	udpEmitter, err := emitter.NewUdpEmitter(destination)
	if err != nil {
		log.Printf("Failed to auto-initialize dropsonde: %v\n", err)
		return nil, destination
	}

	hbEmitter, err := emitter.NewHeartbeatEmitter(udpEmitter, origin)
	if err != nil {
		log.Printf("Failed to auto-initialize dropsonde: %v\n", err)
		return nil, destination
	}

	return emitter.NewEventEmitter(hbEmitter, origin), destination
}
예제 #2
0
// Initialize creates default emitters and instruments the default HTTP
// transport.
//
// The DROPSONDE_ORIGIN environment variable is required and specifies the
// source name for all metrics emitted by this process. If it is not set, the
// program will run normally but will not emit metrics.
//
// The DROPSONDE_DESTINATION environment variable sets the host and port to
// which metrics are sent. It is optional, and defaults to DefaultDestination.
func Initialize() {
	http.DefaultTransport = &http.Transport{Proxy: http.ProxyFromEnvironment}
	autowiredEmitter = &nullEventEmitter{}

	origin := os.Getenv("DROPSONDE_ORIGIN")
	if len(origin) == 0 {
		log.Println("Failed to auto-initialize dropsonde: DROPSONDE_ORIGIN environment variable not set")
		return
	}

	destination = os.Getenv("DROPSONDE_DESTINATION")
	if len(destination) == 0 {
		log.Println("DROPSONDE_DESTINATION not set. Using " + DefaultDestination)
		destination = DefaultDestination
	}

	udpEmitter, err := emitter.NewUdpEmitter(destination)
	if err != nil {
		log.Printf("Failed to auto-initialize dropsonde: %v\n", err)
		return
	}

	hbEmitter, err := emitter.NewHeartbeatEmitter(udpEmitter, origin)
	if err != nil {
		log.Printf("Failed to auto-initialize dropsonde: %v\n", err)
		return
	}

	autowiredEmitter = emitter.NewEventEmitter(hbEmitter, origin)

	go runtime_stats.NewRuntimeStats(autowiredEmitter, runtimeStatsInterval).Run(nil)

	http.DefaultTransport = InstrumentedRoundTripper(http.DefaultTransport)
}
예제 #3
0
func createDefaultEmitter(origin, destination string) (EventEmitter, error) {
	if len(origin) == 0 {
		return nil, errors.New("Failed to initialize dropsonde: origin variable not set")
	}

	if len(destination) == 0 {
		return nil, errors.New("Failed to initialize dropsonde: destination variable not set")
	}

	udpEmitter, err := emitter.NewUdpEmitter(destination)
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize dropsonde: %v", err.Error())
	}

	return emitter.NewEventEmitter(udpEmitter, origin), nil
}
예제 #4
0
func setupDefaultEmitter(origin, destination string) error {
	if origin == "" {
		return errors.New("Cannot initialize metrics with an empty origin")
	}

	if destination == "" {
		return errors.New("Cannot initialize metrics with an empty destination")
	}

	udpEmitter, err := emitter.NewUdpEmitter(destination)
	if err != nil {
		return fmt.Errorf("Failed to initialize dropsonde: %v", err.Error())
	}

	dropsonde.DefaultEmitter = emitter.NewEventEmitter(udpEmitter, origin)
	return nil
}
예제 #5
0
func createDefaultEmitter(origin, destination string) (emitter.EventEmitter, error) {
	if len(origin) == 0 {
		return nil, errors.New("Failed to initialize dropsonde: origin variable not set")
	}

	if len(destination) == 0 {
		return nil, errors.New("Failed to initialize dropsonde: destination variable not set")
	}

	udpEmitter, err := emitter.NewUdpEmitter(destination)
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize dropsonde: %v", err.Error())
	}

	heartbeatResponder, err := emitter.NewHeartbeatResponder(udpEmitter, origin)
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize dropsonde: %v", err.Error())
	}

	go udpEmitter.ListenForHeartbeatRequest(heartbeatResponder.Respond)

	return emitter.NewEventEmitter(heartbeatResponder, origin), nil
}
	"github.com/cloudfoundry/dropsonde/factories"
	"github.com/cloudfoundry/sonde-go/control"
	"github.com/gogo/protobuf/proto"
	uuid "github.com/nu7hatch/gouuid"

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

var _ = Describe("UdpEmitter", func() {
	var testData = []byte("hello")

	Describe("Close()", func() {
		It("closes the UDP connection", func() {

			udpEmitter, _ := emitter.NewUdpEmitter("localhost:42420")

			udpEmitter.Close()

			err := udpEmitter.Emit(testData)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("use of closed network connection"))
		})
	})

	Describe("Emit()", func() {
		var udpEmitter emitter.ByteEmitter

		Context("when the agent is listening", func() {

			var agentListener net.PacketConn
예제 #7
0
	"github.com/cloudfoundry/dropsonde/emitter"
	"github.com/cloudfoundry/dropsonde/envelope_extensions"
	"github.com/cloudfoundry/dropsonde/instrumented_handler"
	"github.com/cloudfoundry/sonde-go/events"
	uuid "github.com/nu7hatch/gouuid"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Sending Http events through loggregator", func() {
	Context("When the instrumented handler receives a request", func() {
		It("should emit an HttpStartStop through the firehose", func() {
			msgChan, errorChan := helpers.ConnectToFirehose()

			udpEmitter, err := emitter.NewUdpEmitter(fmt.Sprintf("localhost:%d", config.DropsondePort))
			Expect(err).ToNot(HaveOccurred())
			emitter := emitter.NewEventEmitter(udpEmitter, helpers.ORIGIN_NAME)
			done := make(chan struct{})
			handler := instrumented_handler.InstrumentedHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				w.WriteHeader(http.StatusTeapot)
				close(done)
			}), emitter)

			r, err := http.NewRequest("HEAD", "/", nil)
			Expect(err).ToNot(HaveOccurred())
			r.Header.Add("User-Agent", "Spider-Man")
			w := httptest.NewRecorder()
			handler.ServeHTTP(w, r)
			Eventually(done).Should(BeClosed())