Search in sources :

Example 1 with FastCompass

use of com.alibaba.metrics.FastCompass in project dubbo by alibaba.

the class MetricsFilterTest method testConsumerSuccess.

public void testConsumerSuccess() throws Exception {
    IMetricManager metricManager = MetricManager.getIMetricManager();
    metricManager.clear();
    MetricsFilter metricsFilter = new MetricsFilter();
    Invocation invocation = new RpcInvocation("sayName", DemoService.class.getName(), "", new Class<?>[] { Integer.class }, new Object[0]);
    RpcContext.getContext().setRemoteAddress(host, url.getPort()).setLocalAddress(host, NetUtils.getAvailablePort());
    RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, CONSUMER_SIDE));
    AppResponse response = AppResponseBuilder.create().build();
    onInvokeReturns(response);
    for (int i = 0; i < 100; i++) {
        metricsFilter.invoke(serviceInvoker, invocation);
    }
    FastCompass dubboClient = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER, MetricLevel.MAJOR));
    FastCompass dubboMethod = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER_METHOD, new HashMap<String, String>(4) {

        {
            put(SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService");
            put(METHOD, "void sayName(Integer)");
        }
    }, MetricLevel.NORMAL));
    long timestamp = System.currentTimeMillis() / 5000 * 5000;
    Assertions.assertEquals(100, dubboClient.getMethodCountPerCategory(0).get("success").get(timestamp));
    timestamp = timestamp / 15000 * 15000;
    Assertions.assertEquals(100, dubboMethod.getMethodCountPerCategory(0).get("success").get(timestamp));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) MetricName(com.alibaba.metrics.MetricName) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) FastCompass(com.alibaba.metrics.FastCompass) HashMap(java.util.HashMap) AppResponse(org.apache.dubbo.rpc.AppResponse) DemoService(org.apache.dubbo.monitor.dubbo.service.DemoService) IMetricManager(com.alibaba.metrics.IMetricManager)

Example 2 with FastCompass

use of com.alibaba.metrics.FastCompass in project dubbo by alibaba.

the class MetricsFilterTest method testConsumerTimeout.

public void testConsumerTimeout() {
    IMetricManager metricManager = MetricManager.getIMetricManager();
    metricManager.clear();
    MetricsFilter metricsFilter = new MetricsFilter();
    Invocation invocation = new RpcInvocation("timeoutException", DemoService.class.getName(), "", null, null);
    RpcContext.getContext().setRemoteAddress(host, url.getPort()).setLocalAddress(host, NetUtils.getAvailablePort());
    RpcContext.getContext().setUrl(timeoutInvoker.getUrl().addParameter(SIDE_KEY, CONSUMER_SIDE).addParameter(TIMEOUT_KEY, 300));
    AppResponse response = AppResponseBuilder.create().build();
    onInvokeReturns(response);
    for (int i = 0; i < 10; i++) {
        try {
            metricsFilter.invoke(timeoutInvoker, invocation);
        } catch (RpcException e) {
        // ignore
        }
    }
    FastCompass dubboClient = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER, MetricLevel.MAJOR));
    FastCompass dubboMethod = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER_METHOD, new HashMap<String, String>(4) {

        {
            put(SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService");
            put(METHOD, "void timeoutException()");
        }
    }, MetricLevel.NORMAL));
    long timestamp = System.currentTimeMillis() / 5000 * 5000;
    Assertions.assertEquals(10, dubboClient.getMethodCountPerCategory(0).get("timeoutError").get(timestamp));
    timestamp = timestamp / 15000 * 15000;
    Assertions.assertEquals(10, dubboMethod.getMethodCountPerCategory(0).get("timeoutError").get(timestamp));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) MetricName(com.alibaba.metrics.MetricName) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) FastCompass(com.alibaba.metrics.FastCompass) HashMap(java.util.HashMap) AppResponse(org.apache.dubbo.rpc.AppResponse) RpcException(org.apache.dubbo.rpc.RpcException) DemoService(org.apache.dubbo.monitor.dubbo.service.DemoService) IMetricManager(com.alibaba.metrics.IMetricManager)

Example 3 with FastCompass

use of com.alibaba.metrics.FastCompass in project dubbo by alibaba.

the class MetricsFilterTest method testProviderSuccess.

