Search in sources :

Example 6 with Monitor

use of org.apache.dubbo.monitor.Monitor in project dubbo by alibaba.

the class AbstractMonitorFactory method getMonitor.

@Override
public Monitor getMonitor(URL url) {
    url = url.setPath(MonitorService.class.getName()).addParameter(INTERFACE_KEY, MonitorService.class.getName());
    String key = url.toServiceStringWithoutResolving();
    Monitor monitor = MONITORS.get(key);
    Future<Monitor> future = FUTURES.get(key);
    if (monitor != null || future != null) {
        return monitor;
    }
    LOCK.lock();
    try {
        monitor = MONITORS.get(key);
        future = FUTURES.get(key);
        if (monitor != null || future != null) {
            return monitor;
        }
        final URL monitorUrl = url;
        future = EXECUTOR.submit(() -> {
            try {
                Monitor m = createMonitor(monitorUrl);
                MONITORS.put(key, m);
                FUTURES.remove(key);
                return m;
            } catch (Throwable e) {
                logger.warn("Create monitor failed, monitor data will not be collected until you fix this problem. monitorUrl: " + monitorUrl, e);
                return null;
            }
        });
        FUTURES.put(key, future);
        return null;
    } finally {
        // unlock
        LOCK.unlock();
    }
}
Also used : Monitor(org.apache.dubbo.monitor.Monitor) MonitorService(org.apache.dubbo.monitor.MonitorService) URL(org.apache.dubbo.common.URL)

Example 7 with Monitor

use of org.apache.dubbo.monitor.Monitor in project dubbo by alibaba.

the class AbstractMonitorFactoryTest method testMonitorFactoryIpCache.

@Test
public void testMonitorFactoryIpCache() throws Exception {
    URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":2233");
    Monitor monitor1 = monitorFactory.getMonitor(url);
    Monitor monitor2 = monitorFactory.getMonitor(url);
    if (monitor1 == null || monitor2 == null) {
        Thread.sleep(2000);
        monitor1 = monitorFactory.getMonitor(url);
        monitor2 = monitorFactory.getMonitor(url);
    }
    Assertions.assertEquals(monitor1, monitor2);
}
Also used : Monitor(org.apache.dubbo.monitor.Monitor) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 8 with Monitor

use of org.apache.dubbo.monitor.Monitor in project dubbo by alibaba.

the class DubboMonitorFactoryTest method testCreateMonitor.

@Test
public void testCreateMonitor() {
    URL urlWithoutPath = URL.valueOf("http://10.10.10.11");
    Monitor monitor = dubboMonitorFactory.createMonitor(urlWithoutPath);
    assertThat(monitor, not(nullValue()));
    URL urlWithFilterKey = URL.valueOf("http://10.10.10.11/").addParameter(REFERENCE_FILTER_KEY, "testFilter");
    monitor = dubboMonitorFactory.createMonitor(urlWithFilterKey);
    assertThat(monitor, not(nullValue()));
    ArgumentCaptor<Invoker> invokerArgumentCaptor = ArgumentCaptor.forClass(Invoker.class);
    verify(proxyFactory, atLeastOnce()).getProxy(invokerArgumentCaptor.capture());
    Invoker invoker = invokerArgumentCaptor.getValue();
    assertThat(invoker.getUrl().getParameter(REFERENCE_FILTER_KEY), containsString("testFilter"));
}
Also used : Monitor(org.apache.dubbo.monitor.Monitor) Invoker(org.apache.dubbo.rpc.Invoker) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Aggregations

URL (org.apache.dubbo.common.URL)8 Monitor (org.apache.dubbo.monitor.Monitor)8 Test (org.junit.jupiter.api.Test)6 MonitorService (org.apache.dubbo.monitor.MonitorService)3 MonitorFactory (org.apache.dubbo.monitor.MonitorFactory)2 URLBuilder (org.apache.dubbo.common.URLBuilder)1 Invocation (org.apache.dubbo.rpc.Invocation)1 Invoker (org.apache.dubbo.rpc.Invoker)1 Protocol (org.apache.dubbo.rpc.Protocol)1 ProxyFactory (org.apache.dubbo.rpc.ProxyFactory)1 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)1