示例#1
0
func (this *SyslogngInput) Init(config *conf.Conf) {
	this.ident = config.String("ident", "")
	if this.ident == "" {
		panic("empty ident")
	}
	this.addr = config.String("addr", ":9787")
}
示例#2
0
func (this *esConverter) load(section *conf.Conf) {
	this.keys = section.StringList("keys", nil)
	this.typ = section.String("type", "")
	this.currency = section.String("currency", "")
	this.rang = section.IntList("range", nil)
	this.normalizers = section.StringList("normalizers", nil)
}
示例#3
0
func (this *EsFilter) Init(config *conf.Conf) {
	this.ident = config.String("ident", "")
	if this.ident == "" {
		panic("empty ident")
	}
	this.converters = make([]esConverter, 0, 10)
	this.indexPattern = config.String("index_pattern", "")
	for i := 0; i < len(config.List("converts", nil)); i++ {
		section, err := config.Section(fmt.Sprintf("%s[%d]", "converts", i))
		if err != nil {
			panic(err)
		}

		c := esConverter{}
		c.load(section)
		this.converters = append(this.converters, c)
	}

	geodbFile := config.String("geodbfile", "")
	if err := als.LoadGeoDb(geodbFile); err != nil {
		panic(err)
	}
	globals := engine.Globals()
	if globals.Verbose {
		globals.Printf("Loaded geodb %s\n", geodbFile)
	}
}
示例#4
0
文件: mysql.go 项目: lucmichalski/fae
func (this *ConfigMysqlServer) loadConfig(section *conf.Conf) {
	this.Pool = section.String("pool", "")
	this.Host = section.String("host", "")
	this.Port = section.String("port", "3306")
	this.DbName = section.String("db", "")
	this.User = section.String("username", "")
	this.Pass = section.String("password", "")
	this.Charset = section.String("charset", "utf8")
	if this.Host == "" ||
		this.Port == "" ||
		this.Pool == "" ||
		this.DbName == "" {
		panic("required field missing")
	}

	this.dsn = ""
	if this.User != "" {
		this.dsn = this.User + ":"
		if this.Pass != "" {
			this.dsn += this.Pass
		}
	}
	this.dsn += fmt.Sprintf("@tcp(%s:%s)/%s?", this.Host, this.Port, this.DbName)
	if this.Charset != "" {
		this.dsn += "charset=" + this.Charset
	}
	if this.conf.Timeout > 0 {
		this.dsn += "&timeout=" + this.conf.Timeout.String()
	}
}
示例#5
0
func (this *CardinalityOutput) Init(config *conf.Conf) {
	this.checkpoint = config.String("checkpoint", "")
	this.counters = stats.NewCardinalityCounter()
	if this.checkpoint != "" {
		this.counters.Load(this.checkpoint)
	}
}
示例#6
0
func (this *SelfSysInput) Init(config *conf.Conf) {
	this.stopChan = make(chan bool)
	this.ident = config.String("ident", "")
	if this.ident == "" {
		panic("empty ident")
	}
}
示例#7
0
文件: lock.go 项目: lucmichalski/fae
func (this *ConfigLock) LoadConfig(cf *conf.Conf) {
	this.MaxItems = cf.Int("max_items", 1<<20)
	this.Expires = cf.Duration("expires", time.Second*10)

	this.enabled = true

	log.Debug("lock conf: %+v", *this)
}
示例#8
0
func (this *Engine) LoadConfig(cf *conf.Conf) *Engine {
	config.LoadEngineConfig(cf)

	if section, err := cf.Section("plugin"); err == nil {
		plugin.LoadPlugins(section)
	}
	return this
}
示例#9
0
func (this *FlashlogInput) Init(config *conf.Conf) {
	this.dsn = config.String("dsn",
		"flashlog:flashlog@unix(/var/run/mysqld/mysqld.sock)/flashlog?charset=utf8")
	this.ident = config.String("ident", "")
	if this.ident == "" {
		panic("empty ident")
	}
}
示例#10
0
func loadConfig(cf *conf.Conf) {
	config.etcServers = cf.StringList("etcd_servers", nil)
	config.faeTemplateFile = cf.String("fae_template_file", "")
	config.faeTargetFile = cf.String("fae_target_file", "")
	config.maintainTemplateFile = cf.String("maintain_template_file", "")
	config.maintainTargetFile = cf.String("maintain_target_file", "")

	log.Debug("config: %+v", config)
}
示例#11
0
文件: engine.go 项目: jlyt898/dpipe
func (this *EngineConfig) loadPluginSection(section *conf.Conf) {
	pluginCommons := new(pluginCommons)
	pluginCommons.load(section)
	if pluginCommons.disabled {
		Globals().Printf("[%s]disabled\n", pluginCommons.name)

		return
	}

	wrapper := new(PluginWrapper)
	var ok bool
	if wrapper.pluginCreator, ok = availablePlugins[pluginCommons.class]; !ok {
		pretty.Printf("allPlugins: %# v\n", availablePlugins)
		panic("unknown plugin type: " + pluginCommons.class)
	}
	wrapper.configCreator = func() *conf.Conf { return section }
	wrapper.name = pluginCommons.name

	plugin := wrapper.pluginCreator()
	plugin.Init(section)

	pluginCats := pluginTypeRegex.FindStringSubmatch(pluginCommons.class)
	if len(pluginCats) < 2 {
		panic("invalid plugin type: " + pluginCommons.class)
	}

	pluginCategory := pluginCats[1]
	if pluginCategory == "Input" {
		this.InputRunners[wrapper.name] = NewInputRunner(wrapper.name, plugin.(Input),
			pluginCommons)
		this.inputWrappers[wrapper.name] = wrapper
		if pluginCommons.ticker > 0 {
			this.InputRunners[wrapper.name].setTickLength(time.Duration(pluginCommons.ticker) * time.Second)
		}

		return
	}

	foRunner := NewFORunner(wrapper.name, plugin, pluginCommons)
	matcher := NewMatcher(section.StringList("match", nil), foRunner)
	foRunner.matcher = matcher

	switch pluginCategory {
	case "Filter":
		this.router.addFilterMatcher(matcher)
		this.FilterRunners[foRunner.name] = foRunner
		this.filterWrappers[foRunner.name] = wrapper

	case "Output":
		this.router.addOutputMatcher(matcher)
		this.OutputRunners[foRunner.name] = foRunner
		this.outputWrappers[foRunner.name] = wrapper
	}
}
示例#12
0
func (this *ConfigMemcacheServer) loadConfig(section *conf.Conf) {
	this.host = section.String("host", "")
	if this.host == "" {
		panic("Empty memcache server host")
	}
	this.hort = section.String("port", "")
	if this.hort == "" {
		panic("Empty memcache server port")
	}

	log.Debug("memcache server: %+v", *this)
}
示例#13
0
文件: engine.go 项目: jlyt898/dpipe
func (this *pluginCommons) load(section *conf.Conf) {
	this.name = section.String("name", "")
	if this.name == "" {
		pretty.Printf("%# v\n", *section)
		panic(fmt.Sprintf("invalid plugin config: %v", *section))
	}

	this.class = section.String("class", "")
	if this.class == "" {
		this.class = this.name
	}
	this.comment = section.String("comment", "")
	this.ticker = section.Int("ticker_interval", Globals().TickerLength)
	this.disabled = section.Bool("disabled", false)
}
示例#14
0
文件: redis.go 项目: lucmichalski/fae
func (this *ConfigRedisServer) loadConfig(cf *conf.Conf) {
	this.Addr = cf.String("addr", "")
	if this.Addr == "" {
		panic("Empty redis server addr")
	}
	this.MaxIdle = cf.Int("max_idle", 10)
	this.MaxActive = cf.Int("max_active", this.MaxIdle*2)
	this.IdleTimeout = cf.Duration("idle_timeout", 10*time.Minute)
}
示例#15
0
func (this *ConfigMemcache) loadConfig(cf *conf.Conf) {
	this.Servers = make(map[string]*ConfigMemcacheServer)
	this.HashStrategy = cf.String("hash_strategy", "standard")
	this.Timeout = cf.Int("timeout", 4)
	this.MaxIdleConnsPerServer = cf.Int("max_idle_conns_per_server", 3)
	for i := 0; i < len(cf.List("servers", nil)); i++ {
		section, err := cf.Section(fmt.Sprintf("servers[%d]", i))
		if err != nil {
			panic(err)
		}

		server := new(ConfigMemcacheServer)
		server.loadConfig(section)
		this.Servers[server.Address()] = server
	}

	log.Debug("memcache: %+v", *this)
}
示例#16
0
文件: config.go 项目: jlyt898/fae
func (this *configRpc) loadConfig(section *conf.Conf) {
	this.listenAddr = section.String("listen_addr", "")
	if this.listenAddr == "" {
		panic("Empty listen_addr")
	}

	this.clientTimeout = time.Duration(section.Int("client_timeout", 0)) * time.Second
	this.framed = section.Bool("framed", false)
	this.protocol = section.String("protocol", "binary")

	log.Debug("rpc: %+v", *this)
}
示例#17
0
func LoadPlugins(cf *conf.Conf) {
	for i := 0; i < PackRecyclePoolSize; i++ {
		pack := NewPipelinePack(packRecycleChan)
		packRecycleChan <- pack
	}
	for i := 0; i < len(cf.List("plugins", nil)); i++ {
		section, err := cf.Section(fmt.Sprintf("plugins[%d]", i))
		if err != nil {
			panic(err)
		}

		name := section.String("name", "")
		if name == "" {
			panic("empty plugin name")
		}

		loadOnePlugin(name, section)
	}
}
示例#18
0
func (this *AlarmOutput) Init(config *conf.Conf) {
	this.stopChan = make(chan interface{})
	this.projects = make(map[string]alarmProjectConf)
	for i := 0; i < len(config.List("projects", nil)); i++ {
		section, err := config.Section(fmt.Sprintf("projects[%d]", i))
		if err != nil {
			panic(err)
		}

		project := alarmProjectConf{}
		project.stopChan = this.stopChan
		project.fromConfig(section)
		if _, present := this.projects[project.name]; present {
			panic("dup project: " + project.name)
		}
		this.projects[project.name] = project
	}
	if len(this.projects) == 0 {
		panic("empty projects")
	}
}
示例#19
0
文件: config.go 项目: jlyt898/fae
func LoadServants(cf *conf.Conf) {
	// mongodb section
	Servants.Mongodb = new(ConfigMongodb)
	section, err := cf.Section("mongodb")
	if err != nil {
		panic(err)
	}
	Servants.Mongodb.loadConfig(section)

	// memcached section
	Servants.Memcache = new(ConfigMemcache)
	section, err = cf.Section("memcache")
	if err != nil {
		panic(err)
	}
	Servants.Memcache.loadConfig(section)

	// lcache section
	Servants.Lcache = new(ConfigLcache)
	section, err = cf.Section("lcache")
	if err != nil {
		panic(err)
	}
	Servants.Lcache.loadConfig(section)
}
示例#20
0
文件: redis.go 项目: lucmichalski/fae
func (this *ConfigRedis) LoadConfig(cf *conf.Conf) {
	section, err := cf.Section("breaker")
	if err == nil {
		this.Breaker.loadConfig(section)
	}

	this.Servers = make(map[string]map[string]*ConfigRedisServer)
	for i := 0; i < len(cf.List("pools", nil)); i++ {
		section, err := cf.Section(fmt.Sprintf("pools[%d]", i))
		if err != nil {
			panic(err)
		}

		pool := section.String("name", "")
		if pool == "" {
			panic("Empty redis pool name")
		}

		this.Servers[pool] = make(map[string]*ConfigRedisServer)

		// get servers in each pool
		for j := 0; j < len(section.List("servers", nil)); j++ {
			server, err := section.Section(fmt.Sprintf("servers[%d]", j))
			if err != nil {
				panic(err)
			}

			redisServer := new(ConfigRedisServer)
			redisServer.loadConfig(server)
			this.Servers[pool][redisServer.Addr] = redisServer
		}
	}

	log.Debug("redis conf: %+v", *this)
}
示例#21
0
func (this *ConfigEngine) LoadConfig(cf *conf.Conf) {
	this.Conf = cf

	this.HttpListenAddr = this.String("http_listen_addr", "")
	this.PprofListenAddr = this.String("pprof_listen_addr", "")
	this.DashboardListenAddr = this.String("dashboard_listen_addr", "")
	this.MetricsLogfile = this.String("metrics_logfile", "metrics.log")
	this.ReloadWatchdogInterval = this.Duration("reload_watchdog_interval", time.Second)
	this.ServerMode = this.Bool("server_mode", true)

	// rpc section
	this.Rpc = new(ConfigRpc)
	section, err := this.Section("rpc")
	if err != nil {
		panic(err)
	}
	this.Rpc.LoadConfig(section)

	// servants section
	this.Servants = new(ConfigServant)
	section, err = this.Section("servants")
	if err != nil {
		panic(err)
	}
	this.Servants.LoadConfig(this.Rpc.ListenAddr, section)

	// after load all configs, calculate EtcdSelfAddr
	this.EtcdServers = cf.StringList("etcd_servers", nil)
	if len(this.EtcdServers) > 0 {
		this.EtcdSelfAddr = this.Rpc.ListenAddr
		if strings.HasPrefix(this.EtcdSelfAddr, ":") {
			// automatically get local ip addr
			ips, _ := ip.LocalIpv4Addrs()
			this.EtcdSelfAddr = ips[0] + this.EtcdSelfAddr
		}
	}

	log.Debug("engine conf: %+v", *this)
}
示例#22
0
func (this *alarmWorkerConfigField) init(config *conf.Conf) {
	this.name = config.String("name", "")
	if this.name == "" {
		panic("alarm worker field name can't be empty")
	}

	this.typ = config.String("type", als.KEY_TYPE_STRING)
	this.parser = config.String("parser", "")
	this.ignores = config.StringList("ignores", nil)
	this._regexIgnores = make([]*regexp.Regexp, 0)
	// build the precompiled regex matcher
	for _, ignore := range this.ignores {
		if strings.HasPrefix(ignore, "regex:") {
			pattern := strings.TrimSpace(ignore[6:])
			r, err := regexp.Compile(pattern)
			if err != nil {
				panic(err)
			}

			this._regexIgnores = append(this._regexIgnores, r)
		}
	}
	this.normalizers = config.StringList("normalizers", nil)
}
示例#23
0
func (this *apiConfig) loadConfig(section *conf.Conf) {
	this.controller = section.String("controller", "")
	this.action = section.String("action", "")
	io, err := section.Section("io")
	if err != nil {
		panic(err)
	}
	this.input = io.Object("input", nil)
	this.output = io.Object("output", nil)
}
示例#24
0
func (this *ConfigMemcacheServer) loadConfig(section *conf.Conf) {
	this.Host = section.String("host", "")
	if this.Host == "" {
		panic("Empty memcache server host")
	}
	this.Port = section.String("port", "")
	if this.Port == "" {
		panic("Empty memcache server port")
	}
	this.Pool = section.String("pool", "default")

}
示例#25
0
func (this *CardinalityFilter) Init(config *conf.Conf) {
	this.ident = config.String("ident", "")
	if this.ident == "" {
		panic("empty ident")
	}
	for i := 0; i < len(config.List("converts", nil)); i++ {
		section, err := config.Section(fmt.Sprintf("%s[%d]", "converts", i))
		if err != nil {
			panic(err)
		}

		c := cardinalityConverter{}
		c.load(section)
		this.converters = append(this.converters, c)
	}
}
示例#26
0
文件: mongodb.go 项目: jlyt898/fae
func (this *ConfigMongodb) loadConfig(cf *conf.Conf) {
	this.ShardBaseNum = cf.Int("shard_base_num", 100000)
	this.Servers = make(map[string]*ConfigMongodbServer)
	for i := 0; i < len(cf.List("servers", nil)); i++ {
		section, err := cf.Section(fmt.Sprintf("servers[%d]", i))
		if err != nil {
			panic(err)
		}

		server := new(ConfigMongodbServer)
		server.loadConfig(section)
		this.Servers[server.ShardName] = server
	}

	log.Debug("mongodb: %+v", *this)
}
示例#27
0
func (this *alarmProjectConf) fromConfig(config *conf.Conf) {
	this.name = config.String("name", "")
	if this.name == "" {
		panic("project has no 'name'")
	}

	mailSection, err := config.Section("alarm_email")
	if err == nil {
		this.mailConf = alarmProjectMailConf{}
		this.mailConf.severityPoolSize = mailSection.Int("severity_pool_size", 100)
		this.mailConf.severityThreshold = mailSection.Int("severity_threshold", 8)
		this.mailConf.suppressHours = mailSection.IntList("suppress_hours", nil)
		this.mailConf.recipients = mailSection.String("recipients", "")
		if this.mailConf.recipients == "" {
			panic("mail alarm can't have no recipients")
		}
		this.mailConf.interval = mailSection.Int("interval", 300)
	}

	this.emailChan = make(chan alarmMailMessage)
	workersMutex := new(sync.Mutex)
	this.workers = make(map[string]*alarmWorker)
	for i := 0; i < len(config.List("workers", nil)); i++ {
		section, err := config.Section(fmt.Sprintf("workers[%d]", i))
		if err != nil {
			panic(err)
		}

		worker := &alarmWorker{projName: this.name,
			emailChan: this.emailChan, workersMutex: workersMutex}
		worker.init(section, this.stopChan)
		this.workers[worker.conf.camelName] = worker
	}
	if len(this.workers) == 0 {
		panic(fmt.Sprintf("%s empty 'workers'", this.name))
	}
}
示例#28
0
文件: project.go 项目: jlyt898/dpipe
func (this *ConfProject) fromConfig(c *conf.Conf) {
	this.Name = c.String("name", "")
	if this.Name == "" {
		panic("project must has 'name'")
	}
	this.IndexPrefix = c.String("index_prefix", this.Name)
	this.ShowError = c.Bool("show_error", true)

	logfile := c.String("logfile", "var/"+this.Name+".log")
	logWriter, err := os.OpenFile(logfile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0644)
	if err != nil {
		panic(err)
	}

	logOptions := log.Ldate | log.Ltime
	if Globals().Verbose {
		logOptions |= log.Lshortfile
	}
	if Globals().Debug {
		logOptions |= log.Lmicroseconds
	}

	this.Logger = log.New(logWriter, "", logOptions)
}
示例#29
0
func (this *EsBufferFilter) Init(config *conf.Conf) {
	this.ident = config.String("ident", "")
	if this.ident == "" {
		panic("empty ident")
	}

	this.stopChan = make(chan interface{})
	this.wokers = make([]*esBufferWorker, 0, 10)
	for i := 0; i < len(config.List("workers", nil)); i++ {
		section, err := config.Section(fmt.Sprintf("workers[%d]", i))
		if err != nil {
			panic(err)
		}

		worker := new(esBufferWorker)
		worker.init(section, this.ident, this.stopChan)
		this.wokers = append(this.wokers, worker)
	}
}
示例#30
0
文件: conf.go 项目: jlyt898/dpipe
func (this *table) init(config *conf.Conf) error {
	this.properties = make([]property, 0, 10)
	this.name = config.String("name", "")
	if this.name == "" {
		return errors.New("empty table name")
	}

	for i := 0; i < len(config.List("props", nil)); i++ {
		section, err := config.Section(fmt.Sprintf("props[%d]", i))
		if err != nil {
			return err
		}

		p := property{}
		p.name = section.String("name", "")
		p.transient = section.Bool("transient", true)
		p.dataType = section.String("type", "")
		this.properties = append(this.properties, p)
	}

	return nil
}