Java public static void initializeCoreConfig(String agentOptions) {
// AGENT_SETTINGS 为Properties类变量 AGENT_SETTINGS = new Properties(); // 加载默认配置:config/agent.config,解析读入至AGENT_SETTINGS变量中 try (final InputStreamReader configFileStream = loadConfig()) {
AGENT_SETTINGS.load(configFileStream); for (String key : AGENT_SETTINGS.stringPropertyNames()) {
String value = (String) AGENT_SETTINGS.get(key); AGENT_SETTINGS.put(key, PropertyPlaceholderHelper.INSTANCE.replacePlaceholders(value, AGENT_SETTINGS)); }
} catch (Exception e) {
LOGGER.error(e, "Failed to read the config file, skywalking is going to run in default config."); } // 读取可能存在的system properties,覆盖默认配置 try {
overrideConfigBySystemProp(); } catch (Exception e) {
LOGGER.error(e, "Failed to read the system properties."); } // 读取agentArgs可能传入的参数,覆盖默认配置 agentOptions = StringUtil.trim(agentOptions, ','); if (!StringUtil.isEmpty(agentOptions)) {
try {
agentOptions = agentOptions.trim(); LOGGER.info("Agent options is {}.", agentOptions);
overrideConfigByAgentOptions(agentOptions); } catch (Exception e) {
LOGGER.error(e, "Failed to parse the agent options, val is {}.", agentOptions); } }
if (StringUtil.isEmpty(Config.Agent.SERVICE_NAME)) {
throw new ExceptionInInitializerError("`agent.service_name` is missing."); } if (StringUtil.isEmpty(Config.Collector.BACKEND_SERVICE)) {
throw new ExceptionInInitializerError("`collector.backend_service` is missing."); } if (Config.Plugin.PEER_MAX_LENGTH <= 3) {
LOGGER.warn( "PEER_MAX_LENGTH configuration:{} error, the default value of 200 will be used.", Config.Plugin.PEER_MAX_LENGTH ); Config.Plugin.PEER_MAX_LENGTH = 200; }