use of com.sohu.cache.entity.InstanceStats in project cachecloud by sohutv.
the class MachineCenterImpl method getMachineMemoryDetail.
@Override
public MachineStats getMachineMemoryDetail(String ip) {
long applyMem = 0;
long usedMem = 0;
List<InstanceStats> instanceStats = instanceStatsDao.getInstanceStatsByIp(ip);
for (InstanceStats instance : instanceStats) {
applyMem += instance.getMaxMemory();
usedMem += instance.getUsedMemory();
}
MachineStats machineStats = machineStatsDao.getMachineStatsByIp(ip);
machineStats.setInfo(machineDao.getMachineInfoByIp(ip));
MachineMemInfo machineMemInfo = new MachineMemInfo();
machineMemInfo.setIp(ip);
machineMemInfo.setApplyMem(applyMem);
machineMemInfo.setUsedMem(usedMem);
machineStats.setMachineMemInfo(machineMemInfo);
int memoryHost = instanceDao.getMemoryByHost(ip);
machineStats.setMemoryAllocated(memoryHost);
return machineStats;
}
use of com.sohu.cache.entity.InstanceStats in project cachecloud by sohutv.
the class AppMemInspector method inspect.
@Override
public boolean inspect(Map<InspectParamEnum, Object> paramMap) {
Long appId = MapUtils.getLong(paramMap, InspectParamEnum.SPLIT_KEY);
List<AppDesc> appDescList = new ArrayList<AppDesc>();
AppDesc app = appDao.getAppDescById(appId);
if (app != null) {
appDescList.add(app);
}
if (CollectionUtils.isEmpty(appDescList)) {
logger.error("appList is empty, appId={}", appId);
return true;
}
for (AppDesc appDesc : appDescList) {
//测试不检查
if (appDesc.getIsTest() == 1) {
continue;
}
long checkAppId = appDesc.getAppId();
AppDetailVO appDetailVO = appStatsCenter.getAppDetail(checkAppId);
if (appDetailVO == null) {
continue;
}
double appMemUsePercent = appDetailVO.getMemUsePercent();
int appUseSetMemAlertValue = appDesc.getMemAlertValue();
// 先检查应用的内存使用率是否超过阀值,如果没有再检查分片
if (appMemUsePercent > appUseSetMemAlertValue) {
// 报警
alertAppMemUse(appDetailVO);
} else {
List<InstanceInfo> appInstanceInfoList = (List<InstanceInfo>) paramMap.get(InspectParamEnum.INSTANCE_LIST);
if (CollectionUtils.isNotEmpty(appInstanceInfoList)) {
for (InstanceInfo instanceInfo : appInstanceInfoList) {
if (instanceInfo == null) {
continue;
}
if (!TypeUtil.isRedisType(instanceInfo.getType())) {
continue;
}
// 忽略sentinel观察者
if (TypeUtil.isRedisSentinel(instanceInfo.getType())) {
continue;
}
long instanceId = instanceInfo.getId();
InstanceStats instanceStats = instanceStatsCenter.getInstanceStats(instanceId);
if (instanceStats == null) {
continue;
}
double instanceMemUsePercent = instanceStats.getMemUsePercent();
// 大于标准值
if (instanceMemUsePercent > appUseSetMemAlertValue) {
alertInstanceMemUse(instanceStats, appDetailVO);
}
}
}
}
}
return true;
}
use of com.sohu.cache.entity.InstanceStats in project cachecloud by sohutv.
the class MachineCenterImpl method getAllMachineStats.
@Override
public List<MachineStats> getAllMachineStats() {
List<MachineStats> list = machineStatsDao.getAllMachineStats();
for (MachineStats ms : list) {
String ip = ms.getIp();
MachineInfo machineInfo = machineDao.getMachineInfoByIp(ip);
if (machineInfo == null || machineInfo.isOffline()) {
continue;
}
int memoryHost = instanceDao.getMemoryByHost(ip);
getMachineMemoryDetail(ms.getIp());
//获取机器申请和使用内存
long applyMem = 0;
long usedMem = 0;
List<InstanceStats> instanceStats = instanceStatsDao.getInstanceStatsByIp(ip);
for (InstanceStats instance : instanceStats) {
applyMem += instance.getMaxMemory();
usedMem += instance.getUsedMemory();
}
MachineMemInfo machineMemInfo = new MachineMemInfo();
machineMemInfo.setIp(ip);
machineMemInfo.setApplyMem(applyMem);
machineMemInfo.setUsedMem(usedMem);
ms.setMachineMemInfo(machineMemInfo);
ms.setMemoryAllocated(memoryHost);
ms.setInfo(machineInfo);
}
return list;
}
use of com.sohu.cache.entity.InstanceStats in project cachecloud by sohutv.
the class AppClientConnInspector method inspect.
@Override
public boolean inspect(Map<InspectParamEnum, Object> paramMap) {
Long appId = MapUtils.getLong(paramMap, InspectParamEnum.SPLIT_KEY);
AppDetailVO appDetailVO = appStatsCenter.getAppDetail(appId);
if (appDetailVO == null) {
logger.warn("appId {} appDetailVO is empty", appId);
return true;
}
List<InstanceInfo> appInstanceInfoList = (List<InstanceInfo>) paramMap.get(InspectParamEnum.INSTANCE_LIST);
if (CollectionUtils.isEmpty(appInstanceInfoList)) {
logger.warn("appId {} instanceList is empty", appId);
return true;
}
// 报警阀值
int appClientConnThreshold = getClientConnThreshold(appDetailVO.getAppDesc());
int appClientConnNum = appDetailVO.getConn();
// 阀值乘以分片个数
int instanceCount = appInstanceInfoList.size();
if (appClientConnNum > appClientConnThreshold * instanceCount) {
alertAppClientConn(appDetailVO, appClientConnThreshold, instanceCount);
} else {
for (InstanceInfo instanceInfo : appInstanceInfoList) {
if (instanceInfo == null) {
continue;
}
if (instanceInfo.isOffline()) {
continue;
}
if (!TypeUtil.isRedisType(instanceInfo.getType())) {
continue;
}
// 忽略sentinel观察者
if (TypeUtil.isRedisSentinel(instanceInfo.getType())) {
continue;
}
long instanceId = instanceInfo.getId();
InstanceStats instanceStats = instanceStatsCenter.getInstanceStats(instanceId);
if (instanceStats == null) {
continue;
}
double instanceClientConnNum = instanceStats.getCurrConnections();
// 大于标准值
if (instanceClientConnNum > appClientConnThreshold) {
alertInstanceClientConn(instanceStats, appDetailVO, appClientConnThreshold);
}
}
}
return true;
}
use of com.sohu.cache.entity.InstanceStats in project cachecloud by sohutv.
the class InstanceStatsCenterTest method getInstanceStats.
@Test
public void getInstanceStats() {
InstanceStats instanceStats = instanceStatsCenter.getInstanceStats(51L);
logger.info("{}", instanceStats);
logger.info("{}", instanceStats.getInfoMap());
logger.info("{}", instanceStats.isRun());
instanceStats = instanceStatsCenter.getInstanceStats(139L);
logger.info("{}", instanceStats);
logger.info("{}", instanceStats.getInfoMap());
logger.info("{}", instanceStats.isRun());
}
Aggregations