Exemplo n.º 1
0
func monitor_process(stop chan bool) chan map[int][]int {
	log.Println("monitor: monitor_process start")

	watcher, err := pdiscover.NewAllWatcher(pdiscover.PROC_EVENT_ALL)
	check(err)

	forks_chan := make(chan map[int][]int, 1)

	go func() {
		forks := make(map[int][]int)
		s := false
		for !s {
			select {
			case <-stop:
				s = true
			case ev := <-watcher.Fork:
				forks[ev.ParentPid] = append(forks[ev.ParentPid], ev.ChildPid)
			case <-watcher.Exec:
			case <-watcher.Exit:
			case err := <-watcher.Error:
				log.Println("error: ", err)
				panic(err)
			}
		}
		forks_chan <- forks
		watcher.Close()
	}()

	return forks_chan
}
Exemplo n.º 2
0
func main() {
	exePath, err := pdiscover.GetOwnProcPath()
	if err != nil {
		log.Fatal(err)
	}

	log.Println("exePath:", exePath)

	watcher, err := pdiscover.NewAllWatcher(pdiscover.PROC_EVENT_ALL)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		for {
			select {
			case ev := <-watcher.Fork:
				log.Println("fork event:", ev)
			case ev := <-watcher.Exec:
				log.Println("exec event:", ev)
				log.Printf("exec event: e => %#v p => %#v\n", ev, pdiscover.GetProcInfo(ev.Pid))
			case ev := <-watcher.Exit:
				log.Println("exit event:", ev)
			case err := <-watcher.Error:
				log.Println("error:", err)
			}
		}
	}()

	err = watcher.WatchAll()
	if err != nil {
		log.Fatal(err)
	}

	done := make(chan bool)

	<-done
	//...
	watcher.Close()
}
Exemplo n.º 3
0
func Run(stopChan chan struct{}) <-chan *report.PeMonitorReport {
	log.Info("pemon: starting...")

	//"connection refused" with boot2docker...
	watcher, err := pdiscover.NewAllWatcher(pdiscover.PROC_EVENT_ALL)
	utils.FailOn(err)

	reportChan := make(chan *report.PeMonitorReport, 1)

	go func() {
		peReport := &report.PeMonitorReport{
			Children: make(map[int][]int),
			Parents:  make(map[int]int),
		}

	done:
		for {
			select {
			case <-stopChan:
				log.Info("pemon: stopping...")
				break done
			case ev := <-watcher.Fork:
				peReport.Children[ev.ParentPid] = append(peReport.Children[ev.ParentPid], ev.ChildPid)
				peReport.Parents[ev.ChildPid] = ev.ParentPid
			case <-watcher.Exec:
			case <-watcher.Exit:
			case err := <-watcher.Error:
				utils.FailOn(err)
			}
		}

		reportChan <- peReport
		watcher.Close()
	}()

	return reportChan
}