Java Code Examples for com.alibaba.dubbo.monitor.MonitorService

The following examples show how to use com.alibaba.dubbo.monitor.MonitorService. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dubbo-2.6.5   Source File: MonitorFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("aaa", new Class<?>[0], new Object[0]);
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("aaa", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
 
Example 2
Source Project: dubbo-2.6.5   Source File: MonitorFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("$invoke", new Class<?>[]{String.class, String[].class, Object[].class}, new Object[]{"xxx", new String[]{}, new Object[]{}});
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("xxx", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
 
Example 3
Source Project: dubbo-2.6.5   Source File: DubboMonitor.java    License: Apache License 2.0 6 votes vote down vote up
public DubboMonitor(Invoker<MonitorService> monitorInvoker, MonitorService monitorService) {
    this.monitorInvoker = monitorInvoker;
    this.monitorService = monitorService;
    this.monitorInterval = monitorInvoker.getUrl().getPositiveParameter("interval", 60000);
    // collect timer for collecting statistics data
    sendFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
        @Override
        public void run() {
            // collect data
            try {
                send();
            } catch (Throwable t) {
                logger.error("Unexpected error occur at send statistic, cause: " + t.getMessage(), t);
            }
        }
    }, monitorInterval, monitorInterval, TimeUnit.MILLISECONDS);
}
 
Example 4
Source Project: dubbo-2.6.5   Source File: DubboMonitorFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false),
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
Example 5
Source Project: dubbox   Source File: AbstractMonitorFactory.java    License: Apache License 2.0 6 votes vote down vote up
public Monitor getMonitor(URL url) {
	url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
	String key = url.toServiceString();
    LOCK.lock();
    try {
        Monitor monitor = MONITORS.get(key);
        if (monitor != null) {
            return monitor;
        }
        monitor = createMonitor(url);
        if (monitor == null) {
            throw new IllegalStateException("Can not create monitor " + url);
        }
        MONITORS.put(key, monitor);
        return monitor;
    } finally {
        // 释放锁
        LOCK.unlock();
    }
}
 
