コード例 #1
0
ファイル: es_filter.go プロジェクト: jlyt898/dpipe
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)
}
コード例 #2
0
ファイル: option.go プロジェクト: lucmichalski/fae
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)
}
コード例 #3
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
	}
}
コード例 #4
0
ファイル: archive_input.go プロジェクト: jlyt898/dpipe
func (this *ArchiveInput) Init(config *conf.Conf) {
	this.rootDir = config.String("root_dir", "")
	this.ident = config.String("ident", "")
	if this.ident == "" {
		panic("empty ident")
	}
	this.project = config.String("project", "rs")
	this.workerNChan = make(chan int, config.Int("concurrent_num", 20))
	this.chkpnt = als.NewFileCheckpoint(config.String("chkpntfile", ""))
	this.ignores = config.StringList("ignores", nil)
}
コード例 #5
0
ファイル: cardinality_filter.go プロジェクト: jlyt898/dpipe
func (this *cardinalityConverter) load(section *conf.Conf) {
	this.logPrefix = section.String("log_prefix", "")
	this.project = section.String("project", "")
	this.fields = make([]cardinalityField, 0, 5)
	for i := 0; i < len(section.List("fields", nil)); i++ {
		keyPrefix := fmt.Sprintf("fields[%d].", i)
		field := cardinalityField{}
		field.key = section.String(keyPrefix+"key", "")
		field.typ = section.String(keyPrefix+"type", "string")
		field.intervals = section.StringList(keyPrefix+"intervals", nil)
		this.fields = append(this.fields, field)
	}
}
コード例 #6
0
ファイル: mysql.go プロジェクト: lucmichalski/fae
func (this *ConfigMysql) LoadConfig(cf *conf.Conf) {
	this.GlobalPools = make(map[string]bool)
	for _, p := range cf.StringList("global_pools", nil) {
		this.GlobalPools[p] = true
	}
	this.ShardStrategy = cf.String("shard_strategy", "standard")
	this.MaxIdleTime = cf.Duration("max_idle_time", 0)
	this.Timeout = cf.Duration("timeout", 10*time.Second)
	this.AllowNullableColumns = cf.Bool("allow_nullable_columns", true)
	this.MaxIdleConnsPerServer = cf.Int("max_idle_conns_per_server", 2)
	this.MaxConnsPerServer = cf.Int("max_conns_per_server",
		this.MaxIdleConnsPerServer*5)
	this.CachePrepareStmtMaxItems = cf.Int("cache_prepare_stmt_max_items", 0)
	this.HeartbeatInterval = cf.Int("heartbeat_interval", 120)
	this.CacheStore = cf.String("cache_store", "mem")
	this.CacheStoreMemMaxItems = cf.Int("cache_store_mem_max_items", 10<<20)
	this.CacheStoreRedisPool = cf.String("cache_store_redis_pool", "db_cache")
	this.CacheKeyHash = cf.Bool("cache_key_hash", false)
	this.LookupPool = cf.String("lookup_pool", "ShardLookup")
	this.JsonMergeMaxOutstandingItems = cf.Int("json_merge_max_outstanding_items", 8<<20)
	this.LookupCacheMaxItems = cf.Int("lookup_cache_max_items", 1<<20)
	section, err := cf.Section("breaker")
	if err == nil {
		this.Breaker.loadConfig(section)
	}
	section, err = cf.Section("lookup_tables")
	if err == nil {
		this.lookupTables = *section
	} else {
		panic(err)
	}

	this.Servers = make(map[string]*ConfigMysqlServer)
	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(ConfigMysqlServer)
		server.conf = this
		server.loadConfig(section)
		this.Servers[server.Pool] = server
	}

	log.Debug("mysql conf: %+v", *this)
}
コード例 #7
0
ファイル: alarm_worker.go プロジェクト: jlyt898/dpipe
func (this *alarmWorkerConfig) init(config *conf.Conf) {
	this.camelName = config.String("camel_name", "")
	if this.camelName == "" {
		panic("empty 'camel_name'")
	}

	this.title = config.String("title", "")
	if this.title == "" {
		this.title = this.camelName
	}
	this.colors = config.StringList("colors", nil)
	this.printFormat = config.String("printf", "")
	this.instantFormat = config.String("iprintf", "")
	if this.printFormat == "" && this.instantFormat == "" {
		panic(fmt.Sprintf("%s empty 'printf' and 'iprintf'", this.title))
	}
	this.severity = config.Int("severity", 1)
	this.windowSize = time.Duration(config.Int("window_size", 0)) * time.Second
	this.showSummary = config.Bool("show_summary", false)
	this.beepThreshold = config.Int("beep_threshold", 0)
	this.abnormalBase = config.Int("abnormal_base", 10)
	this.abnormalSeverityFactor = config.Int("abnormal_severity_factor", 2)
	this.abnormalPercent = config.Float("abnormal_percent", 1.5)
	this.dbName = config.String("dbname", "")
	this.tableName = this.dbName // table name is db name
	this.createTable = config.String("create_table", "")
	this.insertStmt = config.String("insert_stmt", "")
	this.statsStmt = config.String("stats_stmt", "")

	this.fields = make([]alarmWorkerConfigField, 0, 5)
	for i := 0; i < len(config.List("fields", nil)); i++ {
		section, err := config.Section(fmt.Sprintf("fields[%d]", i))
		if err != nil {
			panic(err)
		}

		field := alarmWorkerConfigField{}
		field.init(section)
		this.fields = append(this.fields, field)
	}
	if len(this.fields) == 0 {
		panic(fmt.Sprintf("%s empty 'fields'", this.title))
	}
}
コード例 #8
0
ファイル: engine.go プロジェクト: lucmichalski/fae
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)
}
コード例 #9
0
ファイル: alarm_worker.go プロジェクト: jlyt898/dpipe
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)
}
コード例 #10
0
ファイル: couchbase.go プロジェクト: lucmichalski/fae
func (this *ConfigCouchbase) LoadConfig(cf *conf.Conf) {
	this.Servers = cf.StringList("servers", nil)
	log.Debug("couchbase conf: %+v", *this)
}
コード例 #11
0
ファイル: main.go プロジェクト: jlyt898/dpipe
// recursively
func handleSection(section *conf.Conf) {
	ident := section.String(IDENT, "")
	if ident != "" {
		if _, present := graph[ident]; present {
			fmt.Printf("ident[%s]duplicated\n", ident)
			os.Exit(1)
		}

		ie := &identEntry{}
		ie.matches = make([]string, 0, 10)
		ie.disabled = section.Bool(DISABLED, false)
		if section.StringList(MATCH, nil) == nil {
			ie.isInput = true
		}

		graph[ident] = ie
		pluginName := section.String(NAME, "")
		if pluginName != "" {
			identName[pluginName] = ident
		}
	}

	matches := section.StringList(MATCH, nil)
	if matches != nil {
		pluginName := section.String(NAME, "")
		if pluginName == "" {
			fmt.Printf("plugin match %v has no 'name' key\n", matches)
			os.Exit(1)
		}

		for _, id := range matches {
			if _, present := graph[id]; present {
				graph[id].matches = append(graph[id].matches, pluginName)
			} else {
				fmt.Printf("%15s -> %s\n", id, pluginName)
			}
		}
	}

	sub := section.Interface("", nil).(map[string]interface{})
	if sub == nil {
		return
	}

	for k, v := range sub {
		if x, ok := v.([]interface{}); ok {
			switch x[0].(type) {
			case string, float64, int, bool, time.Time:
				// this section will never find 'ident'
				continue
			}

			for i := 0; i < len(section.List(k, nil)); i++ {
				key := fmt.Sprintf("%s[%d]", k, i)
				sec, err := section.Section(key)
				if err != nil {
					continue
				}

				handleSection(sec)
			}
		}
	}
}