use of com.bonree.brfs.resourceschedule.model.NetStatModel in project BRFS by zhangnianli.
the class GatherResource method gatherServerStatInfo.
/**
* 概述:采集状态信息
* @param dataPath
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static void gatherServerStatInfo(Cache cache) {
ServerStatModel obj = new ServerStatModel();
Map<String, NetStatModel> netMap = null;
Map<String, PatitionStatModel> patitionMap = null;
Map<String, String> snToPatitionMap = new ConcurrentHashMap<String, String>();
try {
netMap = SigarUtils.instance.gatherNetStatInfos();
patitionMap = SigarUtils.instance.gatherPatitionStatInfos(cache);
obj.setCpuStatInfo(SigarUtils.instance.gatherCpuStatInfo());
obj.setMemoryStatInfo(SigarUtils.instance.gatherMemoryStatInfo());
if (netMap != null) {
obj.setNetStatInfoMap(netMap);
}
if (patitionMap != null) {
obj.setPatitionStatInfoMap(patitionMap);
if (cache.snWithDisk != null && !cache.snWithDisk.isEmpty()) {
cache.snRemainSizeMap = matchSnRemainSizeMap(cache.snWithDisk, patitionMap);
}
}
} catch (SigarException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cache.statInfoQueue.add(obj);
}
use of com.bonree.brfs.resourceschedule.model.NetStatModel in project BRFS by zhangnianli.
the class MapModelCalcTest method createNetMap.
public static Map<String, NetStatModel> createNetMap(String[] ipList, int initValue) {
Map<String, NetStatModel> netMap = new HashMap<String, NetStatModel>();
NetStatModel obj = null;
for (String ip : ipList) {
obj = new NetStatModel();
obj.setIpAddress(ip);
obj.setrDataSize(initValue);
obj.settDataSize(initValue);
netMap.put(ip, obj);
}
return netMap;
}
use of com.bonree.brfs.resourceschedule.model.NetStatModel in project BRFS by zhangnianli.
the class GatherResource method sumServerStatus.
/**
* 概述:汇总状态信息
* @param cache
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static ServerStatModel sumServerStatus(Cache cache) {
Queue<ServerStatModel> tmpqueue = cache.statInfoQueue;
if (tmpqueue.size() < 2) {
return null;
}
// 汇总状态信息
int size = tmpqueue.size();
ServerStatModel prex = null;
ServerStatModel current = null;
CpuStatModel cpuObj = new CpuStatModel();
MemoryStatModel memObj = new MemoryStatModel();
// 磁盘IO率集合
Map<String, List<PatitionStatModel>> patMap = null;
// 网卡IO率集合
Map<String, List<NetStatModel>> netMap = null;
CommonMapCalcInterface<String, NetStatModel> netInstance = new MapModelCalc<String, NetStatModel>();
CommonMapCalcInterface<String, PatitionStatModel> patInstance = new MapModelCalc<String, PatitionStatModel>();
for (int i = 0; i < size; i++) {
current = tmpqueue.poll();
// 1.统计cpu状态
cpuObj = cpuObj.calc(current.getCpuStatInfo());
// 2.统计内存状态
memObj = memObj.calc(current.getMemoryStatInfo());
if (i == 0) {
prex = current;
continue;
}
// 3.统计网卡IO
netMap = netInstance.collectModels(netMap, netInstance.calcMapData(current.getNetStatInfoMap(), prex.getNetStatInfoMap()));
// 4.统计磁盘IO
patMap = patInstance.collectModels(patMap, patInstance.calcMapData(current.getPatitionStatInfoMap(), prex.getPatitionStatInfoMap()));
}
Map<String, NetStatModel> netResult = netInstance.sumMapData(netMap);
Map<String, PatitionStatModel> patResult = patInstance.sumMapData(patMap);
ServerStatModel obj = new ServerStatModel();
obj.setCpuStatInfo(cpuObj);
obj.setMemoryStatInfo(memObj);
obj.setNetStatInfoMap(netResult);
obj.setPatitionStatInfoMap(patResult);
obj.setSnRemainSizeMap(cache.snRemainSizeMap);
return obj;
}
use of com.bonree.brfs.resourceschedule.model.NetStatModel in project BRFS by zhangnianli.
the class GatherResource method calcResource.
/**
* 概述:计算本机可用指标
* @param base
* @param stat
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static ResourceModel calcResource(BaseServerModel base, ServerStatModel stat) {
ResourceModel obj = new ResourceModel();
obj.setServerId(base.getServerId());
Map<String, PatitionStatModel> patMap = stat.getPatitionStatInfoMap();
Map<String, String> snToPat = base.getSnToDiskMap();
long totalDisk = base.getTotalPatitionSize();
long remain = 0;
String sn = null;
String mount = null;
PatitionStatModel pat = null;
NetStatModel net = null;
for (Map.Entry<String, Long> entry : stat.getSnRemainSizeMap().entrySet()) {
sn = entry.getKey();
remain = entry.getValue();
mount = snToPat.get(sn);
// 没有挂载点的数据为最低
if (mount == null) {
obj.putClientSNRead(sn, 0.0);
obj.putClientSNWrite(sn, 0.0);
continue;
}
pat = patMap.get(mount);
// 无磁盘状态信息的数据为最低
if (pat == null) {
obj.putClientSNRead(sn, 0.0);
obj.putClientSNWrite(sn, 0.0);
continue;
}
// 1.计算写请求 磁盘剩余率 +I/O请求
double wValue = (double) remain / totalDisk + (pat.getWriteMaxSpeed() - pat.getWriteSpeed() / pat.getCount()) / pat.getWriteMaxSpeed();
double rValue = (double) (pat.getReadMaxSpeed() - pat.getReadSpeed() / pat.getCount()) / pat.getReadMaxSpeed();
double remainValue = (double) remain / (pat.getRemainSize() + pat.getUsedSize());
obj.putClientSNRead(sn, rValue);
obj.putClientSNWrite(sn, wValue);
obj.putSnRemainRate(sn, remainValue);
}
return null;
}
Aggregations