コード例 #1
0
ファイル: handler.go プロジェクト: gsalisbury/fullerite
// configureCommonParams will extract the common parameters that are used and set them in the handler
func (base *BaseHandler) configureCommonParams(configMap map[string]interface{}) {
	if asInterface, exists := configMap["timeout"]; exists {
		timeout := config.GetAsFloat(asInterface, DefaultTimeoutSec)
		base.timeout = time.Duration(timeout) * time.Second
	}

	if asInterface, exists := configMap["max_buffer_size"]; exists {
		base.maxBufferSize = config.GetAsInt(asInterface, DefaultBufferSize)
	}

	if asInterface, exists := configMap["interval"]; exists {
		base.interval = config.GetAsInt(asInterface, DefaultInterval)
	}

	// Default dimensions can be extended or overridden on a per handler basis.
	if asInterface, exists := configMap["defaultDimensions"]; exists {
		handlerLevelDimensions := config.GetAsMap(asInterface)
		base.SetDefaultDimensions(handlerLevelDimensions)
	}

	if asInterface, exists := configMap["keepAliveInterval"]; exists {
		keepAliveInterval := config.GetAsInt(asInterface, DefaultKeepAliveInterval)
		base.SetKeepAliveInterval(keepAliveInterval)
	}

	if asInterface, exists := configMap["maxIdleConnectionsPerHost"]; exists {
		maxIdleConnectionsPerHost := config.GetAsInt(asInterface,
			DefaultMaxIdleConnectionsPerHost)
		base.SetMaxIdleConnectionsPerHost(maxIdleConnectionsPerHost)
	}
}
コード例 #2
0
ファイル: mesos_slave.go プロジェクト: EvanKrall/fullerite
// Configure Override *baseCollector.Configure(). Will create the required MesosLeaderElect instance.
func (m *MesosSlaveStats) Configure(configMap map[string]interface{}) {
	m.configureCommonParams(configMap)
	c := config.GetAsMap(configMap)

	if httpTimeout, exists := c["httpTimeout"]; exists {
		m.client.Timeout = time.Duration(config.GetAsInt(httpTimeout, httpDefaultTimeout)) * time.Second
	}

	if slaveSnapshotPort, exists := c["slaveSnapshotPort"]; exists {
		m.snapshotPort = config.GetAsInt(slaveSnapshotPort, mesosDefaultSlaveSnapshotPort)
	}
}
コード例 #3
0
ファイル: config_test.go プロジェクト: jp2007/fullerite
func TestGetInt(t *testing.T) {
	assert := assert.New(t)

	val := config.GetAsInt("10", 123)
	assert.Equal(val, 10)

	val = config.GetAsInt("notanint", 123)
	assert.Equal(val, 123)

	val = config.GetAsInt(12.123, 123)
	assert.Equal(val, 12)

	val = config.GetAsInt(12, 123)
	assert.Equal(val, 12)
}
コード例 #4
0
ファイル: docker_stats.go プロジェクト: EvanKrall/fullerite
// Configure takes a dictionary of values with which the handler can configure itself.
func (d *DockerStats) Configure(configMap map[string]interface{}) {
	if timeout, exists := configMap["dockerStatsTimeout"]; exists {
		d.statsTimeout = min(config.GetAsInt(timeout, d.interval), d.interval)
	} else {
		d.statsTimeout = d.interval
	}
	if dockerEndpoint, exists := configMap["dockerEndPoint"]; exists {
		if str, ok := dockerEndpoint.(string); ok {
			d.endpoint = str
		} else {
			d.log.Warn("Failed to cast dokerEndPoint: ", reflect.TypeOf(dockerEndpoint))
		}
	} else {
		d.endpoint = endpoint
	}
	d.dockerClient, _ = docker.NewClient(d.endpoint)
	if generatedDimensions, exists := configMap["generatedDimensions"]; exists {
		for dimension, generator := range generatedDimensions.(map[string]interface{}) {
			for key, regx := range config.GetAsMap(generator) {
				re, err := regexp.Compile(regx)
				if err != nil {
					d.log.Warn("Failed to compile regex: ", regx, err)
				} else {
					d.compiledRegex[dimension] = &Regex{regex: re, tag: key}
				}
			}
		}
	}
	d.configureCommonParams(configMap)
	if skipRegex, skipExists := configMap["skipContainerRegex"]; skipExists {
		d.skipRegex = regexp.MustCompile(skipRegex.(string))
	}
}
コード例 #5
0
ファイル: nerve_config.go プロジェクト: venkey-ariv/fullerite
// ParseNerveConfig is responsible for taking the JSON string coming in into a map of service:port
// it will also filter based on only services runnign on this host.
// To deal with multi-tenancy we actually will return port:service
func ParseNerveConfig(raw *[]byte) (map[int]string, error) {
	results := make(map[int]string)
	ips, err := ipGetter()

	if err != nil {
		return results, err
	}
	parsed := new(nerveConfigData)

	// convert the ips into a map for membership tests
	ipMap := make(map[string]bool)
	for _, val := range ips {
		ipMap[val] = true
	}

	err = json.Unmarshal(*raw, parsed)
	if err != nil {
		return results, err
	}

	for rawServiceName, serviceConfig := range parsed.Services {
		host := strings.TrimSpace(serviceConfig["host"].(string))

		_, exists := ipMap[host]
		if exists {
			name := strings.Split(rawServiceName, ".")[0]
			port := config.GetAsInt(serviceConfig["port"], -1)
			if port != -1 {
				results[port] = name
			}
		}
	}

	return results, nil
}
コード例 #6
0
ファイル: nerve_uwsgi.go プロジェクト: yeled/fullerite
// parseNerveConfig is responsible for taking the JSON string coming in into a map of service:port
// it will also filter based on only services runnign on this host.
// To deal with multi-tenancy we actually will return port:service
func (n *nerveUWSGICollector) parseNerveConfig(raw *[]byte, ips []string) (map[int]string, error) {
	parsed := new(releventNerveConfig)

	// convert the ips into a map for membership tests
	ipMap := make(map[string]bool)
	for _, val := range ips {
		ipMap[val] = true
	}

	err := json.Unmarshal(*raw, parsed)
	if err != nil {
		return make(map[int]string), err
	}
	results := make(map[int]string)
	for rawServiceName, serviceConfig := range parsed.Services {
		host := strings.TrimSpace(serviceConfig["host"].(string))

		_, exists := ipMap[host]
		if exists {
			name := strings.Split(rawServiceName, ".")[0]
			port := config.GetAsInt(serviceConfig["port"], -1)
			if port != -1 {
				results[port] = name
			} else {
				n.log.Warn("Failed to get port from value ", serviceConfig["port"])
			}
		}
	}

	return results, nil
}
コード例 #7
0
ファイル: signalfx.go プロジェクト: jaxxstorm/fullerite
// Configure accepts the different configuration options for the signalfx handler
func (s *SignalFx) Configure(configMap map[string]interface{}) {
	if authToken, exists := configMap["authToken"]; exists == true {
		s.authToken = authToken.(string)
	} else {
		s.log.Error("There was no auth key specified for the SignalFx Handler, there won't be any emissions")
	}
	if endpoint, exists := configMap["endpoint"]; exists == true {
		s.endpoint = endpoint.(string)
	} else {
		s.log.Error("There was no endpoint specified for the SignalFx Handler, there won't be any emissions")
	}
	if timeout, exists := configMap["timeout"]; exists == true {
		val, err := config.GetAsFloat(timeout)
		if err != nil {
			s.log.Error("Failed to parse the value", timeout, "into a float")
		} else {
			s.timeout = time.Duration(val) * time.Second
		}
	}
	if bufferSize, exists := configMap["max_buffer_size"]; exists == true {
		val, err := config.GetAsInt(bufferSize)
		if err != nil {
			s.log.Error("Failed to parse the value", bufferSize, "into an int")
		} else {
			s.maxBufferSize = val
		}
	}
}
コード例 #8
0
ファイル: docker_stats.go プロジェクト: yeled/fullerite
// Configure takes a dictionary of values with which the handler can configure itself.
func (d *DockerStats) Configure(configMap map[string]interface{}) {
	d.configureCommonParams(configMap)
	if timeout, exists := configMap["dockerStatsTimeout"]; exists {
		d.statsTimeout = min(config.GetAsInt(timeout, d.interval), d.interval)
	} else {
		d.statsTimeout = d.interval
	}
}
コード例 #9
0
func (srv *InternalServer) configure(cfgMap map[string]interface{}) {

	if val, exists := (cfgMap)["port"]; exists {
		srv.port = config.GetAsInt(val, defaultPort)
	} else {
		srv.port = defaultPort
	}

	if val, exists := (cfgMap)["path"]; exists {
		srv.path = val.(string)
	} else {
		srv.path = defaultMetricsPath
	}
}
コード例 #10
0
ファイル: handler.go プロジェクト: Yelp/fullerite
func getCollectorBatchSize(collectorName string,
	globalConfig config.Config,
	defaultBufSize int) (result int) {
	conf, err := globalConfig.GetCollectorConfig(collectorName)
	result = defaultBufSize
	if err != nil {
		return
	}

	if bufferSize, exists := conf["max_buffer_size"]; exists {
		result = config.GetAsInt(bufferSize, defaultBufSize)
	}
	return
}
コード例 #11
0
ファイル: scribe.go プロジェクト: sagar8192/fullerite
// Configure accepts the different configuration options for the Scribe handler
func (s *Scribe) Configure(configMap map[string]interface{}) {
	if endpoint, exists := configMap["endpoint"]; exists {
		s.endpoint = endpoint.(string)
	}

	if port, exists := configMap["port"]; exists {
		s.port = config.GetAsInt(port, defaultScribePort)
	}

	if stream, exists := configMap["streamName"]; exists {
		s.streamName = stream.(string)
	}

	s.configureCommonParams(configMap)
}
コード例 #12
0
ファイル: collectors.go プロジェクト: gsalisbury/fullerite
func startCollector(name string, globalConfig config.Config, instanceConfig map[string]interface{}) collector.Collector {
	log.Debug("Starting collector ", name)
	collectorInst := collector.New(name)
	if collectorInst == nil {
		return nil
	}

	// apply the global configs
	collectorInst.SetInterval(config.GetAsInt(globalConfig.Interval, collector.DefaultCollectionInterval))

	// apply the instance configs
	collectorInst.Configure(instanceConfig)

	go runCollector(collectorInst)
	return collectorInst
}
コード例 #13
0
ファイル: collector.go プロジェクト: Yelp/fullerite
func (col *baseCollector) configureCommonParams(configMap map[string]interface{}) {
	if interval, exists := configMap["interval"]; exists {
		col.interval = config.GetAsInt(interval, DefaultCollectionInterval)
	}

	if prefix, exists := configMap["prefix"]; exists {
		if str, ok := prefix.(string); ok {
			col.prefix = str
		}
	}

	if asInterface, exists := configMap["metrics_blacklist"]; exists {
		col.blacklist = config.GetAsSlice(asInterface)
	}

}
コード例 #14
0
// Rewrites config variables from the global config
func (n *uWSGINerveWorkerStatsCollector) Configure(configMap map[string]interface{}) {
	if val, exists := configMap["queryPath"]; exists {
		n.queryPath = val.(string)
	}
	if val, exists := configMap["configFilePath"]; exists {
		n.configFilePath = val.(string)
	}
	if val, exists := configMap["servicesWhitelist"]; exists {
		n.servicesWhitelist = config.GetAsSlice(val)
	}

	if val, exists := configMap["http_timeout"]; exists {
		n.timeout = config.GetAsInt(val, 2)
	}

	n.configureCommonParams(configMap)
}
コード例 #15
0
ファイル: handlers.go プロジェクト: carriercomm/fullerite
func startHandler(name string, globalConfig config.Config, instanceConfig map[string]interface{}) handler.Handler {
	log.Info("Starting handler ", name)
	handlerInst := handler.New(name)
	if handlerInst == nil {
		return nil
	}

	// apply any global configs
	handlerInst.SetInterval(config.GetAsInt(globalConfig.Interval, handler.DefaultInterval))
	handlerInst.SetPrefix(globalConfig.Prefix)
	handlerInst.SetDefaultDimensions(globalConfig.DefaultDimensions)

	// now apply the handler level configs
	handlerInst.Configure(instanceConfig)

	go handlerInst.Run()
	return handlerInst
}
コード例 #16
0
ファイル: handlers.go プロジェクト: Yelp/fullerite
func createHandler(name string, globalConfig config.Config, instanceConfig map[string]interface{}) handler.Handler {
	handlerInst := handler.New(name)
	if handlerInst == nil {
		return nil
	}

	// apply any global configs
	handlerInst.SetInterval(config.GetAsInt(globalConfig.Interval, handler.DefaultInterval))
	handlerInst.SetPrefix(globalConfig.Prefix)
	handlerInst.SetDefaultDimensions(globalConfig.DefaultDimensions)

	// now apply the handler level configs
	handlerInst.Configure(instanceConfig)

	// now run a listener channel for each collector
	handlerInst.InitListeners(globalConfig)

	return handlerInst
}
コード例 #17
0
ファイル: nerve_httpd.go プロジェクト: venkey-ariv/fullerite
// Configure the collector
func (c *NerveHTTPD) Configure(configMap map[string]interface{}) {
	if val, exists := configMap["queryPath"]; exists {
		c.queryPath = val.(string)
	}
	if val, exists := configMap["configFilePath"]; exists {
		c.configFilePath = val.(string)
	}

	if val, exists := configMap["host"]; exists {
		c.host = val.(string)
	}

	if val, exists := configMap["status_ttl"]; exists {
		tmpStatusTTL := config.GetAsInt(val, 3600)
		c.statusTTL = time.Duration(tmpStatusTTL) * time.Second
	}

	c.configureCommonParams(configMap)
}
コード例 #18
0
ファイル: docker_stats.go プロジェクト: sagar8192/fullerite
// Configure takes a dictionary of values with which the handler can configure itself.
func (d *DockerStats) Configure(configMap map[string]interface{}) {
	if timeout, exists := configMap["dockerStatsTimeout"]; exists {
		d.statsTimeout = min(config.GetAsInt(timeout, d.interval), d.interval)
	} else {
		d.statsTimeout = d.interval
	}
	if generatedDimensions, exists := configMap["generatedDimensions"]; exists {
		for dimension, generator := range generatedDimensions.(map[string]interface{}) {
			for key, regx := range config.GetAsMap(generator) {
				re, err := regexp.Compile(regx)
				if err != nil {
					d.log.Warn("Failed to compile regex: ", regx, err)
				} else {
					d.compiledRegex[dimension] = &Regex{regex: re, tag: key}
				}
			}
		}
	}
	d.configureCommonParams(configMap)
}
コード例 #19
0
ファイル: collector.go プロジェクト: yeled/fullerite
func (col *baseCollector) configureCommonParams(configMap map[string]interface{}) {
	if interval, exists := configMap["interval"]; exists {
		col.interval = config.GetAsInt(interval, DefaultCollectionInterval)
	}
}
コード例 #20
0
// Configure takes a dictionary of values with which the handler can configure itself.
func (d *DockerStats) Configure(configMap map[string]interface{}) {
	if timeout, exists := configMap["dockerStatsTimeout"]; exists {
		d.statsTimeout = config.GetAsInt(timeout, defaultStatsTimeout)
	}
	d.configureCommonParams(configMap)
}