Example 6
Source Project: dubbox   Source File: MonitorFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("aaa", new Class<?>[0], new Object[0]);
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("aaa", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
 
Example 7
Source Project: dubbox-hystrix   Source File: AbstractMonitorFactory.java    License: Apache License 2.0 6 votes vote down vote up
public Monitor getMonitor(URL url) {
	url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
	String key = url.toServiceString();
    LOCK.lock();
    try {
        Monitor monitor = MONITORS.get(key);
        if (monitor != null) {
            return monitor;
        }
        monitor = createMonitor(url);
        if (monitor == null) {
            throw new IllegalStateException("Can not create monitor " + url);
        }
        MONITORS.put(key, monitor);
        return monitor;
    } finally {
        // 释放锁
        LOCK.unlock();
    }
}
 
Example 8
Source Project: dubbox-hystrix   Source File: MonitorFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("$invoke", new Class<?>[] { String.class, String[].class, Object[].class }, new Object[] { "xxx", new String[] {}, new Object[] {} } );
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("xxx", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
 
Example 9
Source Project: dubbox   Source File: MonitorFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("aaa", new Class<?>[0], new Object[0]);
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("aaa", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
 
Example 10
Source Project: dubbox-hystrix   Source File: DubboMonitorFactroy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
Example 11
Source Project: dubbox   Source File: DubboMonitorFactroy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
Example 12
Source Project: dubbo3   Source File: AbstractMonitorFactory.java    License: Apache License 2.0 6 votes vote down vote up
public Monitor getMonitor(URL url) {
	url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
	String key = url.toServiceString();
    LOCK.lock();
    try {
        Monitor monitor = MONITORS.get(key);
        if (monitor != null) {
            return monitor;
        }
        monitor = createMonitor(url);
        if (monitor == null) {
            throw new IllegalStateException("Can not create monitor " + url);
        }
        MONITORS.put(key, monitor);
        return monitor;
    } finally {
        // 释放锁
        LOCK.unlock();
    }
}
 
Example 13
Source Project: dubbo3   Source File: MonitorFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("aaa", new Class<?>[0], new Object[0]);
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("aaa", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
 
Example 14
Source Project: dubbo3   Source File: MonitorFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("$invoke", new Class<?>[] { String.class, String[].class, Object[].class }, new Object[] { "xxx", new String[] {}, new Object[] {} } );
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("xxx", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
 
Example 15
Source Project: dubbox   Source File: AbstractMonitorFactory.java    License: Apache License 2.0 6 votes vote down vote up
public Monitor getMonitor(URL url) {
	url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
	String key = url.toServiceString();
    LOCK.lock();
    try {
        Monitor monitor = MONITORS.get(key);
        if (monitor != null) {
            return monitor;
        }
        monitor = createMonitor(url);
        if (monitor == null) {
            throw new IllegalStateException("Can not create monitor " + url);
        }
        MONITORS.put(key, monitor);
        return monitor;
    } finally {
        // 释放锁
        LOCK.unlock();
    }
}
 
Example 16
Source Project: dubbox   Source File: DubboMonitorFactroy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
Example 17
Source Project: dubbo3   Source File: DubboMonitorFactroy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Monitor createMonitor(URL url) {
    url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
    if (url.getPath() == null || url.getPath().length() == 0) {
        url = url.setPath(MonitorService.class.getName());
    }
    String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
    if (filter == null || filter.length() == 0) {
        filter = "";
    } else {
        filter = filter + ",";
    }
    url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false), 
            Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
    Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
    MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
    return new DubboMonitor(monitorInvoker, monitorService);
}
 
Example 18
Source Project: dubbox   Source File: DubboMonitor.java    License: Apache License 2.0 6 votes vote down vote up
public DubboMonitor(Invoker<MonitorService> monitorInvoker, MonitorService monitorService) {
    this.monitorInvoker = monitorInvoker;
    this.monitorService = monitorService;
    this.monitorInterval = monitorInvoker.getUrl().getPositiveParameter("interval", 60000);
    // 启动统计信息收集定时器
    sendFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
        public void run() {
            // 收集统计信息
            try {
                send();
            } catch (Throwable t) { // 防御性容错
                logger.error("Unexpected error occur at send statistic, cause: " + t.getMessage(), t);
            }
        }
    }, monitorInterval, monitorInterval, TimeUnit.MILLISECONDS);
}
 
Example 19
Source Project: dubbox   Source File: AbstractMonitorFactory.java    License: Apache License 2.0 6 votes vote down vote up
public Monitor getMonitor(URL url) {
	url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
	String key = url.toServiceString();
    LOCK.lock();
    try {
        Monitor monitor = MONITORS.get(key);
        if (monitor != null) {
            return monitor;
        }
        monitor = createMonitor(url);
        if (monitor == null) {
            throw new IllegalStateException("Can not create monitor " + url);
        }
        MONITORS.put(key, monitor);
        return monitor;
    } finally {
        // 释放锁
        LOCK.unlock();
    }
}
 
Example 20
Source Project: dubbox   Source File: MonitorFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("aaa", new Class<?>[0], new Object[0]);
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("aaa", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
 
Example 21
Source Project: dubbox   Source File: MonitorFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericFilter() throws Exception {
    MonitorFilter monitorFilter = new MonitorFilter();
    monitorFilter.setMonitorFactory(monitorFactory);
    Invocation invocation = new RpcInvocation("$invoke", new Class<?>[] { String.class, String[].class, Object[].class }, new Object[] { "xxx", new String[] {}, new Object[] {} } );
    RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
    monitorFilter.invoke(serviceInvoker, invocation);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals("abc", lastStatistics.getParameter(MonitorService.APPLICATION));
    Assert.assertEquals(MonitorService.class.getName(), lastStatistics.getParameter(MonitorService.INTERFACE));
    Assert.assertEquals("xxx", lastStatistics.getParameter(MonitorService.METHOD));
    Assert.assertEquals(NetUtils.getLocalHost() + ":20880", lastStatistics.getParameter(MonitorService.PROVIDER));
    Assert.assertEquals(NetUtils.getLocalHost(), lastStatistics.getAddress());
    Assert.assertEquals(null, lastStatistics.getParameter(MonitorService.CONSUMER));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.SUCCESS, 0));
    Assert.assertEquals(0, lastStatistics.getParameter(MonitorService.FAILURE, 0));
    Assert.assertEquals(1, lastStatistics.getParameter(MonitorService.CONCURRENT, 0));
    Assert.assertEquals(invocation, lastInvocation);
}
 
Example 22
Source Project: dubbo-2.6.5   Source File: AbstractInterfaceConfigTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLoadMonitor() throws Exception {
    System.setProperty("dubbo.monitor.address", "monitor-addr:12080");
    System.setProperty("dubbo.monitor.protocol", "monitor");
    InterfaceConfig interfaceConfig = new InterfaceConfig();
    URL url = interfaceConfig.loadMonitor(new URL("dubbo", "addr1", 9090));
    TestCase.assertEquals("monitor-addr:12080", url.getAddress());
    TestCase.assertEquals(MonitorService.class.getName(), url.getParameter("interface"));
    TestCase.assertNotNull(url.getParameter("dubbo"));
    TestCase.assertNotNull(url.getParameter("pid"));
    TestCase.assertNotNull(url.getParameter("timestamp"));
}
 
Example 23
Source Project: dubbo-2.6.5   Source File: AbstractMonitorFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Monitor getMonitor(URL url) {
    url = url.setPath(MonitorService.class.getName()).addParameter(Constants.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;
        final ListenableFutureTask<Monitor> listenableFutureTask = ListenableFutureTask.create(new MonitorCreator(monitorUrl));
        listenableFutureTask.addListener(new MonitorListener(key));
        executor.execute(listenableFutureTask);
        FUTURES.put(key, listenableFutureTask);

        return null;
    } finally {
        // unlock
        LOCK.unlock();
    }
}
 
Example 24
Source Project: dubbo-2.6.5   Source File: Statistics.java    License: Apache License 2.0 5 votes vote down vote up
public Statistics(URL url) {
    this.url = url;
    this.application = url.getParameter(MonitorService.APPLICATION);
    this.service = url.getParameter(MonitorService.INTERFACE);
    this.method = url.getParameter(MonitorService.METHOD);
    this.group = url.getParameter(MonitorService.GROUP);
    this.version = url.getParameter(MonitorService.VERSION);
    this.client = url.getParameter(MonitorService.CONSUMER, url.getAddress());
    this.server = url.getParameter(MonitorService.PROVIDER, url.getAddress());
}
 
Example 25
Source Project: dubbox   Source File: DubboMonitorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCount() throws Exception {
    DubboMonitor monitor = new DubboMonitor(monitorInvoker, monitorService);
    URL statistics = new URL("dubbo", "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);
    monitor.collect(statistics);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.APPLICATION), "morgan");
    Assert.assertEquals(lastStatistics.getProtocol(), "dubbo");
    Assert.assertEquals(lastStatistics.getHost(), "10.20.153.10");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.APPLICATION), "morgan");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.INTERFACE), "MemberService");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.METHOD), "findPerson");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.CONSUMER), "10.20.153.11");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.SUCCESS), "1");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.FAILURE), "0");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.ELAPSED), "3");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.MAX_ELAPSED), "3");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.CONCURRENT), "1");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.MAX_CONCURRENT), "1");
    monitor.destroy();
}
 
