use of com.sohu.cache.entity.InstanceInfo in project cachecloud by sohutv.
the class RedisImportantDataDeal method clearAllAppData.
@Test
public void clearAllAppData() {
// /////////////一定要谨慎处理/////////////////
// /////////////一定要谨慎处理/////////////////
// /////////////一定要谨慎处理/////////////////
long appId = 000L;
// /////////////一定要谨慎处理///////////////
// /////////////一定要谨慎处理/////////////////
// /////////////一定要谨慎处理/////////////////
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
logger.warn("确认要清除appId:" + appId + "的所有内存数据(输入y代表确认):");
String confirm = null;
try {
confirm = br.readLine();
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (!"y".equals(confirm)) {
return;
}
List<InstanceInfo> instanceList = instanceDao.getInstListByAppId(appId);
if (CollectionUtils.isEmpty(instanceList)) {
logger.error("appId: {}, 可能输入错误,不存在实例列表");
}
for (InstanceInfo instance : instanceList) {
if (instance.getStatus() != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
continue;
}
String host = instance.getIp();
int port = instance.getPort();
// master + 非sentinel节点
Boolean isMater = redisCenter.isMaster(host, port);
if (isMater != null && isMater.equals(true) && !TypeUtil.isRedisSentinel(instance.getType())) {
Jedis jedis = new Jedis(host, port, 30000);
try {
logger.info("{}:{} 开始清理内存", host, port);
long start = System.currentTimeMillis();
jedis.flushAll();
logger.info("{}:{} 清理完成, 耗时:{} ms", host, port, (System.currentTimeMillis() - start));
} catch (Exception e) {
logger.error(e.getMessage());
} finally {
jedis.close();
}
}
}
}
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;
}
Aggregations