Example #1
0
// Refresh refreshes the poller catalog content
func (p *Poller) Refresh() {
	logger.Info("poller", "refreshing poller catalog")

	for _, w := range p.Workers {
		w.Refresh()
	}
}
Example #2
0
// Stop stops the server
func (s *Server) Stop() {
	s.poller.Shutdown()

	logger.Info("server", "service stopped")

	os.Exit(0)
}
Example #3
0
// Shutdown stops the poller
func (p *Poller) Shutdown() {
	if p.stopping {
		return
	}

	logger.Info("poller", "shutting down poller workers")

	for _, w := range p.Workers {
		w.Shutdown()
	}

	p.wg.Wait()
}
Example #4
0
// Run starts the server processing
func (s *Server) Run() error {
	var err error

	logger.Info("server", "service started")

	// Initialize poller
	s.poller = poller.NewPoller(s.config.Poller)

	// Initialize HTTP router
	gin.SetMode(gin.ReleaseMode)

	s.router = gin.New()
	s.router.RedirectTrailingSlash = true

	// Set static files handlers
	s.router.Any("/", s.handleStatic)
	s.router.Any("/static/*path", s.handleStatic)

	// Set API handlers
	s.router.Any("/api/hosts/:name", s.handleAPIHost)
	s.router.Any("/api/hosts/", s.handleAPIHosts)
	s.router.Any("/api/groups/", s.handleAPIGroups)
	s.router.Any("/api/nodes/", s.handleAPINodes)
	s.router.Any("/api/search/", s.handleAPISearch)

	// Start HTTP router
	logger.Info("server", "listening on %q", s.config.BindAddr)

	err = s.router.Run(s.config.BindAddr)
	if err != nil {
		logger.Error("server", "failed to initialize router: %s", err)
		return err
	}

	return nil
}
Example #5
0
// NewPoller returns a new poller instance
func NewPoller(c Config) *Poller {
	p := &Poller{
		config:  c,
		Workers: make([]*Worker, 0),
		wg:      &sync.WaitGroup{},
	}

	logger.Info("poller", "starting poller workers")

	names := set.New(set.ThreadSafe)

	for _, n := range c.Nodes {
		if n.Name == "" {
			logger.Error("poller", "missing mandatory `name' node parameter")
			continue
		} else if n.Address == "" {
			logger.Error("poller", "missing mandatory `remote_addr' node parameter")
			continue
		} else if names.Has(n.Name) {
			logger.Error("poller", "duplicate name `%s' found in node definition", n.Name)
			continue
		}

		w := NewWorker(n, p.wg)

		p.Workers = append(p.Workers, w)
		p.wg.Add(1)

		go w.Start()
		w.Refresh()

		names.Add(n.Name)
	}

	return p
}