Search in sources :

Example 16 with MonitorConfig

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;
}
Also used : MonitorFactory(org.apache.dubbo.monitor.MonitorFactory) HashMap(java.util.HashMap) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) MonitorService(org.apache.dubbo.monitor.MonitorService) MonitorConfig(org.apache.dubbo.config.MonitorConfig)

Aggregations

MonitorConfig (org.apache.dubbo.config.MonitorConfig)16 Test (org.junit.jupiter.api.Test)11 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)5 RegistryConfig (org.apache.dubbo.config.RegistryConfig)4 ModuleConfig (org.apache.dubbo.config.ModuleConfig)3 MonitorService (org.apache.dubbo.monitor.MonitorService)2 HashMap (java.util.HashMap)1 URL (org.apache.dubbo.common.URL)1 AbstractInterfaceConfig (org.apache.dubbo.config.AbstractInterfaceConfig)1 AbstractInterfaceConfigTest (org.apache.dubbo.config.AbstractInterfaceConfigTest)1 ConfigCenterConfig (org.apache.dubbo.config.ConfigCenterConfig)1 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)1 MetadataReportConfig (org.apache.dubbo.config.MetadataReportConfig)1 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)1 ProviderConfig (org.apache.dubbo.config.ProviderConfig)1 MonitorFactory (org.apache.dubbo.monitor.MonitorFactory)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1