コード例 #1
0
ファイル: main.go プロジェクト: kei-yamazaki/loggregator
func main() {
	configFilePath := flag.String("configPath", "", "path to the configuration file")

	flag.Parse()

	conf := config.Configuration(*configFilePath)

	if len(conf.Syslog) > 0 {
		logging.SetSysLogger(conf.Syslog)
	}
	logging.SetLevel(conf.LogLevel)

	dropsonde.Initialize("localhost:"+strconv.Itoa(conf.MetronPort), valuemetricsender.ForwarderOrigin)

	go func() {
		err := tcp.Open(conf.IncomingPort, forwarder.StartMessageForwarder(valuemetricsender.NewValueMetricSender()))
		if err != nil {
			logging.Log.Panic("Could not open the TCP port", err)
		}
	}()

	logging.Log.Info("Bosh HM forwarder initialized")

	infoHandler := handlers.NewInfoHandler()
	router := mux.NewRouter()
	router.Handle("/info", infoHandler).Methods("GET")

	if conf.DebugPort > 0 {
		go pprofServer(conf.DebugPort)
	}

	logging.Log.Info(fmt.Sprintf("Starting Info Server on port %d", conf.InfoPort))

	err := http.ListenAndServe(net.JoinHostPort("", fmt.Sprintf("%d", conf.InfoPort)), router)
	if err != nil {
		logging.Log.Panic("Failed to start up alerter: ", err)
	}
}
コード例 #2
0
	. "github.com/onsi/gomega"
)

var _ = Describe("Tcp", func() {
	var (
		incoming chan string
		port     int
	)

	Context("Open TCP Port", func() {
		BeforeEach(func() {
			var err error
			incoming = make(chan string)
			port = 4000
			go func() {
				err = tcp.Open(port, incoming)
				Expect(err).ToNot(HaveOccurred())
			}()
			Eventually(func() error {
				conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", port))

				if err == nil && conn != nil {
					defer conn.Close()
				}

				return err
			}, 100).ShouldNot(HaveOccurred())
		})

		It("opens the TCP Port", func() {
			expectedMessage := "put LoggregatorDeaAgent.numCpus 1440704981 2 deployment=cf-dijon index=0 ip=10.10.16.31 job=LoggregatorDeaAgent name=LoggregatorDeaAgent/0 role=core status=3xx component=uaa"