Esempio n. 1
0
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)
	}
}
Esempio n. 2
0
import (
	"boshhmforwarder/config"

	"io/ioutil"
	"os"

	"boshhmforwarder/logging"

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

var _ = Describe("Config", func() {
	Context("Good configuration", func() {
		It("reads the config from a file", func() {
			conf := config.Configuration("./assets/working.json")

			Expect(conf.IncomingPort).To(Equal(1234))
			Expect(conf.LogLevel).To(Equal(logging.DEBUG))
			Expect(conf.DebugPort).To(Equal(65434))
			Expect(conf.InfoPort).To(Equal(65433))
			Expect(conf.Syslog).To(Equal("vcap.boshhmforwarder"))
		})

		It("reads a config that will default the log level", func() {
			conf := config.Configuration("./assets/without_loglevel.json")
			Expect(conf.LogLevel).To(Equal(logging.INFO))
		})
	})

	It("panics if the file doesn't exist", func() {
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/gogo/protobuf/proto"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Bosh HealthMonitor Forwarder - IntegrationTests", func() {
	var (
		udpServer  *net.UDPConn
		udpChannel chan []byte

		conf *config.Config
	)

	BeforeEach(func() {
		conf = config.Configuration("./integration_config.json")
		udpChannel = make(chan []byte, 100)
		udpServerAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", conf.MetronPort))
		Expect(err).ToNot(HaveOccurred())

		udpServer, err = net.ListenUDP("udp", udpServerAddr)
		Expect(err).ToNot(HaveOccurred())

		go readUdpToCH(udpServer, udpChannel)

	})

	AfterEach(func() {
		Expect(udpServer.Close()).To(Succeed())
		Eventually(udpChannel).Should(BeClosed())
	})