Beispiel #1
0
func TestGetAsSlice(t *testing.T) {
	assert := assert.New(t)

	// Test if string array can be converted to []string
	stringToParse := "[\"TestCollector1\", \"TestCollector2\"]"
	expectedValue := []string{"TestCollector1", "TestCollector2"}
	assert.Equal(config.GetAsSlice(stringToParse), expectedValue)

	sliceToParse := []string{"TestCollector1", "TestCollector2"}
	assert.Equal(config.GetAsSlice(sliceToParse), expectedValue)
}
Beispiel #2
0
// 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)
	}
}
Beispiel #3
0
// Configure Override default parameters
func (ss *SocketQueue) Configure(configMap map[string]interface{}) {
	ss.configureCommonParams(configMap)
	if asInterface, exists := configMap["PortList"]; exists {
		ss.portList = config.GetAsSlice(asInterface)
	} else {
		ss.log.Warn("Required config 'PortList' does not exist")
	}
}
Beispiel #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)
	}

	if asInterface, exists := configMap["collectorBlackList"]; exists {
		blackList := config.GetAsSlice(asInterface)
		base.SetCollectorBlackList(blackList)
	}

	if asInterface, exists := configMap["collectorWhiteList"]; exists {
		whiteList := config.GetAsSlice(asInterface)
		base.SetCollectorWhiteList(whiteList)
	}
}
Beispiel #5
0
func (n *nerveUWSGICollector) 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)
	}

	n.configureCommonParams(configMap)
}
Beispiel #6
0
func TestGetAsSliceFromJson(t *testing.T) {
	var data interface{}
	jsonString := []byte(`{"listOfStrings": ["a", "b", "c"]}`)

	err := json.Unmarshal(jsonString, &data)
	assert.Nil(t, err)

	if err == nil {
		temp := data.(map[string]interface{})

		res := config.GetAsSlice(temp["listOfStrings"])
		assert.Equal(t, []string{"a", "b", "c"}, res)
	}
}
Beispiel #7
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)
	}

}
// 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)
}
Beispiel #9
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
	}

	if val, exists := configMap["servicesWhitelist"]; exists {
		c.servicesWhitelist = config.GetAsSlice(val)
	}

	c.configureCommonParams(configMap)
}