use of org.apache.dubbo.config.MonitorConfig in project dubbo by alibaba.
the class ConfigValidationUtils method loadMonitor.
public static URL loadMonitor(AbstractInterfaceConfig interfaceConfig, URL registryURL) {
Map<String, String> map = new HashMap<String, String>();
map.put(INTERFACE_KEY, MonitorService.class.getName());
AbstractInterfaceConfig.appendRuntimeParameters(map);
// set ip
String hostToRegistry = ConfigUtils.getSystemProperty(DUBBO_IP_TO_REGISTRY);
if (StringUtils.isEmpty(hostToRegistry)) {
hostToRegistry = NetUtils.getLocalHost();
} else if (NetUtils.isInvalidLocalHost(hostToRegistry)) {
throw new IllegalArgumentException("Specified invalid registry ip from property:" + DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry);
}
map.put(REGISTER_IP_KEY, hostToRegistry);
MonitorConfig monitor = interfaceConfig.getMonitor();
ApplicationConfig application = interfaceConfig.getApplication();
AbstractConfig.appendParameters(map, monitor);
AbstractConfig.appendParameters(map, application);
String address = null;
String sysaddress = System.getProperty(DUBBO_MONITOR_ADDRESS);
if (sysaddress != null && sysaddress.length() > 0) {
address = sysaddress;
} else if (monitor != null) {
address = monitor.getAddress();
}
if (ConfigUtils.isNotEmpty(address)) {
if (!map.containsKey(PROTOCOL_KEY)) {
if (getExtensionLoader(MonitorFactory.class).hasExtension(LOGSTAT_PROTOCOL)) {
map.put(PROTOCOL_KEY, LOGSTAT_PROTOCOL);
} else {
map.put(PROTOCOL_KEY, DUBBO_PROTOCOL);
}
}
return UrlUtils.parseURL(address, map);
} else if (monitor != null && (REGISTRY_PROTOCOL.equals(monitor.getProtocol()) || SERVICE_REGISTRY_PROTOCOL.equals(monitor.getProtocol())) && registryURL != null) {
return URLBuilder.from(registryURL).setProtocol(DUBBO_PROTOCOL).addParameter(PROTOCOL_KEY, monitor.getProtocol()).addParameterAndEncoded(REFER_KEY, StringUtils.toQueryString(map)).build();
}
return null;
}
Aggregations