dubbo服务治理和监控相关

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_33625560/article/details/82912159
dubbo作为一个成熟的分布式服务框架,自然提供了服务监控和服务治理的相关功能。
服务治理:dubbo-admin
服务监控:dubbo-monitor

incubator-dubbo-ops

官方提供的项目,部署很简单
git clone https://github.com/apache/incubator-dubbo-ops.git
选择master分支。
里面会有dubbo-admin(服务治理),dubbo-monitor(服务监控),这两个需要单独部署。

**

dubbokeeper

**
非官方,集服务治理和服务监控于一体,,服务监控数据提供了lucene、mysql、mongodb等三种存储方式。部署时,需要单独部署一个war包还有一个服务监控数据存储的服务。
git地址: https://github.com/dubboclub/dubbokeeper.git

**

dubbokeeper-mqs

**
dubbokeeper的快速启动版,只需启动一个应用就可以了。
git地址: https://github.com/zylele/dubbokeeper-mqs.git

注:
对于服务治理来讲dubbokeeper的功能并没有完全覆盖dubbo-admin但是基本上也够用了,而且监控功能比dubbo-monitor强很多(主要是前端页面好很多。。)
dubbokeeper刚搭建的时候,服务监控那没有数据,需要有调用才能有数据。

**

服务监控原理分析:

**
所谓的监控中心,其实也是一个标准的dubbo服务,实现的是dubbo包里的
com.alibaba.dubbo.monitor.MonitorService;
是谁调用这个服务的呢?

	dubbo可设置很多filter,对于监控这块来讲就是 MonitorFilter;
	翻开源码可以看到
// intercepting invocation
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        if (invoker.getUrl().hasParameter(Constants.MONITOR_KEY)) {
            RpcContext context = RpcContext.getContext(); // provider must fetch context before invoke() gets called
            String remoteHost = context.getRemoteHost();
            long start = System.currentTimeMillis(); // record start timestamp
            getConcurrent(invoker, invocation).incrementAndGet(); // count up
            try {
                Result result = invoker.invoke(invocation); // proceed invocation chain
                collect(invoker, invocation, result, remoteHost, start, false);
                return result;
            } catch (RpcException e) {
                collect(invoker, invocation, null, remoteHost, start, true);
                throw e;
            } finally {
                getConcurrent(invoker, invocation).decrementAndGet(); // count down
            }
        } else {
            return invoker.invoke(invocation);
        }
    }
	上面是MonitorFilter里的调用方法,可以看到很明显的是
invoker.getUrl().hasParameter(Constants.MONITOR_KEY)

dubbo并不是所有的调用都会监控的,在应用中需要配置
<dubbo:monitor protocol=“registry”/>
只有加上这个配置,才会有之后发生的事情。
继续看代码。
调用完成后收集相关的调用信息。具体方法

 collect(invoker, invocation, result, remoteHost, start, false);

这里面通过 DubboMonitorFactory 获取 DubboMonitor然后收集好调用信息,执行DubboMonitor的collect这个方法将调用信息放到map中,然后隔一段时间就将map里的所有监控信息调用MonitorService提供的服务。

大概意思就是这样,十月一要下班了不想写了。想知道就看源码,debug一下就都知道了。。

愿祖国繁荣昌盛,大家平安喜乐!!!

猜你喜欢

转载自blog.csdn.net/sinat_33625560/article/details/82912159