Search in sources :

Example 1 with Monitor

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

the class MonitorFilter method collect.

/**
 * The collector logic, it will be handled by the default monitor
 *
 * @param invoker
 * @param invocation
 * @param result     the invoke result
 * @param remoteHost the remote host address
 * @param start      the timestamp the invoke begin
 * @param error      if there is an error on the invoke
 */
private void collect(Invoker<?> invoker, Invocation invocation, Result result, String remoteHost, long start, boolean error) {
    try {
        URL monitorUrl = invoker.getUrl().getUrlParameter(MONITOR_KEY);
        Monitor monitor = monitorFactory.getMonitor(monitorUrl);
        if (monitor == null) {
            return;
        }
        URL statisticsURL = createStatisticsUrl(invoker, invocation, result, remoteHost, start, error);
        monitor.collect(statisticsURL);
    } catch (Throwable t) {
        logger.warn("Failed to monitor count service " + invoker.getUrl() + ", cause: " + t.getMessage(), t);
    }
}
Also used : Monitor(org.apache.dubbo.monitor.Monitor) URL(org.apache.dubbo.common.URL)

Example 2 with Monitor

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

the class AbstractMonitorFactoryTest method testMonitorFactoryGroupCache.

@Test
public void testMonitorFactoryGroupCache() throws Exception {
    URL url1 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":2233?group=aaa");
    URL url2 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":2233?group=bbb");
    Monitor monitor1 = monitorFactory.getMonitor(url1);
    Monitor monitor2 = monitorFactory.getMonitor(url2);
    if (monitor1 == null || monitor2 == null) {
        Thread.sleep(2000);
        monitor1 = monitorFactory.getMonitor(url1);
        monitor2 = monitorFactory.getMonitor(url2);
    }
    Assertions.assertNotSame(monitor1, monitor2);
}
Also used : Monitor(org.apache.dubbo.monitor.Monitor) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 3 with Monitor

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

the class AbstractMonitorFactoryTest method testMonitorFactoryCache.

@Test
public void testMonitorFactoryCache() throws Exception {
    URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":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 4 with Monitor

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

the class MonitorFilterTest method testSafeFailForMonitorCollectFail.

@Test
public void testSafeFailForMonitorCollectFail() {
    MonitorFilter monitorFilter = new MonitorFilter();
    MonitorFactory mockMonitorFactory = mock(MonitorFactory.class);
    Monitor mockMonitor = mock(Monitor.class);
    Mockito.doThrow(new RuntimeException()).when(mockMonitor).collect(any(URL.class));
    monitorFilter.setMonitorFactory(mockMonitorFactory);
    given(mockMonitorFactory.getMonitor(any(URL.class))).willReturn(mockMonitor);
    Invocation invocation = new RpcInvocation("aaa", MonitorService.class.getName(), "", new Class<?>[0], new Object[0]);
    monitorFilter.invoke(serviceInvoker, invocation);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Monitor(org.apache.dubbo.monitor.Monitor) MonitorFactory(org.apache.dubbo.monitor.MonitorFactory) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) MonitorService(org.apache.dubbo.monitor.MonitorService) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 5 with Monitor

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

the class DubboMonitorTest method testMonitorFactory.

@Test
public void testMonitorFactory() throws Exception {
    MockMonitorService monitorService = new MockMonitorService();
    URL statistics = new URLBuilder(DUBBO_PROTOCOL, "10.20.153.10", 0).addParameter(MonitorService.APPLICATION, "morgan").addParameter(MonitorService.INTERFACE, "MemberService").addParameter(MonitorService.METHOD, "findPerson").addParameter(MonitorService.CONSUMER, "10.20.153.11").addParameter(MonitorService.SUCCESS, 1).addParameter(MonitorService.FAILURE, 0).addParameter(MonitorService.ELAPSED, 3).addParameter(MonitorService.MAX_ELAPSED, 3).addParameter(MonitorService.CONCURRENT, 1).addParameter(MonitorService.MAX_CONCURRENT, 1).build();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    MonitorFactory monitorFactory = ExtensionLoader.getExtensionLoader(MonitorFactory.class).getAdaptiveExtension();
    Exporter<MonitorService> exporter = protocol.export(proxyFactory.getInvoker(monitorService, MonitorService.class, URL.valueOf("dubbo://127.0.0.1:17979/" + MonitorService.class.getName())));
    try {
        Monitor monitor = null;
        long start = System.currentTimeMillis();
        while (System.currentTimeMillis() - start < 60000) {
            monitor = monitorFactory.getMonitor(URL.valueOf("dubbo://127.0.0.1:17979?interval=10"));
            if (monitor == null) {
                continue;
            }
            try {
                monitor.collect(statistics);
                int i = 0;
                while (monitorService.getStatistics() == null && i < 200) {
                    i++;
                    Thread.sleep(10);
                }
                URL result = monitorService.getStatistics();
                Assertions.assertEquals(1, result.getParameter(MonitorService.SUCCESS, 0));
                Assertions.assertEquals(3, result.getParameter(MonitorService.ELAPSED, 0));
            } finally {
                monitor.destroy();
            }
            break;
        }
        Assertions.assertNotNull(monitor);
    } finally {
        exporter.unexport();
    }
}
Also used : Monitor(org.apache.dubbo.monitor.Monitor) MonitorFactory(org.apache.dubbo.monitor.MonitorFactory) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) MonitorService(org.apache.dubbo.monitor.MonitorService) Protocol(org.apache.dubbo.rpc.Protocol) URL(org.apache.dubbo.common.URL) URLBuilder(org.apache.dubbo.common.URLBuilder) 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