예제 #1
0
파일: smem.go 프로젝트: Yelp/fullerite
// Configure Override *baseCollector.Configure(); will fetch the whitelisted processes
func (s *SmemStats) Configure(configMap map[string]interface{}) {
	s.configureCommonParams(configMap)

	if user, exists := configMap["user"]; exists {
		s.user = user.(string)
	} else {
		s.log.Warn("Required config does not exist for SmemStats: user")
	}

	if whitelist, exists := configMap["procsWhitelist"]; exists {
		s.whitelistedProcs = whitelist.(string)
	} else {
		s.log.Warn("Required config does not exist for SmemStats: procsWhitelist")
	}

	if smemPath, exists := configMap["smemPath"]; exists {
		s.smemPath = smemPath.(string)
	} else {
		s.log.Warn("Required config does not exist for SmemStats: smemPath")
	}

	if blacklist, exists := configMap["metricsBlacklist"]; exists {
		s.whitelistedMetrics = getWhitelistedMetrics(config.GetAsSlice(blacklist))
	} else {
		s.whitelistedMetrics = allMetrics
	}

	if dimensionsFromCmdline, exists := configMap["dimensionsFromCmdline"]; exists {
		s.dimensionsFromCmdline = config.GetAsMap(dimensionsFromCmdline)
	}

	if dimensionsFromEnv, exists := configMap["dimensionsFromEnv"]; exists {
		s.dimensionsFromEnv = config.GetAsMap(dimensionsFromEnv)
	}
}
예제 #2
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))
	}
}
예제 #3
0
// Configure this takes a dictionary of values with which the handler can configure itself
func (ps *ProcStatus) Configure(configMap map[string]interface{}) {
	if pattern, exists := configMap["pattern"]; exists {
		re, err := regexp.Compile(pattern.(string))
		if err != nil {
			ps.log.Warn("Failed to compile regex: ", err)
		} else {
			ps.pattern = re
		}
	}

	if matchCommandLine, exists := configMap["matchCommandLine"]; exists {
		ps.matchCommandLine = matchCommandLine.(bool)
	}

	if generatedDimensions, exists := configMap["generatedDimensions"]; exists {
		for dimension, generator := range config.GetAsMap(generatedDimensions) {
			//don't use MustCompile otherwise program will panic due to misformated regex
			re, err := regexp.Compile(generator)
			if err != nil {
				ps.log.Warn("Failed to compile regex: ", generator, err)
			} else {
				ps.compiledRegex[dimension] = re
			}
		}
	}

	ps.configureCommonParams(configMap)
}
예제 #4
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)
	}
}
예제 #5
0
func TestGetAsMap(t *testing.T) {
	assert := assert.New(t)

	// Test if string can be converted to map[string]string
	stringToParse := "{\"runtimeenv\" : \"dev\", \"region\":\"uswest1-devc\"}"
	expectedValue := map[string]string{
		"runtimeenv": "dev",
		"region":     "uswest1-devc",
	}
	assert.Equal(config.GetAsMap(stringToParse), expectedValue)

	// Test if map[string]interface{} can be converted to map[string]string
	interfaceMapToParse := make(map[string]interface{})
	interfaceMapToParse["runtimeenv"] = "dev"
	interfaceMapToParse["region"] = "uswest1-devc"
	assert.Equal(config.GetAsMap(interfaceMapToParse), expectedValue)
}
예제 #6
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)
	}
}
예제 #7
0
// Configure Override *baseCollector.Configure(). Will create the required MesosLeaderElect instance.
func (m *MesosStats) Configure(configMap map[string]interface{}) {
	m.configureCommonParams(configMap)

	c := config.GetAsMap(configMap)
	if mesosNodes, exists := c["mesosNodes"]; exists && len(mesosNodes) > 0 {
		m.mesosCache = newMLE()
		m.mesosCache.Configure(mesosNodes, cacheTimeout)
	} else {
		m.log.Error("Require configuration not found: mesosNodes")
		return
	}
}
예제 #8
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)
}