All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yiji.framework.watcher.dubbo.metrics.DubboServerStatusMetrics Maven / Gradle / Ivy

/*
 * www.yiji.com Inc.
 * Copyright (c) 2014 All Rights Reserved
 */

/*
 * 修订记录:
 * [email protected] 2015-05-19 16:57 创建
 *
 */
package com.yiji.framework.watcher.dubbo.metrics;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.alibaba.dubbo.remoting.exchange.ExchangeServer;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yiji.framework.watcher.WatcherException;

/**
 * @author [email protected]
 */
public class DubboServerStatusMetrics extends AbstractDubboWatcherMetrics {
	
	@Override
	public Object doMonitor(Map params) throws Throwable {
		List> result = Lists.newArrayList();
		Collection servers = DubboProtocol.getDubboProtocol().getServers();
		if (servers == null || servers.size() == 0) {
			throw WatcherException.throwIt("no server found");
		}
		for (ExchangeServer server : servers) {
			Map serverResult = Maps.newHashMap();
			boolean isBound = server.isBound();
			serverResult.put("isBound", isBound);
			if (isBound) {
				serverResult.put("clients", server.getChannels().size());
			}
			serverResult.put("port", server.getLocalAddress().getPort());
			result.add(serverResult);
		}
		return result;
	}
	
	@Override
	public String name() {
		return "dubboServerStatus";
	}
	
	@Override
	public String desc() {
		return "dubbo server status";
	}
	
	@Override
	public CacheTime getCacheTime() {
		return CacheTime.THIRTY_SECOND;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy