Пример #1
0
func main() {
	if dropsondeDestination == "" {
		fmt.Println("dropsondeDestination flag is required")
		os.Exit(1)
	}
	if sourceInstance == "" {
		fmt.Println("sourceInstance flag is required")
		os.Exit(1)
	}

	args := flag.Args()

	if len(args) == 0 {
		fmt.Println("Command not specified!")
		fmt.Println("Usage: tee2metron -dropsondeDestionation=127.0.0.1:3457 -sourceInstance=cell-21 COMMAND")
		os.Exit(3)
	}
	err := dropsonde.Initialize(dropsondeDestination, sourceInstance, args[0])

	if err != nil {
		panic("error initializing dropsonde" + err.Error())
	}

	dropsondeStdoutReader, dropsondeStdoutWriter := io.Pipe()
	dropsondeStderrReader, dropsondeStderrWriter := io.Pipe()

	stdoutTeeWriter := io.MultiWriter(dropsondeStdoutWriter, os.Stdout)
	stderrTeeWriter := io.MultiWriter(dropsondeStderrWriter, os.Stderr)

	defer dropsondeStdoutReader.Close()
	defer dropsondeStderrReader.Close()
	defer dropsondeStdoutWriter.Close()
	defer dropsondeStderrWriter.Close()
	cmd := exec.Command(args[0], args[1:]...)
	cmd.Stdout = stdoutTeeWriter
	cmd.Stderr = stderrTeeWriter
	go logs.ScanLogStream(latticeDebugStreamId, args[0], sourceInstance, dropsondeStdoutReader)
	go logs.ScanErrorLogStream(latticeDebugStreamId, args[0], sourceInstance, dropsondeStderrReader)

	err = cmd.Start()
	if err != nil {
		fmt.Println(err)
		os.Exit(3)
	}

	// if the child is killed abnormally we would know
	err = cmd.Wait()
	if err != nil {
		fmt.Println(args[0], ":", err)
		os.Exit(3)
	}
}
Пример #2
0
func (tl *TaskListener) StartListening() {
	tl.Debugf("TaskListener.StartListening: Starting to listen to %v\n", tl.taskIdentifier)
	tl.Debugf("TaskListener.StartListening: Scanning logs for %s", tl.task.ApplicationId)

	tl.Add(2)
	go func() {
		defer tl.Done()
		defer tl.StopListening()
		logs.ScanLogStream(tl.task.ApplicationId, tl.task.SourceName, strconv.FormatUint(tl.task.Index, 10), tl.stdOutReader)
	}()
	go func() {
		defer tl.Done()
		defer tl.StopListening()
		logs.ScanErrorLogStream(tl.task.ApplicationId, tl.task.SourceName, strconv.FormatUint(tl.task.Index, 10), tl.stdErrReader)
	}()

	tl.Wait()
}
Пример #3
0
			err := logs.SendAppErrorLog("app-id", "custom-log-error-message", "App", "0")
			Expect(err).To(HaveOccurred())
		})
	})

	Context("when Metric Sender is not initialized", func() {
		BeforeEach(func() {
			logs.Initialize(nil)
		})

		It("SendAppLog is a no-op", func() {
			err := logs.SendAppLog("app-id", "custom-log-message", "App", "0")
			Expect(err).ToNot(HaveOccurred())
		})

		It("SendAppErrorLog is a no-op", func() {
			err := logs.SendAppErrorLog("app-id", "custom-log-error-message", "App", "0")
			Expect(err).ToNot(HaveOccurred())
		})

		It("ScanLogStream is a no-op", func() {
			Expect(func() { logs.ScanLogStream("app-id", "src-type", "src-instance", nil) }).ShouldNot(Panic())
		})

		It("ScanErrorLogStream is a no-op", func() {
			Expect(func() { logs.ScanErrorLogStream("app-id", "src-type", "src-instance", nil) }).ShouldNot(Panic())
		})

	})
})