Example 26
Source Project: dubbo-2.6.5   Source File: DubboMonitorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCount() throws Exception {
    DubboMonitor monitor = new DubboMonitor(monitorInvoker, monitorService);
    URL statistics = new URL("dubbo", "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);
    monitor.collect(statistics);
    while (lastStatistics == null) {
        Thread.sleep(10);
    }
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.APPLICATION), "morgan");
    Assert.assertEquals(lastStatistics.getProtocol(), "dubbo");
    Assert.assertEquals(lastStatistics.getHost(), "10.20.153.10");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.APPLICATION), "morgan");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.INTERFACE), "MemberService");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.METHOD), "findPerson");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.CONSUMER), "10.20.153.11");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.SUCCESS), "1");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.FAILURE), "0");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.ELAPSED), "3");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.MAX_ELAPSED), "3");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.CONCURRENT), "1");
    Assert.assertEquals(lastStatistics.getParameter(MonitorService.MAX_CONCURRENT), "1");
    monitor.destroy();
}
 
Example 27
Source Project: dubbo-2.6.5   Source File: DubboMonitorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAvailable() {
    Invoker invoker = mock(Invoker.class);
    MonitorService monitorService = mock(MonitorService.class);

    given(invoker.isAvailable()).willReturn(true);
    given(invoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:7070?interval=20"));
    DubboMonitor dubboMonitor = new DubboMonitor(invoker, monitorService);

    assertThat(dubboMonitor.isAvailable(), is(true));
    verify(invoker).isAvailable();
}
 
Example 28
Source Project: dubbo-2.6.5   Source File: DubboMonitorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSum() {
    URL statistics = new URL("dubbo", "10.20.153.11", 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);
    Invoker invoker = mock(Invoker.class);
    MonitorService monitorService = mock(MonitorService.class);

    given(invoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:7070?interval=20"));
    DubboMonitor dubboMonitor = new DubboMonitor(invoker, monitorService);

    dubboMonitor.collect(statistics);
    dubboMonitor.collect(statistics.addParameter(MonitorService.SUCCESS, 3).addParameter(MonitorService.CONCURRENT, 2)
            .addParameter(MonitorService.INPUT, 1).addParameter(MonitorService.OUTPUT, 2));
    dubboMonitor.collect(statistics.addParameter(MonitorService.SUCCESS, 6).addParameter(MonitorService.ELAPSED, 2));

    dubboMonitor.send();

    ArgumentCaptor<URL> summaryCaptor = ArgumentCaptor.forClass(URL.class);
    verify(monitorService, atLeastOnce()).collect(summaryCaptor.capture());

    List<URL> allValues = summaryCaptor.getAllValues();

    assertThat(allValues, not(nullValue()));
    assertThat(allValues, hasItem(new CustomMatcher<URL>("Monitor count should greater than 1") {
        @Override
        public boolean matches(Object item) {
            URL url = (URL) item;
            return Integer.valueOf(url.getParameter(MonitorService.SUCCESS)) > 1;
        }
    }));
}
 
Example 29
Source Project: dubbo-2.6.5   Source File: DubboMonitorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLookUp() {
    Invoker invoker = mock(Invoker.class);
    MonitorService monitorService = mock(MonitorService.class);

    URL queryUrl = URL.valueOf("dubbo://127.0.0.1:7070?interval=20");
    given(invoker.getUrl()).willReturn(queryUrl);
    DubboMonitor dubboMonitor = new DubboMonitor(invoker, monitorService);

    dubboMonitor.lookup(queryUrl);

    verify(monitorService).lookup(eq(queryUrl));
}
 
Example 30
Source Project: dubbo-2.6.5   Source File: StatisticsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEquals() {
    URL statistics = new URL("dubbo", "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);

    Statistics statistics1 = new Statistics(statistics);
    Statistics statistics2 = new Statistics(statistics);

    Assert.assertThat(statistics1, equalTo(statistics1));
    Assert.assertThat(statistics1, equalTo(statistics2));

    statistics1.setVersion("2");
    Assert.assertThat(statistics1, not(equalTo(statistics2)));
    Assert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode())));

    statistics1.setMethod("anotherMethod");
    Assert.assertThat(statistics1, not(equalTo(statistics2)));
    Assert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode())));

    statistics1.setClient("anotherClient");
    Assert.assertThat(statistics1, not(equalTo(statistics2)));
    Assert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode())));
}