Search in sources :

Example 1 with MetricRegistry

use of com.alibaba.metrics.MetricRegistry 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)1 MetricName (com.alibaba.metrics.MetricName)1 MetricRegistry (com.alibaba.metrics.MetricRegistry)1 MetricObject (com.alibaba.metrics.common.MetricObject)1 MetricsCollector (com.alibaba.metrics.common.MetricsCollector)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 MetricsService (org.apache.dubbo.monitor.MetricsService)1 Invocation (org.apache.dubbo.rpc.Invocation)1 Invoker (org.apache.dubbo.rpc.Invoker)1