use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class RedisClientController method getRedisStandaloneInfo.
private void getRedisStandaloneInfo(HttpServletRequest request, long appId, Model model) {
String clientVersion = request.getParameter("clientVersion");
if (!checkClientVersion(clientVersion, model)) {
return;
}
List<InstanceInfo> instanceList = instanceDao.getInstListByAppId(appId);
String standalone = null;
for (InstanceInfo instanceInfo : instanceList) {
if (instanceInfo.isOffline()) {
continue;
}
standalone = instanceInfo.getIp() + ":" + instanceInfo.getPort();
}
model.addAttribute("standalone", standalone);
model.addAttribute("status", ClientStatusEnum.GOOD.getStatus());
//保存版本信息
try {
clientVersionService.saveOrUpdateClientVersion(appId, IpUtil.getIpAddr(request), clientVersion);
} catch (Exception e) {
logger.error("redisStandalone heart error:" + e.getMessage(), e);
}
}
use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class MachineCenterImpl method getMachineInstanceInfo.
@Override
public List<InstanceInfo> getMachineInstanceInfo(String ip) {
List<InstanceInfo> resultList = instanceDao.getInstListByIp(ip);
if (resultList == null || resultList.isEmpty()) {
return resultList;
}
if (resultList != null && resultList.size() > 0) {
for (InstanceInfo instanceInfo : resultList) {
int type = instanceInfo.getType();
if (instanceInfo.getStatus() != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
continue;
}
if (TypeUtil.isRedisType(type)) {
if (TypeUtil.isRedisSentinel(type)) {
continue;
}
String host = instanceInfo.getIp();
int port = instanceInfo.getPort();
Boolean isMaster = redisCenter.isMaster(host, port);
instanceInfo.setRoleDesc(isMaster);
if (isMaster != null && !isMaster) {
HostAndPort hap = redisCenter.getMaster(host, port);
if (hap != null) {
instanceInfo.setMasterHost(hap.getHost());
instanceInfo.setMasterPort(hap.getPort());
for (InstanceInfo innerInfo : resultList) {
if (innerInfo.getIp().equals(hap.getHost()) && innerInfo.getPort() == hap.getPort()) {
instanceInfo.setMasterInstanceId(innerInfo.getId());
break;
}
}
}
}
}
}
}
return resultList;
}
use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class AppInspectHandler method getSplitMap.
@Override
protected Map<String, List<InstanceInfo>> getSplitMap() {
List<InstanceInfo> list = getAllInstanceList();
Map<String, List<InstanceInfo>> hostMap = new TreeMap<String, List<InstanceInfo>>();
for (InstanceInfo instanceInfo : list) {
String appId = String.valueOf(instanceInfo.getAppId());
if (hostMap.containsKey(appId)) {
hostMap.get(appId).add(instanceInfo);
} else {
List<InstanceInfo> hostInstances = new ArrayList<InstanceInfo>();
hostInstances.add(instanceInfo);
hostMap.put(appId, hostInstances);
}
}
return hostMap;
}
use of com.sohu.cache.entity.InstanceInfo 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.InstanceInfo in project cachecloud by sohutv.
the class InstanceRunInspector method inspect.
@Override
public boolean inspect(Map<InspectParamEnum, Object> paramMap) {
String host = MapUtils.getString(paramMap, InspectParamEnum.SPLIT_KEY);
List<InstanceInfo> list = (List<InstanceInfo>) paramMap.get(InspectParamEnum.INSTANCE_LIST);
for (InstanceInfo info : list) {
final int port = info.getPort();
final int type = info.getType();
long appId = info.getAppId();
if (TypeUtil.isRedisType(type)) {
boolean isRun = redisCenter.isRun(host, port);
Boolean isUpdate = updateInstanceByRun(isRun, info);
if (isUpdate == null) {
continue;
} else if (isUpdate) {
redisCenter.deployRedisCollection(appId, host, port);
redisCenter.deployRedisSlowLogCollection(appId, host, port);
} else {
redisCenter.unDeployRedisCollection(appId, host, port);
redisCenter.unDeployRedisSlowLogCollection(appId, host, port);
}
// 错误
if (isUpdate != null) {
alertInstanceInfo(info);
}
}
}
return true;
}
Aggregations