package com.sohu.cache.redis.impl;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import com.sohu.cache.async.AsyncService;
import com.sohu.cache.async.AsyncThreadPoolFactory;
import com.sohu.cache.async.KeyCallable;
import com.sohu.cache.constant.*;
import com.sohu.cache.dao.*;
import com.sohu.cache.entity.*;
import com.sohu.cache.exception.SSHException;
import com.sohu.cache.machine.MachineCenter;
import com.sohu.cache.protocol.MachineProtocol;
import com.sohu.cache.protocol.RedisProtocol;
import com.sohu.cache.redis.RedisCenter;
import com.sohu.cache.redis.enums.RedisInfoEnum;
import com.sohu.cache.redis.enums.RedisReadOnlyCommandEnum;
import com.sohu.cache.redis.util.*;
import com.sohu.cache.report.ReportDataComponent;
import com.sohu.cache.ssh.SSHService;
import com.sohu.cache.ssh.SSHUtil;
import com.sohu.cache.stats.instance.InstanceStatsCenter;
import com.sohu.cache.task.BaseTask;
import com.sohu.cache.task.constant.InstanceInfoEnum.InstanceTypeEnum;
import com.sohu.cache.util.*;
import com.sohu.cache.web.enums.BooleanEnum;
import com.sohu.cache.web.enums.ClientTypeEnum;
import com.sohu.cache.web.enums.SuccessEnum;
import com.sohu.cache.web.service.AppService;
import com.sohu.cache.web.service.ModuleService;
import com.sohu.cache.web.service.WebClientComponent;
import com.sohu.cache.web.util.DateUtil;
import com.sohu.cache.web.vo.RedisSlowLog;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import redis.clients.jedis.DebugParams;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisSentinelPool;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.ScanResult;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Module;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.exceptions.JedisAskDataException;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisMovedDataException;
import redis.clients.jedis.util.SafeEncoder;
import redis.clients.jedis.util.Slowlog;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
/**
* Created by yijunzhang on 14-6-10.
*/
@Service("redisCenter")
public class RedisCenterImpl implements RedisCenter {
public static final int REDIS_DEFAULT_TIME = 1000;
public static final String REDIS_SLOWLOG_POOL = "redis-slowlog-pool";
private static final int COUNT = 1000;
private static List<RedisInfoEnum> otherNeedCalDifRedisInfoEnumList = new ArrayList<>();
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Lock lock = new ReentrantLock();
@Autowired
private AppStatsDao appStatsDao;
@Autowired
private AsyncService asyncService;
@Autowired
private InstanceDao instanceDao;
@Autowired
private InstanceStatsDao instanceStatsDao;
@Autowired
private InstanceStatsCenter instanceStatsCenter;
@Autowired
@Lazy
private MachineCenter machineCenter;
private volatile Map<String, JedisPool> jedisPoolMap = new HashMap<String, JedisPool>();
@Autowired
private AppDao appDao;
@Autowired
private RedisModuleConfigDao redisModuleConfigDao;
@Autowired
private AppAuditLogDao appAuditLogDao;
@Autowired
private AppService appService;
@Autowired
private InstanceSlowLogDao instanceSlowLogDao;
@Autowired
private InstanceLatencyHistoryDao instanceLatencyHistoryDao;
@Autowired
private WebClientComponent webClientComponent;
@Autowired
SSHService sshService;
@Autowired
private ModuleService moduleService;
@Autowired
private ReportDataComponent reportDataComponent;
@PostConstruct
public void init() {
asyncService.assemblePool(getThreadPoolKey(), AsyncThreadPoolFactory.REDIS_SLOWLOG_THREAD_POOL);
otherNeedCalDifRedisInfoEnumList.add(RedisInfoEnum.mem_fragmentation_ratio);
}
private JedisPool maintainJedisPool(String host, int port, String password) {
String hostAndPort = ObjectConvert.linkIpAndPort(host, port);
JedisPool jedisPool = jedisPoolMap.get(hostAndPort);
if (jedisPool == null) {
lock.lock();
try {
//double check
jedisPool = jedisPoolMap.get(hostAndPort);
if (jedisPool == null) {
try {
if (StringUtils.isNotBlank(password)) {
jedisPool = new JedisPool(new GenericObjectPoolConfig(), host, port,
Protocol.DEFAULT_TIMEOUT, password);
} else {
jedisPool = new JedisPool(new GenericObjectPoolConfig(), host, port,
Protocol.DEFAULT_TIMEOUT);
}
jedisPoolMap.put(hostAndPort, jedisPool);
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
}
}
} finally {
lock.unlock();
}
}
return jedisPool;
}
private String buildFutureKey(long appId, long collectTime, String host, int port) {
StringBuilder keyBuffer = new StringBuilder("redis-");
keyBuffer.append(collectTime);
keyBuffer.append("-");
keyBuffer.append(appId);
keyBuffer.append("-");
keyBuffer.append(host + ":" + port);
return keyBuffer.toString();
}
@Override
public List<InstanceSlowLog> collectRedisSlowLog(long appId, long collectTime, String host, int port) {
Assert.isTrue(appId > 0);
Assert.hasText(host);
Assert.isTrue(port > 0);
InstanceInfo instanceInfo = instanceDao.getInstByIpAndPort(host, port);
//不存在实例/实例异常/下线
if (instanceInfo == null) {
return null;
}
if (TypeUtil.isRedisSentinel(instanceInfo.getType())) {
//忽略sentinel redis实例
return null;
}
// 从redis中获取慢查询日志
List<RedisSlowLog> redisLowLogList = getRedisSlowLogs(appId, host, port, 100);
if (CollectionUtils.isEmpty(redisLowLogList)) {
return Collections.emptyList();
}
// transfer
final List<InstanceSlowLog> instanceSlowLogList = new ArrayList<InstanceSlowLog>();
for (RedisSlowLog redisSlowLog : redisLowLogList) {
InstanceSlowLog instanceSlowLog = transferRedisSlowLogToInstance(redisSlowLog, instanceInfo);
if (instanceSlowLog == null) {
continue;
}
instanceSlowLogList.add(instanceSlowLog);
}
if (CollectionUtils.isEmpty(instanceSlowLogList)) {
return Collections.emptyList();
}
//处理
String key = getThreadPoolKey() + "_" + host + "_" + port;
boolean isOk = asyncService.submitFuture(getThrea
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
搜狐视频(sohu tv)Redis私有云平台 :支持Redis多种架构(Standalone、Sentinel、Cluster)高效管理、有效降低大规模redis运维成本,提升资源管控能力和利用率。平台提供快速搭建/迁移,运维管理,弹性伸缩,统计监控,客户端整合接入等功能。
资源推荐
资源详情
资源评论
收起资源包目录
搜狐视频(sohu tv)Redis私有云平台 :支持Redis多种架构Standalone、Sentinel、Cluster (1734个子文件)
cachecloud-web.conf 969B
ace.min.css 388KB
ace-part2.min.css 126KB
bootstrap.css 123KB
bootstrap.css 120KB
ace-rtl.min.css 114KB
bootstrap.min.css 113KB
bootstrap.min.css 100KB
bootstrap.min.css 97KB
style.css 80KB
buttons.css 78KB
ace-skins.min.css 76KB
animate.css 60KB
font-awesome.min.css 27KB
font-awesome.min.css 27KB
style-metronic.css 27KB
font-awesome.css 22KB
style.css 22KB
plugins.css 21KB
docs.min.css 21KB
bootstrap-datepicker3.min.css 20KB
font-awesome.min.css 18KB
bootstrap-editable.min.css 17KB
jquery-ui.min.css 15KB
select2.min.css 14KB
bootstrap-theme.css 14KB
bootstrap-theme.min.css 13KB
ui.jqgrid.min.css 13KB
fullcalendar.min.css 12KB
chosen.min.css 11KB
style-responsive.css 10KB
light.css 10KB
dropzone.min.css 9KB
ace-ie.min.css 9KB
inbox.css 8KB
purple.css 8KB
blue.css 8KB
brown.css 8KB
grey.css 8KB
default.css 8KB
bootstrap-datetimepicker.min.css 8KB
pricing-tables.css 7KB
toastr.min.css 7KB
timeline.css 6KB
bootstrap-select.css 6KB
theme.css 6KB
daterangepicker.min.css 5KB
profile.css 5KB
bootstrap-select.min.css 5KB
style-non-responsive.css 4KB
datepicker.css 4KB
bootstrap-colorpicker.min.css 4KB
DT_bootstrap.css 4KB
datepicker.css 4KB
githubmd.css 3KB
jquery-ui.custom.min.css 3KB
bootstrap-timepicker.min.css 3KB
login.css 3KB
colorbox.min.css 3KB
login-soft.css 3KB
blog.css 3KB
search.css 2KB
error.css 2KB
news.css 2KB
lock.css 2KB
portfolio.css 2KB
common.css 2KB
invalid.css 2KB
coming-soon.css 2KB
tasks.css 2KB
mem-cloud.css 2KB
login.css 2KB
jquery.gritter.min.css 2KB
prettify.css 2KB
bootstrap-duallistbox.min.css 1KB
promo.css 1KB
prettify.css 1KB
bootstrap-multiselect.min.css 1KB
reset.css 1KB
jquery-editable-select.min.css 1KB
image-crop.css 988B
font.css 902B
email.css 755B
invoice.css 566B
prettify.min.css 532B
fonts.googleapis.com.css 494B
print.css 362B
about-us.css 286B
WdatePicker.css 158B
custom.css 71B
Thumbs.db 34KB
fontawesome-webfont.eot 69KB
fontawesome-webfont.eot 37KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
expAppsDaily.ftl 30KB
appDaily.ftl 12KB
appAudit.ftl 8KB
instanceAlert.ftl 5KB
共 1734 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
UnknownToKnown
- 粉丝: 1w+
- 资源: 773
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功