Exemplo n.º 1
0
func InitEnv(configPath string) {

	if !filetool.IsExist(configPath) {
		log.Warn("configuration file[%s] is nonexistent", configPath)
		UseSystemConfig = true
	}

	if !UseSystemConfig {
		var err error
		Config, err = config.NewConfig("ini", configPath)
		if err != nil {
			log.Fetal("configuration file[%s] cannot parse. ", configPath)
			os.Exit(1)
		}
	}

	if !UseSystemConfig {
		log.SetLevelWithDefault(Config.String("log::level"), "info")
	} else {
		log.SetLevel("info")
	}

	initCfg()

	defaultPidPath := "/var/run/falcon_eye/falcon_eye.pid"
	if !UseSystemConfig {
		if iniPidPath := Config.String("common::pid"); iniPidPath != "" {
			defaultPidPath = iniPidPath
		}
	}
	systool.WritePidFile(defaultPidPath)

	runtime.GOMAXPROCS(runtime.NumCPU())
}
Exemplo n.º 2
0
func initHttpConfig() {
	HttpPort = Config.String("http::port")
	if HttpPort == "" {
		log.Warn("http::port is blank. use default 1988")
		HttpPort = "1988"
	}
}
Exemplo n.º 3
0
func initCollectBaseInfoInterval() {
	if UseSystemConfig {
		CollBaseInfoInterval = 1 * time.Second
		return
	}

	str := Config.String("collector::base_interval_in_seconds")
	if str == "" {
		log.Warn("collector::base_interval_in_seconds is blank. use default 1s")
		CollBaseInfoInterval = 1 * time.Second
		return
	}

	v, err := Config.Int64("collector::base_interval_in_seconds")
	if err != nil {
		log.Warn("collector::base_interval_in_seconds config error")
		os.Exit(1)
	}

	CollBaseInfoInterval = time.Duration(v) * time.Second
}
Exemplo n.º 4
0
func main() {
	var cfgFile string
	flag.StringVar(&cfgFile, "c", "", "configuration file")
	flag.Parse()

	if cfgFile == "" {
		cfgFile, _ = filetool.RealPath("cfg.ini")
		logtool.Warn("no configuration file specified. use default: %s", cfgFile)
	}

	global.InitEnv(cfgFile)

	go InitDataHistory()

	http.StartHttp()

	select {}
}