示例#1
0
// 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
// 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
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
// 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
// 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
// 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
// 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
// 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
	}
}
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
// 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
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
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
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
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
// 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
// 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
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)
}