diff --git a/agent_api/messages/const.go b/agent_api/messages/const.go index 882bb58..4abc441 100644 --- a/agent_api/messages/const.go +++ b/agent_api/messages/const.go @@ -18,6 +18,7 @@ const ( TASK_POL_INTERVAL_UPDATE = "TASK_POLLER_INTERVAL_UPDATE" DISCOVERY_START = "DISCOVERY_START" + DISCOVERY_STOP = "DISCOVERY_STOP" DISCOVERY_HOST_START = "DISCOVERY_HOST_START" DISCOVERY_HOST_FOUND = "DISCOVERY_HOST_FOUND" DISCOVERY_HOST_DONE = "DISCOVERY_HOST_DONE" diff --git a/discovery/bootstrap/bootstrap.go b/discovery/bootstrap/bootstrap.go index 9bb939b..2e5378e 100644 --- a/discovery/bootstrap/bootstrap.go +++ b/discovery/bootstrap/bootstrap.go @@ -1,13 +1,13 @@ -package main +package bootstrap import ( "flag" "fmt" - "git.loafle.net/overflow/overflow_probe/discovery" "git.loafle.net/overflow/overflow_probe/discovery/conf" log "github.com/cihub/seelog" "os" "runtime" + "git.loafle.net/overflow/overflow_probe/discovery" ) func init() { @@ -28,16 +28,12 @@ func init() { } } -func main() { - +func Start() { runtime.GOMAXPROCS(runtime.NumCPU()) - defer log.Flush() - stop := make(chan bool, 1) go handleShell(stop) handleSignal(stop) - collector.Start() if <-stop { @@ -49,3 +45,25 @@ func main() { os.Exit(0) } } + +//func main() { +// +// runtime.GOMAXPROCS(runtime.NumCPU()) +// +// defer log.Flush() +// +// stop := make(chan bool, 1) +// go handleShell(stop) +// handleSignal(stop) +// +// collector.Start() +// +// if <-stop { +// // Comes from shell cmd 'stop' or quit signals +// stopHandleShell() +// collector.Stop() +// close(stop) +// log.Flush() +// os.Exit(0) +// } +//} diff --git a/discovery/bootstrap/shell.go b/discovery/bootstrap/shell.go index fef23b3..6b03a6e 100644 --- a/discovery/bootstrap/shell.go +++ b/discovery/bootstrap/shell.go @@ -1,4 +1,4 @@ -package main +package bootstrap import ( log "github.com/cihub/seelog" diff --git a/discovery/bootstrap/signal.go b/discovery/bootstrap/signal.go index ce163bf..8d784e1 100644 --- a/discovery/bootstrap/signal.go +++ b/discovery/bootstrap/signal.go @@ -1,4 +1,4 @@ -package main +package bootstrap import ( log "github.com/cihub/seelog" diff --git a/probe.go b/probe.go index 725ea19..f908b58 100644 --- a/probe.go +++ b/probe.go @@ -4,6 +4,7 @@ import ( "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" msg "git.loafle.net/overflow/overflow_probe/agent_api/messages" "git.loafle.net/overflow/overflow_probe/bootstrap" + discovery "git.loafle.net/overflow/overflow_probe/discovery/bootstrap" col "git.loafle.net/overflow/overflow_probe/collector" cfg "git.loafle.net/overflow/overflow_probe/config_manager" crm "git.loafle.net/overflow/overflow_probe/crawler_manager" @@ -24,6 +25,7 @@ var wg sync.WaitGroup func main() { wg.Add(1) + log.Debug("ddddddddddddddddd") go StartAgent() wg.Wait() } @@ -35,17 +37,19 @@ type Probe struct { } func StartAgent() { + stopch := make(chan bool, 1) bootstrap.HandleShell(stopch) bootstrap.HandleSignal(stopch) prb := Probe{} prb.startProbe() - + discovery.Start() prb.handleProbeStop(stopch) } func (prb *Probe) startProbe() { + //1. cfg start() cfgStarted := make(chan *config_manager.GlobalConfig, 1) if err := cfg.Start(cfgStarted, PATH); err != nil { @@ -104,6 +108,7 @@ func (prb *Probe) startProbe() { //7. col start() dataCh := make(chan interface{}) colStarted := make(chan bool, 1) + col.Start(colStarted, dataCh, prb.cm) <-colStarted @@ -159,6 +164,12 @@ func (prb *Probe) waitAgentTask() { case msg.TASK_LOG_SEND: prb.processSendLog(task) break + case msg.DISCOVERY_START: + discovery.Start() + break + case msg.DISCOVERY_STOP: + break + default: }