Exemple #1
0
func New(configFile string) *Monitor {
	//new Monitor
	monitor := new(Monitor)
	monitor.configFile = configFile
	config := lib.ReadConfig(configFile)

	// heart beat checker
	cfg, ok := config["heart_beat"]
	if !ok {
		loglib.Error("miss heart beat config")
		return nil
	}
	checkInterval, _ := strconv.Atoi(cfg["check_interval"])
	delete(cfg, "check_interval")
	mutex := &sync.RWMutex{}

	monitor.mutex = mutex
	monitor.checkInterval = checkInterval

	hbChecker := heart_beat.NewHeartBeatChecker()
	monitor.hbChecker = hbChecker

	//log receiver
	cfg, ok = config["receiver"]
	if !ok {
		loglib.Error("miss receiver config!")
		return nil
	}
	mysql := db.NewMysql(cfg["db_host"], cfg["db_port"], cfg["db_uname"], cfg["db_passwd"], cfg["db_db"], cfg["db_charset"])
	monitor.dbConn = mysql
	monitor.ipRoleMap = getIpRoleMap(mysql)
	recvPort, _ := strconv.Atoi(cfg["recv_port"])
	receiver := NewLogReceiver(recvPort, mysql, monitor.ipRoleMap, monitor.mutex)
	monitor.receiver = receiver

	return monitor
}
Exemple #2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	var cpuProfile = flag.String("cpuprofile", "", "profile file")
	var memProfile = flag.String("memprofile", "", "mem profile")
	flag.Parse()

	if *cpuProfile != "" {
		f, err := os.Create(*cpuProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	cfgFile := flag.Arg(1)
	cfg := lib.ReadConfig(cfgFile)
	loglib.Init(cfg["logAgent"])
	hbPort, ok := cfg["monitor"]["hb_port"]
	if ok {
		loglib.HeartBeatPort = hbPort
	}

	savePid()

	switch flag.Arg(0) {
	case "logd":
		logdGo(cfg)

	case "tail":
		tailerGo(cfg)

	case "client":
		testClient2()
	case "collector":
		collectorGo(cfg)

	case "fcollector":
		fcollectorGo(cfg)

	case "etlcollector":
		etlcollectorGo(cfg)
	case "mgocollector":
		mgocollectorGo(cfg)
	case "monitor":
		mon := monitor.New(cfgFile)
		mon.Run()
	case "test":
		testClient2()
	default:
		fmt.Println("unknown parameters")
		os.Exit(1)
	}

	if *memProfile != "" {
		f, err := os.Create(*memProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.WriteHeapProfile(f)
		f.Close()
	}
}