redis.clients.jedis.util.Slowlog Java Examples

The following examples show how to use redis.clients.jedis.util.Slowlog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SlowlogCollectorSchedule.java    From RCT with Apache License 2.0 6 votes vote down vote up
public void slowlogs(RedisInfo redisInfo) {
     String redisHost = redisInfo.getAddress().split(":")[0];
     String port = redisInfo.getAddress().split(":")[1];
     Map<String, List<Slowlog>> mapSlowlog = null;
     RedisUtil redisUtil = null;
     try {
     	if(StringUtils.isNotBlank(redisInfo.getPassword())) {
	redisUtil = new RedisUtil(redisHost, Integer.parseInt(port),redisInfo.getPassword());
}else {
	redisUtil = new RedisUtil(redisHost, Integer.parseInt(port));
}
         mapSlowlog = redisUtil.slowlogs();
     } catch (Exception e) {
         LOG.error("RedisUtil operation error. ", e);
     } finally {
         if (redisUtil != null) {
         	redisUtil.close();
         }
     }
     slowlogToES(mapSlowlog, redisInfo.getName());
 }
 
Example #2
Source File: SlowlogService.java    From RCT with Apache License 2.0 6 votes vote down vote up
public Map<String, List<Slowlog>> getSlowlog(Long id) {
	RedisUtil redisUtil = null;
	Map<String, List<Slowlog>> result = null;
	try {
		RedisInfo redisInfo = redisInfoService.selectById(id);
		String redisHost = redisInfo.getAddress().split(":")[0];
		String port = redisInfo.getAddress().split(":")[1];
		if (StringUtils.isNotBlank(redisInfo.getPassword())) {
			redisUtil = new RedisUtil(redisHost, Integer.parseInt(port), redisInfo.getPassword());
		} else {
			redisUtil = new RedisUtil(redisHost, Integer.parseInt(port));
		}
		result = redisUtil.slowlogs();
	} catch (Exception e) {
		LOG.error("slow has error.", e);
	} finally {
		if (redisUtil != null) {
			redisUtil.close();
		}
	}
	return result;
}
 
Example #3
Source File: SlowlogService.java    From RCT with Apache License 2.0 5 votes vote down vote up
public List<Map<String, Object>> slowlogSearch(String id,String hosts) {
	List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
	DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");		
	Map<String, List<Slowlog>> slowlist = this.getSlowlog(Long.valueOf(id));		
    slowlist.forEach((host,slowLists)->{
    	List<Slowlog> slowlog = null;
    	if(!"".equals(hosts) && null != hosts) {
    		if(host.equalsIgnoreCase(hosts)) {
    			slowlog = slowlist.get(host);
    		}else {	    			
    		   return;	
    		}
    	}else {
    		slowlog = slowlist.get(host);
    	}
    	slowlog.forEach(slow->{
    		Map<String, Object> maps = new HashMap<String, Object>();
    		maps.put("host", host);
    		Date date = new Date(slow.getTimeStamp()*1000);
			maps.put("SlowDate", sdf.format(date));
			maps.put("type", slow.getArgs().get(0));
			maps.put("command", slow.getArgs().toString());
			maps.put("runTime", String.valueOf(slow.getExecutionTime()));
			results.add(maps);
    	});
    });
	return results;
}
 
Example #4
Source File: RedisUtil.java    From RCT with Apache License 2.0 5 votes vote down vote up
/**
 * 获取slowlogs信息
 * 
 * @return
 */
public Map<String, List<Slowlog>> slowlogs() {
	Map<String, List<Slowlog>> mapSlowlog = new HashMap<>();
	if (clusterEnabled()) {
		mapSlowlog = this.clusterSlowlogs();
	} else {
		mapSlowlog = this.standAloneSlowlogs();
	}
	return mapSlowlog;
}
 
Example #5
Source File: RedisSlowLog.java    From redis-manager with Apache License 2.0 5 votes vote down vote up
public RedisSlowLog(HostAndPort hostAndPort, Slowlog slowlog) {
    this.node = hostAndPort.toString();
    this.dateTime = new Timestamp(slowlog.getTimeStamp() * 1000);
    this.executionTime = slowlog.getExecutionTime();
    List<String> args = slowlog.getArgs();
    this.type = args.get(0);
    List<String> commands = args.subList(1, args.size());
    this.command = Joiner.on(" ").skipNulls().join(commands);
}
 
