func (this *SyslogngInput) Init(config *conf.Conf) { this.ident = config.String("ident", "") if this.ident == "" { panic("empty ident") } this.addr = config.String("addr", ":9787") }
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) }
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) } }
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() } }
func (this *CardinalityOutput) Init(config *conf.Conf) { this.checkpoint = config.String("checkpoint", "") this.counters = stats.NewCardinalityCounter() if this.checkpoint != "" { this.counters.Load(this.checkpoint) } }
func (this *SelfSysInput) Init(config *conf.Conf) { this.stopChan = make(chan bool) this.ident = config.String("ident", "") if this.ident == "" { panic("empty ident") } }
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) }
func (this *Engine) LoadConfig(cf *conf.Conf) *Engine { config.LoadEngineConfig(cf) if section, err := cf.Section("plugin"); err == nil { plugin.LoadPlugins(section) } return this }
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") } }
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) }
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 } }
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) }
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) }
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) }
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) }
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) }
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) } }
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") } }
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) }
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) }
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) }
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) }
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) }
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") }
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) } }
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) }
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)) } }
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) }
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) } }
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 }