func (s *MetricsServer) Start() error { component, err := cfcomponent.NewComponent( s.steno, "HM9000", 0, s, uint32(s.config.MetricsServerPort), []string{s.config.MetricsServerUser, s.config.MetricsServerPassword}, []instrumentation.Instrumentable{s}, ) if err != nil { return err } s.logger.Info("Serving Metrics", map[string]string{ "IP": component.IpAddress, "Port": strconv.Itoa(int(component.StatusPort)), "Username": component.StatusCredentials[0], "Password": component.StatusCredentials[1], }) go component.StartMonitoringEndpoints() err = s.registrar.RegisterWithCollector(component) return err }
func NewRouter(host string, h *hasher, config cfcomponent.Config, logger *gosteno.Logger) (r *router, err error) { var instrumentables []instrumentation.Instrumentable loggregatorClients := make(map[string]loggregatorclient.LoggregatorClient, len(h.loggregatorServers())) for _, server := range h.loggregatorServers() { client := loggregatorclient.NewLoggregatorClient(server, logger, loggregatorclient.DefaultBufferSize) loggregatorClients[server] = client instrumentables = append(instrumentables, client) } al := agentlistener.NewAgentListener(host, logger) instrumentables = append(instrumentables, al) cfc, err := cfcomponent.NewComponent( 0, "LoggregatorRouter", 0, &LoggregatorRouterMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, instrumentables, ) if err != nil { return } r = &router{Component: cfc, h: h, lcs: loggregatorClients, agentListener: al, host: host} return }
func NewRouter(host string, hasher *hasher.Hasher, config cfcomponent.Config, logger *gosteno.Logger) (r *Router, err error) { var instrumentables []instrumentation.Instrumentable servers := hasher.LoggregatorServers() loggregatorClients := make(map[string]loggregatorclient.LoggregatorClient, len(servers)) for _, server := range servers { client := loggregatorclient.NewLoggregatorClient(server, logger, loggregatorclient.DefaultBufferSize) loggregatorClients[server] = client instrumentables = append(instrumentables, client) } agentListener, dataChan := agentlistener.NewAgentListener(host, logger) instrumentables = append(instrumentables, agentListener) cfc, err := cfcomponent.NewComponent( logger, "LoggregatorTrafficcontroller", 0, &TrafficControllerMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, instrumentables, ) if err != nil { return } r = &Router{Component: cfc, hasher: hasher, loggregatorClients: loggregatorClients, agentListener: agentListener, dataChan: dataChan, host: host} return }
func initializeComponent(config metronConfig, instrumentables []instrumentation.Instrumentable, logger *gosteno.Logger) cfcomponent.Component { if len(config.NatsHosts) == 0 { logger.Warn("Startup: Did not receive a NATS host - not going to register component") cfcomponent.DefaultYagnatsClientProvider = func(logger *gosteno.Logger, c *cfcomponent.Config) (yagnats.NATSConn, error) { return fakeyagnats.Connect(), nil } } component, err := cfcomponent.NewComponent(logger, "MetronAgent", config.Index, &metronHealthMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, instrumentables) if err != nil { panic(err) } return component }
func main() { seed := time.Now().UnixNano() rand.Seed(seed) flag.Parse() if *version { fmt.Printf("version: %s\ngitSha: %s\nsourceUrl: https://github.com/cloudfoundry/loggregator/tree/%s\n\n", versionNumber, gitSha, gitSha) return } runtime.GOMAXPROCS(runtime.NumCPU()) if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { panic(err) } pprof.StartCPUProfile(f) defer func() { pprof.StopCPUProfile() f.Close() }() } if *memprofile != "" { f, err := os.Create(*memprofile) if err != nil { panic(err) } go func() { defer f.Close() ticker := time.NewTicker(time.Second * 1) defer ticker.Stop() for { <-ticker.C pprof.WriteHeapProfile(f) } }() } config, logger := parseConfig(logLevel, configFile, logFilePath) if len(config.NatsHosts) == 0 { logger.Warn("Startup: Did not receive a NATS host - not going to regsiter component") cfcomponent.DefaultYagnatsClientProvider = func(logger *gosteno.Logger, c *cfcomponent.Config) (yagnats.NATSClient, error) { return fakeyagnats.New(), nil } } err := config.Validate(logger) if err != nil { panic(err) } l := New("0.0.0.0", config, logger) cfc, err := cfcomponent.NewComponent( logger, "LoggregatorServer", config.Index, &LoggregatorServerHealthMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, l.Emitters(), ) if err != nil { panic(err) } cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger) err = cr.RegisterWithCollector(cfc) if err != nil { logger.Warnf("Unable to register with collector. Err: %v.", err) } go func() { err := cfc.StartMonitoringEndpoints() if err != nil { panic(err) } }() l.Start() logger.Info("Startup: loggregator server started.") killChan := make(chan os.Signal) signal.Notify(killChan, os.Kill, os.Interrupt) for { select { case <-cfcomponent.RegisterGoRoutineDumpSignalChannel(): cfcomponent.DumpGoRoutine() case <-killChan: logger.Info("Shutting down") l.Stop() return } } }
func main() { seed := time.Now().UnixNano() rand.Seed(seed) flag.Parse() if *version { fmt.Printf("version: %s\ngitSha: %s\nsourceUrl: https://github.com/cloudfoundry/loggregator/tree/%s\n\n", versionNumber, gitSha, gitSha) return } runtime.GOMAXPROCS(runtime.NumCPU()) config, logger := parseConfig(logLevel, configFile, logFilePath) err := config.validate(logger) if err != nil { panic(err) } agentListener := agentlistener.NewAgentListener(fmt.Sprintf("0.0.0.0:%d", config.IncomingPort), logger) incomingLogChan := agentListener.Start() sinkManager := sinkserver.NewSinkManager(config.MaxRetainedLogMessages, config.SkipCertVerify, config.BlackListIps, logger) go sinkManager.Start() unmarshaller := func(data []byte) (*logmessage.Message, error) { return logmessage.ParseEnvelope(data, config.SharedSecret) } messageChannelLength := 2048 messageRouter := sinkserver.NewMessageRouter(incomingLogChan, unmarshaller, sinkManager, messageChannelLength, logger) apiEndpoint := fmt.Sprintf("0.0.0.0:%d", config.OutgoingPort) keepAliveInterval := 30 * time.Second websocketServer := sinkserver.NewWebsocketServer(apiEndpoint, sinkManager, keepAliveInterval, config.WSMessageBufferSize, logger) cfc, err := cfcomponent.NewComponent( logger, "LoggregatorServer", config.Index, &LoggregatorServerHealthMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, []instrumentation.Instrumentable{agentListener, sinkManager, messageRouter}, ) if err != nil { panic(err) } cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger) err = cr.RegisterWithCollector(cfc) if err != nil { logger.Warnf("Unable to register with collector. Err: %v.", err) } go func() { err := cfc.StartMonitoringEndpoints() if err != nil { panic(err) } }() go messageRouter.Start() go websocketServer.Start() killChan := make(chan os.Signal) signal.Notify(killChan, os.Kill) for { select { case <-cfcomponent.RegisterGoRoutineDumpSignalChannel(): cfcomponent.DumpGoRoutine() case <-killChan: break } } }
func main() { flag.Parse() if *version { fmt.Printf("version: %s\ngitSha: %s\nsourceUrl: https://github.com/cloudfoundry/loggregator/tree/%s\n\n", versionNumber, gitSha, gitSha) return } // ** Config Setup config := &Config{} err := cfcomponent.ReadConfigInto(config, *configFile) if err != nil { panic(err) } logger := cfcomponent.NewLogger(*logLevel, *logFilePath, "deaagent", config.Config) logger.Info("Startup: Setting up the loggregator dea logging agent") err = config.validate(logger) if err != nil { panic(err) } // ** END Config Setup loggregatorEmitter, err := emitter.NewEmitter(config.LoggregatorAddress, "APP", "NA", config.SharedSecret, logger) if err != nil { panic(err) } agent := deaagent.NewAgent(*instancesJsonFilePath, logger) cfc, err := cfcomponent.NewComponent( logger, "LoggregatorDeaAgent", config.Index, &DeaAgentHealthMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, []instrumentation.Instrumentable{loggregatorEmitter.LoggregatorClient}, ) if err != nil { panic(err) } cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger) err = cr.RegisterWithCollector(cfc) if err != nil { panic(err) } go func() { err := cfc.StartMonitoringEndpoints() if err != nil { panic(err) } }() go agent.Start(loggregatorEmitter) for { select { case <-cfcomponent.RegisterGoRoutineDumpSignalChannel(): cfcomponent.DumpGoRoutine() } } }
func main() { flag.Parse() if *version { fmt.Printf("version: %s\ngitSha: %s\nsourceUrl: https://github.com/cloudfoundry/loggregator/tree/%s\n\n", versionNumber, gitSha, gitSha) return } // ** Config Setup config := &Config{} err := cfcomponent.ReadConfigInto(config, *configFile) if err != nil { panic(err) } if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { panic(err) } pprof.StartCPUProfile(f) defer func() { pprof.StopCPUProfile() f.Close() }() } if *memprofile != "" { f, err := os.Create(*memprofile) if err != nil { panic(err) } go func() { defer f.Close() ticker := time.NewTicker(time.Second * 1) defer ticker.Stop() for { <-ticker.C pprof.WriteHeapProfile(f) } }() } logger := cfcomponent.NewLogger(*logLevel, *logFilePath, "deaagent", config.Config) logger.Info("Startup: Setting up the loggregator dea logging agent") err = config.validate(logger) if err != nil { panic(err) } // ** END Config Setup loggregatorEmitter, err := emitter.NewEmitter(config.LoggregatorAddress, "APP", "NA", config.SharedSecret, logger) if err != nil { panic(err) } agent := deaagent.NewAgent(*instancesJsonFilePath, logger) cfc, err := cfcomponent.NewComponent( logger, "LoggregatorDeaAgent", config.Index, &DeaAgentHealthMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, []instrumentation.Instrumentable{loggregatorEmitter.LoggregatorClient}, ) if err != nil { panic(err) } cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger) err = cr.RegisterWithCollector(cfc) if err != nil { panic(err) } go func() { err := cfc.StartMonitoringEndpoints() if err != nil { panic(err) } }() go agent.Start(loggregatorEmitter) killChan := make(chan os.Signal) signal.Notify(killChan, os.Kill, os.Interrupt) for { select { case <-cfcomponent.RegisterGoRoutineDumpSignalChannel(): cfcomponent.DumpGoRoutine() case <-killChan: logger.Info("Shutting down") return } } }
func main() { seed := time.Now().UnixNano() rand.Seed(seed) flag.Parse() if *version { fmt.Printf("version: %s\ngitSha: %s\nsourceUrl: https://github.com/cloudfoundry/loggregator/tree/%s\n\n", versionNumber, gitSha, gitSha) return } runtime.GOMAXPROCS(runtime.NumCPU()) config := &Config{IncomingPort: 3456, OutgoingPort: 8080} err := cfcomponent.ReadConfigInto(config, *configFile) if err != nil { panic(err) } logger := cfcomponent.NewLogger(*logLevel, *logFilePath, "loggregator", config.Config) logger.Info("Startup: Setting up the loggregator server") err = config.validate(logger) if err != nil { panic(err) } listener := agentlistener.NewAgentListener(fmt.Sprintf("0.0.0.0:%d", config.IncomingPort), logger) incomingData := listener.Start() messageRouter := sinkserver.NewMessageRouter(config.MaxRetainedLogMessages, logger) unmarshaller := func(data []byte) (*logmessage.Message, error) { return logmessage.ParseEnvelope(data, config.SharedSecret) } httpServer := sinkserver.NewHttpServer(messageRouter, 30*time.Second, unmarshaller, logger) cfc, err := cfcomponent.NewComponent( logger, "LoggregatorServer", config.Index, &LoggregatorServerHealthMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, []instrumentation.Instrumentable{listener, messageRouter}, ) if err != nil { panic(err) } cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger) err = cr.RegisterWithCollector(cfc) if err != nil { logger.Warnf("Unable to register with collector. Err: %v.", err) } go func() { err := cfc.StartMonitoringEndpoints() if err != nil { panic(err) } }() go messageRouter.Start() go httpServer.Start(incomingData, fmt.Sprintf("0.0.0.0:%d", config.OutgoingPort)) killChan := make(chan os.Signal) signal.Notify(killChan, os.Kill) for { select { case <-cfcomponent.RegisterGoRoutineDumpSignalChannel(): cfcomponent.DumpGoRoutine() case <-killChan: break } } }
func main() { flag.Parse() if *version { fmt.Printf("\n\nversion: %s\ngitSha: %s\n\n", versionNumber, gitSha) return } runtime.GOMAXPROCS(runtime.NumCPU()) logger := cfcomponent.NewLogger(*logLevel, *logFilePath, "loggregator") config := &Config{SourcePort: 3456, WebPort: 8080, UaaVerificationKeyFile: *uaaVerificationKeyFile} err := cfcomponent.ReadConfigInto(config, *configFile) if err != nil { panic(err) } err = config.validate(logger) if err != nil { panic(err) } listener := agentlistener.NewAgentListener(fmt.Sprintf("0.0.0.0:%d", config.SourcePort), logger) incomingData := listener.Start() authorizer := authorization.NewLogAccessAuthorizer(config.decoder, config.ApiHost) sinkServer := sinkserver.NewSinkServer( messagestore.NewMessageStore(config.MaxRetainedLogMessages), logger, authorizer, 30*time.Second, ) cfc, err := cfcomponent.NewComponent( config.WebPort, "LoggregatorServer", config.Index, &LoggregatorServerHealthMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, []instrumentation.Instrumentable{listener, sinkServer}, ) if err != nil { panic(err) } rr := routerregistrar.NewRouterRegistrar(config.MbusClient, logger) uri := servernamer.ServerName( net.JoinHostPort(cfc.IpAddress, strconv.Itoa(int(config.SourcePort))), "loggregator."+config.SystemDomain) err = rr.RegisterWithRouter(cfc.IpAddress, config.WebPort, []string{uri}) if err != nil { logger.Fatalf("Did not get response from router when greeting. Using default keep-alive for now. Err: %v.", err) } cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger) err = cr.RegisterWithCollector(cfc) if err != nil { logger.Warnf("Unable to register with collector. Err: %v.", err) } go func() { err := cfc.StartMonitoringEndpoints() if err != nil { panic(err) } }() go sinkServer.Start(incomingData, fmt.Sprintf("0.0.0.0:%d", config.WebPort)) killChan := make(chan os.Signal) signal.Notify(killChan, os.Kill) for { select { case <-cfcomponent.RegisterGoRoutineDumpSignalChannel(): cfcomponent.DumpGoRoutine() case <-killChan: rr.UnregisterFromRouter(cfc.IpAddress, cfc.WebPort, []string{uri}) break } } }
func main() { seed := time.Now().UnixNano() rand.Seed(seed) flag.Parse() if *version { fmt.Printf("version: %s\ngitSha: %s\nsourceUrl: https://github.com/cloudfoundry/loggregator/tree/%s\n\n", versionNumber, gitSha, gitSha) return } runtime.GOMAXPROCS(runtime.NumCPU()) config, logger := parseConfig(logLevel, configFile, logFilePath) err := config.Validate(logger) if err != nil { panic(err) } l := New("0.0.0.0", config, logger) cfc, err := cfcomponent.NewComponent( logger, "LoggregatorServer", config.Index, &LoggregatorServerHealthMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, l.Emitters(), ) if err != nil { panic(err) } cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger) err = cr.RegisterWithCollector(cfc) if err != nil { logger.Warnf("Unable to register with collector. Err: %v.", err) } go func() { err := cfc.StartMonitoringEndpoints() if err != nil { panic(err) } }() l.Start() killChan := make(chan os.Signal) signal.Notify(killChan, os.Kill) for { select { case <-cfcomponent.RegisterGoRoutineDumpSignalChannel(): cfcomponent.DumpGoRoutine() case <-killChan: l.Stop() break } } }
func main() { flag.Parse() if *version { fmt.Printf("\n\nversion: %s\ngitSha: %s\n\n", versionNumber, gitSha) return } logger := cfcomponent.NewLogger(*logLevel, *logFilePath, "deaagent") // ** Config Setup config := &Config{} err := cfcomponent.ReadConfigInto(config, *configFile) if err != nil { panic(err) } err = config.validate(logger) if err != nil { panic(err) } // ** END Config Setup loggregatorClient := loggregatorclient.NewLoggregatorClient(config.LoggregatorAddress, logger, 4096) agent := deaagent.NewAgent(*instancesJsonFilePath, logger) cfc, err := cfcomponent.NewComponent( 0, "LoggregatorDeaAgent", config.Index, &DeaAgentHealthMonitor{}, config.VarzPort, []string{config.VarzUser, config.VarzPass}, []instrumentation.Instrumentable{loggregatorClient}, ) if err != nil { panic(err) } cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger) err = cr.RegisterWithCollector(cfc) if err != nil { panic(err) } go func() { err := cfc.StartMonitoringEndpoints() if err != nil { panic(err) } }() go agent.Start(loggregatorClient) for { select { case <-cfcomponent.RegisterGoRoutineDumpSignalChannel(): cfcomponent.DumpGoRoutine() } } }