Example #6
Source File: SlowlogCollectorSchedule.java    From RCT with Apache License 2.0 4 votes vote down vote up
/**
 * 将slowlog 数据写入ES中,保存最后提交时间
 * 
 * @param mapSlowlog
 * @param clusterName
 */
public void slowlogToES(Map<String, List<Slowlog>> mapSlowlog, String clusterName) {
    long SendTime = System.currentTimeMillis();
    if (mapSlowlog == null || mapSlowlog.size() <= 0) {
    	 return;
    }           
    Set<JSONObject> documents = new HashSet<>();
    for (String key : mapSlowlog.keySet()) {
        List<Slowlog> slowlogs = mapSlowlog.get(key);
        String host = key.split(":")[0];
        String port = key.split(":")[1];           
        for (int i = 0; i < slowlogs.size(); i++) {
            Slowlog slowlog = slowlogs.get(i);
            JSONObject json = new JSONObject();
            Long lastTime = lastToESTimes.get(key);

            // 小于缓存时间就不发送
            if (lastTime != null && slowlog.getTimeStamp() <= lastTime) {
                continue;
            }
            
            json.put("ClusterName", clusterName);
            json.put("RedisInstance", key);
            json.put("ExecutionTime", slowlog.getExecutionTime());
            json.put("TimeStamp", slowlog.getTimeStamp() * 1000); // 改为毫秒级别 TimeStamp
            // 构建唯一ID,防止数据写入多次
            json.put("id", host + port + slowlog.getId());
            List<String> args = slowlog.getArgs();
            if (args != null && args.size() > 1) {
                json.put("Command", args.get(0));
                json.put("Key", args.get(1));
                json.put("Args", JSONObject.toJSONString(args));
            }
            json.put("SendTime", SendTime);            
            documents.add(json);
        }
       
        // 存储最新提交时间,便于后期不往ES中推数据
        if (slowlogs != null && slowlogs.size() > 0) {
            lastToESTimes.put(key, slowlogs.get(0).getTimeStamp());
        }
    }
  //  System.out.println("documents:"+documents.size());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String index = initConfig.getSlowlogIndexName() + "-" + sdf.format(new Date());
    try {
        if (documents.size() <= 0) {
        	  return;
        }      
        if(initConfig.isElasticsearchEnable()) {
        	 ElasticSearchUtil.bulkIndexDocumentByID(index, "rct-slowlog", documents);  
        }
               
    } catch (Exception e) {
        LOG.error("slowlogToES error .", e);
    }
}
 
Example #7
Source File: RedisClient.java    From redis-manager with Apache License 2.0 4 votes vote down vote up
@Override
public List<Slowlog> getSlowLog(int size) {
    return jedis.slowlogGet(size);
}
 
Example #8
Source File: TracingJedisWrapper.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public List<Slowlog> slowlogGet() {
  Span span = helper.buildSpan("slowlogGet");
  return helper.decorate(span, () -> wrapped.slowlogGet());
}
 
Example #9
Source File: TracingJedisWrapper.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public List<Slowlog> slowlogGet(long entries) {
  Span span = helper.buildSpan("slowlogGet");
  span.setTag("entries", entries);
  return helper.decorate(span, () -> wrapped.slowlogGet(entries));
}
 
Example #10
Source File: InstrumentedJedis.java    From kork with Apache License 2.0 4 votes vote down vote up
@Override
public List<Slowlog> slowlogGet() {
  String command = "slowlogGet";
  return instrumented(command, () -> delegated.slowlogGet());
}
 
Example #11
Source File: InstrumentedJedis.java    From kork with Apache License 2.0 4 votes vote down vote up
@Override
public List<Slowlog> slowlogGet(long entries) {
  String command = "slowlogGet";
  return instrumented(command, () -> delegated.slowlogGet(entries));
}
 
Example #12
Source File: IRedisClient.java    From redis-manager with Apache License 2.0 2 votes vote down vote up
/**
 * Get slow log
 *
 * @return
 */
List<Slowlog> getSlowLog(int size);