public void testProviderSuccess() throws Exception {
    IMetricManager metricManager = MetricManager.getIMetricManager();
    metricManager.clear();
    MetricsFilter metricsFilter = new MetricsFilter();
    Invocation invocation = new RpcInvocation("sayName", DemoService.class.getName(), "", new Class<?>[0], new Object[0]);
    RpcContext.getContext().setRemoteAddress(host, url.getPort()).setLocalAddress(host, NetUtils.getAvailablePort());
    RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, PROVIDER));
    AppResponse response = AppResponseBuilder.create().build();
    onInvokeReturns(response);
    for (int i = 0; i < 100; i++) {
        metricsFilter.invoke(serviceInvoker, invocation);
    }
    FastCompass dubboClient = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_PROVIDER, MetricLevel.MAJOR));
    FastCompass dubboMethod = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_PROVIDER_METHOD, new HashMap<String, String>(4) {

        {
            put(SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService");
            put(METHOD, "void sayName()");
        }
    }, MetricLevel.NORMAL));
    long timestamp = System.currentTimeMillis() / 5000 * 5000;
    Assertions.assertEquals(100, dubboClient.getMethodCountPerCategory(0).get("success").get(timestamp));
    timestamp = timestamp / 15000 * 15000;
    Assertions.assertEquals(100, dubboMethod.getMethodCountPerCategory(0).get("success").get(timestamp));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) MetricName(com.alibaba.metrics.MetricName) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) FastCompass(com.alibaba.metrics.FastCompass) HashMap(java.util.HashMap) AppResponse(org.apache.dubbo.rpc.AppResponse) DemoService(org.apache.dubbo.monitor.dubbo.service.DemoService) IMetricManager(com.alibaba.metrics.IMetricManager)

Example 4 with FastCompass

use of com.alibaba.metrics.FastCompass in project dubbo by alibaba.

the class MetricsFilter method setCompassQuantity.

private void setCompassQuantity(String groupName, String result, long duration, MetricName... metricNames) {
    for (MetricName metricName : metricNames) {
        FastCompass compass = MetricManager.getFastCompass(groupName, metricName);
        compass.record(duration, result);
    }
}
Also used : MetricName(com.alibaba.metrics.MetricName) FastCompass(com.alibaba.metrics.FastCompass)

Example 5 with FastCompass

use of com.alibaba.metrics.FastCompass in project dubbo by alibaba.

the class MetricsFilter method initMetricsInvoker.

private Invoker<MetricsService> initMetricsInvoker() {
    return new Invoker<MetricsService>() {

        @Override
        public Class<MetricsService> getInterface() {
            return MetricsService.class;
        }

        @Override
        public Result invoke(Invocation invocation) throws RpcException {
            String group = invocation.getArguments()[0].toString();
            MetricRegistry registry = MetricManager.getIMetricManager().getMetricRegistryByGroup(group);
            SortedMap<MetricName, FastCompass> fastCompasses = registry.getFastCompasses();
            long timestamp = System.currentTimeMillis();
            double rateFactor = TimeUnit.SECONDS.toSeconds(1);
            double durationFactor = 1.0 / TimeUnit.MILLISECONDS.toNanos(1);
            MetricsCollector collector = MetricsCollectorFactory.createNew(CollectLevel.NORMAL, Collections.EMPTY_MAP, rateFactor, durationFactor, null);
            for (Map.Entry<MetricName, FastCompass> entry : fastCompasses.entrySet()) {
                collector.collect(entry.getKey(), entry.getValue(), timestamp);
            }
            List<MetricObject> res = collector.build();
            res.addAll(getThreadPoolMessage());
            return AsyncRpcResult.newDefaultAsyncResult(JSON.toJSONString(res), invocation);
        }

        @Override
        public URL getUrl() {
            return URL.valueOf(protocolName + "://" + NetUtils.getIpByConfig() + ":" + port + "/" + MetricsService.class.getName());
        }

        @Override
        public boolean isAvailable() {
            return false;
        }

        @Override
        public void destroy() {
        }
    };
}
Also used : MetricsCollector(com.alibaba.metrics.common.MetricsCollector) Invocation(org.apache.dubbo.rpc.Invocation) MetricsService(org.apache.dubbo.monitor.MetricsService) MetricRegistry(com.alibaba.metrics.MetricRegistry) MetricName(com.alibaba.metrics.MetricName) Invoker(org.apache.dubbo.rpc.Invoker) FastCompass(com.alibaba.metrics.FastCompass) MetricObject(com.alibaba.metrics.common.MetricObject) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Aggregations

FastCompass (com.alibaba.metrics.FastCompass)5 MetricName (com.alibaba.metrics.MetricName)5 HashMap (java.util.HashMap)4 Invocation (org.apache.dubbo.rpc.Invocation)4 IMetricManager (com.alibaba.metrics.IMetricManager)3 DemoService (org.apache.dubbo.monitor.dubbo.service.DemoService)3 AppResponse (org.apache.dubbo.rpc.AppResponse)3 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)3 MetricRegistry (com.alibaba.metrics.MetricRegistry)1 MetricObject (com.alibaba.metrics.common.MetricObject)1 MetricsCollector (com.alibaba.metrics.common.MetricsCollector)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 MetricsService (org.apache.dubbo.monitor.MetricsService)1 Invoker (org.apache.dubbo.rpc.Invoker)1 RpcException (org.apache.dubbo.rpc.RpcException)1